Skip to content

Commit de88617

Browse files
authored
merge main into amd-staging (llvm#1601)
2 parents a0eb3eb + 2251aef commit de88617

File tree

403 files changed

+6405
-9729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

403 files changed

+6405
-9729
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13065,6 +13065,8 @@ def err_acc_decl_for_routine
1306513065
: Error<"expected function or lambda declaration for 'routine' construct">;
1306613066
def err_acc_invalid_modifier
1306713067
: Error<"OpenACC '%0' modifier not valid on '%1' clause">;
13068+
def err_acc_invalid_default_type
13069+
: Error<"invalid value %0 in '%1' clause; valid values are %2">;
1306813070

1306913071
// AMDGCN builtins diagnostics
1307013072
def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ struct MissingFeatures {
108108
static bool cgFPOptionsRAII() { return false; }
109109
static bool metaDataNode() { return false; }
110110
static bool fastMathFlags() { return false; }
111-
static bool lvalueBaseInfo() { return false; }
112111
static bool alignCXXRecordDecl() { return false; }
113112
static bool setNonGC() { return false; }
114113
static bool incrementProfileCounter() { return false; }
115114
static bool insertBuiltinUnpredictable() { return false; }
115+
static bool objCGC() { return false; }
116116

117117
// Missing types
118118
static bool dataMemberType() { return false; }

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
463463

464464
if (!this->visit(SubExpr))
465465
return false;
466+
if (CE->getType()->isFunctionPointerType())
467+
return true;
466468
if (FromT == PT_Ptr)
467469
return this->emitPtrPtrCast(SubExprTy->isVoidPointerType(), CE);
468470
return true;
@@ -4921,10 +4923,10 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
49214923
} else if (!FuncDecl) {
49224924
const Expr *Callee = E->getCallee();
49234925
CalleeOffset =
4924-
this->allocateLocalPrimitive(Callee, PT_FnPtr, /*IsConst=*/true);
4926+
this->allocateLocalPrimitive(Callee, PT_Ptr, /*IsConst=*/true);
49254927
if (!this->visit(Callee))
49264928
return false;
4927-
if (!this->emitSetLocal(PT_FnPtr, *CalleeOffset, E))
4929+
if (!this->emitSetLocal(PT_Ptr, *CalleeOffset, E))
49284930
return false;
49294931
}
49304932

@@ -5011,7 +5013,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
50115013
if (!this->emitGetMemberPtrDecl(E))
50125014
return false;
50135015
} else {
5014-
if (!this->emitGetLocal(PT_FnPtr, *CalleeOffset, E))
5016+
if (!this->emitGetLocal(PT_Ptr, *CalleeOffset, E))
50155017
return false;
50165018
}
50175019
if (!this->emitCallPtr(ArgSize, E, E))

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ std::optional<PrimType> Context::classify(QualType T) const {
189189

190190
if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
191191
T->isFunctionType() || T->isBlockPointerType())
192-
return PT_FnPtr;
192+
return PT_Ptr;
193193

194194
if (T->isPointerOrReferenceType() || T->isObjCObjectPointerType())
195195
return PT_Ptr;

clang/lib/AST/ByteCode/Context.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ class Context final {
7878
/// Classifies an expression.
7979
std::optional<PrimType> classify(const Expr *E) const {
8080
assert(E);
81-
if (E->isGLValue()) {
82-
if (E->getType()->isFunctionType())
83-
return PT_FnPtr;
81+
if (E->isGLValue())
8482
return PT_Ptr;
85-
}
8683

8784
return classify(E->getType());
8885
}

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
169169

170170
const Pointer &Ptr = S.Stk.pop<Pointer>();
171171

172+
if (Ptr.isFunctionPointer()) {
173+
EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext()));
174+
return true;
175+
}
176+
172177
if (!EvalResult.checkReturnValue(S, Ctx, Ptr, Info))
173178
return false;
174179
if (CheckFullyInitialized && !EvalResult.checkFullyInitialized(S, Ptr))

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ static bool BCP(InterpState &S, CodePtr &RealPC, int32_t Offset, PrimType PT) {
9090
assert(S.Stk.size() == StackSizeBefore);
9191
S.Stk.push<Integral<32, true>>(
9292
Integral<32, true>::from(CheckBCPResult(S, Ptr)));
93-
} else if (PT == PT_FnPtr) {
94-
S.Stk.discard<FunctionPointer>();
95-
S.Stk.push<Integral<32, true>>(Integral<32, true>::from(0));
9693
} else {
9794
// Pop the result from the stack and return success.
9895
TYPE_SWITCH(PT, S.Stk.pop<T>(););
@@ -318,6 +315,8 @@ bool CheckBCPResult(InterpState &S, const Pointer &Ptr) {
318315
return false;
319316
if (Ptr.isZero())
320317
return true;
318+
if (Ptr.isFunctionPointer())
319+
return false;
321320
if (Ptr.isIntegralPointer())
322321
return true;
323322
if (Ptr.isTypeidPointer())
@@ -1621,20 +1620,24 @@ bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
16211620

16221621
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
16231622
const CallExpr *CE) {
1624-
const FunctionPointer &FuncPtr = S.Stk.pop<FunctionPointer>();
1623+
const Pointer &Ptr = S.Stk.pop<Pointer>();
16251624

1626-
const Function *F = FuncPtr.getFunction();
1627-
if (!F) {
1625+
if (Ptr.isZero()) {
16281626
const auto *E = cast<CallExpr>(S.Current->getExpr(OpPC));
16291627
S.FFDiag(E, diag::note_constexpr_null_callee)
16301628
<< const_cast<Expr *>(E->getCallee()) << E->getSourceRange();
16311629
return false;
16321630
}
16331631

1634-
if (!FuncPtr.isValid() || !F->getDecl())
1632+
if (!Ptr.isFunctionPointer())
16351633
return Invalid(S, OpPC);
16361634

1635+
const FunctionPointer &FuncPtr = Ptr.asFunctionPointer();
1636+
const Function *F = FuncPtr.getFunction();
16371637
assert(F);
1638+
// Don't allow calling block pointers.
1639+
if (!F->getDecl())
1640+
return Invalid(S, OpPC);
16381641

16391642
// This happens when the call expression has been cast to
16401643
// something else, but we don't support that.
@@ -1774,6 +1777,8 @@ bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC,
17741777
const Pointer &Ptr, unsigned BitWidth) {
17751778
if (Ptr.isDummy())
17761779
return false;
1780+
if (Ptr.isFunctionPointer())
1781+
return true;
17771782

17781783
const SourceInfo &E = S.Current->getSource(OpPC);
17791784
S.CCEDiag(E, diag::note_constexpr_invalid_cast)

clang/lib/AST/ByteCode/Interp.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -979,20 +979,6 @@ bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn) {
979979
return CmpHelper<T>(S, OpPC, Fn);
980980
}
981981

982-
/// Function pointers cannot be compared in an ordered way.
983-
template <>
984-
inline bool CmpHelper<FunctionPointer>(InterpState &S, CodePtr OpPC,
985-
CompareFn Fn) {
986-
const auto &RHS = S.Stk.pop<FunctionPointer>();
987-
const auto &LHS = S.Stk.pop<FunctionPointer>();
988-
989-
const SourceInfo &Loc = S.Current->getSource(OpPC);
990-
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
991-
<< LHS.toDiagnosticString(S.getASTContext())
992-
<< RHS.toDiagnosticString(S.getASTContext());
993-
return false;
994-
}
995-
996982
template <>
997983
inline bool CmpHelperEQ<FunctionPointer>(InterpState &S, CodePtr OpPC,
998984
CompareFn Fn) {
@@ -1019,18 +1005,27 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10191005
const Pointer &RHS = S.Stk.pop<Pointer>();
10201006
const Pointer &LHS = S.Stk.pop<Pointer>();
10211007

1008+
// Function pointers cannot be compared in an ordered way.
1009+
if (LHS.isFunctionPointer() || RHS.isFunctionPointer()) {
1010+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1011+
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1012+
<< LHS.toDiagnosticString(S.getASTContext())
1013+
<< RHS.toDiagnosticString(S.getASTContext());
1014+
return false;
1015+
}
1016+
10221017
if (!Pointer::hasSameBase(LHS, RHS)) {
10231018
const SourceInfo &Loc = S.Current->getSource(OpPC);
10241019
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
10251020
<< LHS.toDiagnosticString(S.getASTContext())
10261021
<< RHS.toDiagnosticString(S.getASTContext());
10271022
return false;
1028-
} else {
1029-
unsigned VL = LHS.getByteOffset();
1030-
unsigned VR = RHS.getByteOffset();
1031-
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(VL, VR))));
1032-
return true;
10331023
}
1024+
1025+
unsigned VL = LHS.getByteOffset();
1026+
unsigned VR = RHS.getByteOffset();
1027+
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(VL, VR))));
1028+
return true;
10341029
}
10351030

10361031
static inline bool IsOpaqueConstantCall(const CallExpr *E) {
@@ -1069,6 +1064,12 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10691064
return false;
10701065
}
10711066

1067+
if (LHS.isFunctionPointer() && RHS.isFunctionPointer()) {
1068+
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(LHS.getIntegerRepresentation(),
1069+
RHS.getIntegerRepresentation()))));
1070+
return true;
1071+
}
1072+
10721073
if (Pointer::hasSameBase(LHS, RHS)) {
10731074
if (LHS.inUnion() && RHS.inUnion()) {
10741075
// If the pointers point into a union, things are a little more
@@ -2787,7 +2788,7 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
27872788

27882789
inline bool GetFnPtr(InterpState &S, CodePtr OpPC, const Function *Func) {
27892790
assert(Func);
2790-
S.Stk.push<FunctionPointer>(Func);
2791+
S.Stk.push<Pointer>(Func);
27912792
return true;
27922793
}
27932794

@@ -2822,7 +2823,7 @@ inline bool GetMemberPtrDecl(InterpState &S, CodePtr OpPC) {
28222823
const auto *FD = cast<FunctionDecl>(MP.getDecl());
28232824
const auto *Func = S.getContext().getOrCreateFunction(FD);
28242825

2825-
S.Stk.push<FunctionPointer>(Func);
2826+
S.Stk.push<Pointer>(Func);
28262827
return true;
28272828
}
28282829

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,45 @@ bool SetThreeWayComparisonField(InterpState &S, CodePtr OpPC,
27232723
return true;
27242724
}
27252725

2726+
static void zeroAll(Pointer &Dest) {
2727+
const Descriptor *Desc = Dest.getFieldDesc();
2728+
2729+
if (Desc->isPrimitive()) {
2730+
TYPE_SWITCH(Desc->getPrimType(), {
2731+
Dest.deref<T>().~T();
2732+
new (&Dest.deref<T>()) T();
2733+
});
2734+
return;
2735+
}
2736+
2737+
if (Desc->isRecord()) {
2738+
const Record *R = Desc->ElemRecord;
2739+
for (const Record::Field &F : R->fields()) {
2740+
Pointer FieldPtr = Dest.atField(F.Offset);
2741+
zeroAll(FieldPtr);
2742+
}
2743+
return;
2744+
}
2745+
2746+
if (Desc->isPrimitiveArray()) {
2747+
for (unsigned I = 0, N = Desc->getNumElems(); I != N; ++I) {
2748+
TYPE_SWITCH(Desc->getPrimType(), {
2749+
Dest.deref<T>().~T();
2750+
new (&Dest.deref<T>()) T();
2751+
});
2752+
}
2753+
return;
2754+
}
2755+
2756+
if (Desc->isCompositeArray()) {
2757+
for (unsigned I = 0, N = Desc->getNumElems(); I != N; ++I) {
2758+
Pointer ElemPtr = Dest.atIndex(I).narrow();
2759+
zeroAll(ElemPtr);
2760+
}
2761+
return;
2762+
}
2763+
}
2764+
27262765
static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
27272766
Pointer &Dest, bool Activate);
27282767
static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
@@ -2751,11 +2790,14 @@ static bool copyRecord(InterpState &S, CodePtr OpPC, const Pointer &Src,
27512790
const Record *R = DestDesc->ElemRecord;
27522791
for (const Record::Field &F : R->fields()) {
27532792
if (R->isUnion()) {
2754-
// For unions, only copy the active field.
2793+
// For unions, only copy the active field. Zero all others.
27552794
const Pointer &SrcField = Src.atField(F.Offset);
27562795
if (SrcField.isActive()) {
27572796
if (!copyField(F, /*Activate=*/true))
27582797
return false;
2798+
} else {
2799+
Pointer DestField = Dest.atField(F.Offset);
2800+
zeroAll(DestField);
27592801
}
27602802
} else {
27612803
if (!copyField(F, Activate))

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,15 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
152152
CharUnits::fromQuantity(asIntPointer().Value + this->Offset),
153153
Path,
154154
/*IsOnePastEnd=*/false, /*IsNullPtr=*/false);
155-
if (isFunctionPointer())
156-
return asFunctionPointer().toAPValue(ASTCtx);
155+
if (isFunctionPointer()) {
156+
const FunctionPointer &FP = asFunctionPointer();
157+
if (const FunctionDecl *FD = FP.getFunction()->getDecl())
158+
return APValue(FD, CharUnits::fromQuantity(FP.getOffset() + Offset), {},
159+
/*OnePastTheEnd=*/false, /*IsNull=*/false);
160+
return APValue(FP.getFunction()->getExpr(),
161+
CharUnits::fromQuantity(FP.getOffset() + Offset), {},
162+
/*OnePastTheEnd=*/false, /*IsNull=*/false);
163+
}
157164

158165
if (isTypeidPointer()) {
159166
TypeInfoLValue TypeInfo(PointeeStorage.Typeid.TypePtr);
@@ -379,6 +386,9 @@ std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const {
379386
if (isIntegralPointer())
380387
return (Twine("&(") + Twine(asIntPointer().Value + Offset) + ")").str();
381388

389+
if (isFunctionPointer())
390+
return asFunctionPointer().toDiagnosticString(Ctx);
391+
382392
return toAPValue(Ctx).getAsString(Ctx, getType());
383393
}
384394

0 commit comments

Comments
 (0)