Skip to content

Commit 4e1fe96

Browse files
committed
Revert "[Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values"
This reverts commit a35c64c. Reverting this commit as it causes various failures on LE and BE PPC bots.
1 parent cea1b79 commit 4e1fe96

File tree

9 files changed

+3
-291
lines changed

9 files changed

+3
-291
lines changed

clang/include/clang/Basic/Attr.td

-7
Original file line numberDiff line numberDiff line change
@@ -2023,13 +2023,6 @@ def NoEscape : Attr {
20232023
let Documentation = [NoEscapeDocs];
20242024
}
20252025

2026-
def MaybeUndef : InheritableAttr {
2027-
let Spellings = [Clang<"maybe_undef">];
2028-
let Subjects = SubjectList<[ParmVar]>;
2029-
let Documentation = [MaybeUndefDocs];
2030-
let SimpleHandler = 1;
2031-
}
2032-
20332026
def AssumeAligned : InheritableAttr {
20342027
let Spellings = [GCC<"assume_aligned">];
20352028
let Subjects = SubjectList<[ObjCMethod, Function]>;

clang/include/clang/Basic/AttrDocs.td

-22
Original file line numberDiff line numberDiff line change
@@ -257,28 +257,6 @@ applies to copies of the block. For example:
257257
}];
258258
}
259259

260-
def MaybeUndefDocs : Documentation {
261-
let Category = DocCatVariable;
262-
let Content = [{
263-
The ``maybe_undef`` attribute can be placed on a function parameter. It indicates
264-
that the parameter is allowed to use undef values. It informs the compiler
265-
to insert a freeze LLVM IR instruction on the function parameter.
266-
Please note that this is an attribute that is used as an internal
267-
implementation detail and not intended to be used by external users.
268-
269-
In languages HIP, CUDA etc., some functions have multi-threaded semantics and
270-
it is enough for only one or some threads to provide defined arguments.
271-
Depending on semantics, undef arguments in some threads don't produce
272-
undefined results in the function call. Since, these functions accept undefined
273-
arguments, ``maybe_undef`` attribute can be placed.
274-
275-
Sample usage:
276-
.. code-block:: c
277-
278-
void maybeundeffunc(int __attribute__((maybe_undef))param);
279-
}];
280-
}
281-
282260
def CarriesDependencyDocs : Documentation {
283261
let Category = DocCatFunction;
284262
let Content = [{

clang/lib/CodeGen/CGCall.cpp

+3-47
Original file line numberDiff line numberDiff line change
@@ -2046,27 +2046,6 @@ static bool DetermineNoUndef(QualType QTy, CodeGenTypes &Types,
20462046
return false;
20472047
}
20482048

2049-
/// Check if the argument of a function has maybe_undef attribute.
2050-
static bool IsArgumentMaybeUndef(const Decl *TargetDecl,
2051-
unsigned NumRequiredArgs, unsigned ArgNo) {
2052-
const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
2053-
if (!FD)
2054-
return false;
2055-
2056-
// Assume variadic arguments do not have maybe_undef attribute.
2057-
if (ArgNo >= NumRequiredArgs)
2058-
return false;
2059-
2060-
// Check if argument has maybe_undef attribute.
2061-
if (ArgNo < FD->getNumParams()) {
2062-
const ParmVarDecl *Param = FD->getParamDecl(ArgNo);
2063-
if (Param && Param->hasAttr<MaybeUndefAttr>())
2064-
return true;
2065-
}
2066-
2067-
return false;
2068-
}
2069-
20702049
/// Construct the IR attribute list of a function or call.
20712050
///
20722051
/// When adding an attribute, please consider where it should be handled:
@@ -4842,9 +4821,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
48424821
unsigned FirstIRArg, NumIRArgs;
48434822
std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
48444823

4845-
bool ArgHasMaybeUndefAttr =
4846-
IsArgumentMaybeUndef(TargetDecl, CallInfo.getNumRequiredArgs(), ArgNo);
4847-
48484824
switch (ArgInfo.getKind()) {
48494825
case ABIArgInfo::InAlloca: {
48504826
assert(NumIRArgs == 0);
@@ -4903,11 +4879,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
49034879
// Make a temporary alloca to pass the argument.
49044880
Address Addr = CreateMemTempWithoutCast(
49054881
I->Ty, ArgInfo.getIndirectAlign(), "indirect-arg-temp");
4906-
4907-
llvm::Value *Val = Addr.getPointer();
4908-
if (ArgHasMaybeUndefAttr)
4909-
Val = Builder.CreateFreeze(Addr.getPointer());
4910-
IRCallArgs[FirstIRArg] = Val;
4882+
IRCallArgs[FirstIRArg] = Addr.getPointer();
49114883

49124884
I->copyInto(*this, Addr);
49134885
} else {
@@ -4965,10 +4937,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
49654937
// Create an aligned temporary, and copy to it.
49664938
Address AI = CreateMemTempWithoutCast(
49674939
I->Ty, ArgInfo.getIndirectAlign(), "byval-temp");
4968-
llvm::Value *Val = AI.getPointer();
4969-
if (ArgHasMaybeUndefAttr)
4970-
Val = Builder.CreateFreeze(AI.getPointer());
4971-
IRCallArgs[FirstIRArg] = Val;
4940+
IRCallArgs[FirstIRArg] = AI.getPointer();
49724941

49734942
// Emit lifetime markers for the temporary alloca.
49744943
llvm::TypeSize ByvalTempElementSize =
@@ -4987,13 +4956,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
49874956
auto *T = llvm::PointerType::getWithSamePointeeType(
49884957
cast<llvm::PointerType>(V->getType()),
49894958
CGM.getDataLayout().getAllocaAddrSpace());
4990-
4991-
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
4959+
IRCallArgs[FirstIRArg] = getTargetHooks().performAddrSpaceCast(
49924960
*this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
49934961
true);
4994-
if (ArgHasMaybeUndefAttr)
4995-
Val = Builder.CreateFreeze(Val);
4996-
IRCallArgs[FirstIRArg] = Val;
49974962
}
49984963
}
49994964
break;
@@ -5047,8 +5012,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
50475012
V->getType() != IRFuncTy->getParamType(FirstIRArg))
50485013
V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
50495014

5050-
if (ArgHasMaybeUndefAttr)
5051-
V = Builder.CreateFreeze(V);
50525015
IRCallArgs[FirstIRArg] = V;
50535016
break;
50545017
}
@@ -5093,8 +5056,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
50935056
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
50945057
Address EltPtr = Builder.CreateStructGEP(Src, i);
50955058
llvm::Value *LI = Builder.CreateLoad(EltPtr);
5096-
if (ArgHasMaybeUndefAttr)
5097-
LI = Builder.CreateFreeze(LI);
50985059
IRCallArgs[FirstIRArg + i] = LI;
50995060
}
51005061
} else {
@@ -5111,9 +5072,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
51115072
if (ATy != nullptr && isa<RecordType>(I->Ty.getCanonicalType()))
51125073
Load = EmitCMSEClearRecord(Load, ATy, I->Ty);
51135074
}
5114-
5115-
if (ArgHasMaybeUndefAttr)
5116-
Load = Builder.CreateFreeze(Load);
51175075
IRCallArgs[FirstIRArg] = Load;
51185076
}
51195077

@@ -5159,8 +5117,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
51595117
if (ABIArgInfo::isPaddingForCoerceAndExpand(eltType)) continue;
51605118
Address eltAddr = Builder.CreateStructGEP(addr, i);
51615119
llvm::Value *elt = Builder.CreateLoad(eltAddr);
5162-
if (ArgHasMaybeUndefAttr)
5163-
elt = Builder.CreateFreeze(elt);
51645120
IRCallArgs[IRArgPos++] = elt;
51655121
}
51665122
assert(IRArgPos == FirstIRArg + NumIRArgs);

clang/lib/Sema/SemaDeclAttr.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -8634,9 +8634,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
86348634
case ParsedAttr::AT_NoEscape:
86358635
handleNoEscapeAttr(S, D, AL);
86368636
break;
8637-
case ParsedAttr::AT_MaybeUndef:
8638-
handleSimpleAttribute<MaybeUndefAttr>(S, D, AL);
8639-
break;
86408637
case ParsedAttr::AT_AssumeAligned:
86418638
handleAssumeAlignedAttr(S, D, AL);
86428639
break;

clang/test/CodeGen/attr-maybeundef-template.cpp

-43
This file was deleted.

clang/test/CodeGen/attr-maybeundef.c

-109
This file was deleted.

clang/test/CodeGenHIP/maybe_undef-attr-verify.hip

-44
This file was deleted.

clang/test/Misc/pragma-attribute-supported-attributes-list.test

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
// CHECK-NEXT: Lockable (SubjectMatchRule_record)
8484
// CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
8585
// CHECK-NEXT: MSStruct (SubjectMatchRule_record)
86-
// CHECK-NEXT: MaybeUndef (SubjectMatchRule_variable_is_parameter)
8786
// CHECK-NEXT: MicroMips (SubjectMatchRule_function)
8887
// CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method)
8988
// CHECK-NEXT: MinVectorWidth (SubjectMatchRule_function)

clang/test/Sema/attr-maybeundef.c

-15
This file was deleted.

0 commit comments

Comments
 (0)