Skip to content

Commit fc5cf32

Browse files
committed
merge main into amd-staging
Change-Id: Ie530799cb3c9a585bfb3047021e7fc05e8873f03
2 parents 1162309 + 7dcca62 commit fc5cf32

File tree

123 files changed

+13184
-4706
lines changed

Some content is hidden

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

123 files changed

+13184
-4706
lines changed

clang/include/clang/Basic/BuiltinsAArch64.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", INTRIN_H, ALL_MS_LA
139139
TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
140140

141141
TARGET_HEADER_BUILTIN(_InterlockedAdd, "NiNiD*Ni", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
142+
TARGET_HEADER_BUILTIN(_InterlockedAdd64, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
142143
TARGET_HEADER_BUILTIN(_InterlockedAnd64, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
143144
TARGET_HEADER_BUILTIN(_InterlockedDecrement64, "LLiLLiD*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
144145
TARGET_HEADER_BUILTIN(_InterlockedExchange64, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,10 +1446,13 @@ bool ByteCodeExprGen<Emitter>::VisitPointerCompoundAssignOperator(
14461446
if (!visit(RHS))
14471447
return false;
14481448

1449-
if (Op == BO_AddAssign)
1450-
this->emitAddOffset(*RT, E);
1451-
else
1452-
this->emitSubOffset(*RT, E);
1449+
if (Op == BO_AddAssign) {
1450+
if (!this->emitAddOffset(*RT, E))
1451+
return false;
1452+
} else {
1453+
if (!this->emitSubOffset(*RT, E))
1454+
return false;
1455+
}
14531456

14541457
if (DiscardResult)
14551458
return this->emitStorePopPtr(E);

clang/lib/AST/Interp/Context.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
8888
assert(Stk.empty());
8989
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);
9090

91-
auto Res = C.interpretDecl(VD);
91+
bool CheckGlobalInitialized =
92+
shouldBeGloballyIndexed(VD) &&
93+
(VD->getType()->isRecordType() || VD->getType()->isArrayType());
94+
auto Res = C.interpretDecl(VD, CheckGlobalInitialized);
9295
if (Res.isInvalid()) {
9396
Stk.clear();
9497
return false;
@@ -101,25 +104,7 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
101104
Stk.clear();
102105
#endif
103106

104-
// Ensure global variables are fully initialized.
105-
if (shouldBeGloballyIndexed(VD) &&
106-
(VD->getType()->isRecordType() || VD->getType()->isArrayType() ||
107-
VD->getType()->isAnyComplexType())) {
108-
assert(Res.isLValue());
109-
110-
if (!VD->getType()->isAnyComplexType() &&
111-
!Res.checkFullyInitialized(C.getState()))
112-
return false;
113-
114-
// lvalue-to-rvalue conversion. We do this manually here so we can
115-
// examine the result above before converting and returning it.
116-
std::optional<APValue> RValueResult = Res.toRValue();
117-
if (!RValueResult)
118-
return false;
119-
Result = *RValueResult;
120-
121-
} else
122-
Result = Res.toAPValue();
107+
Result = Res.toAPValue();
123108
return true;
124109
}
125110

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
4444
return std::move(this->EvalResult);
4545
}
4646

47-
EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD) {
47+
EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
48+
bool CheckFullyInitialized) {
49+
this->CheckFullyInitialized = CheckFullyInitialized;
4850
EvalResult.setSource(VD);
4951

5052
if (!this->visitDecl(VD) && EvalResult.empty())
@@ -131,7 +133,17 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
131133
return false;
132134
}
133135
} else {
134-
EvalResult.setPointer(Ptr);
136+
if (CheckFullyInitialized) {
137+
if (!EvalResult.checkFullyInitialized(S, Ptr))
138+
return false;
139+
140+
std::optional<APValue> RValueResult = Ptr.toRValue(Ctx);
141+
if (!RValueResult)
142+
return false;
143+
EvalResult.setValue(*RValueResult);
144+
} else {
145+
EvalResult.setValue(Ptr.toAPValue());
146+
}
135147
}
136148

137149
return true;

clang/lib/AST/Interp/EvalEmitter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EvalEmitter : public SourceMapper {
3636

3737
EvaluationResult interpretExpr(const Expr *E,
3838
bool ConvertResultToRValue = false);
39-
EvaluationResult interpretDecl(const VarDecl *VD);
39+
EvaluationResult interpretDecl(const VarDecl *VD, bool CheckFullyInitialized);
4040

4141
InterpState &getState() { return S; }
4242

@@ -89,6 +89,9 @@ class EvalEmitter : public SourceMapper {
8989
EvaluationResult EvalResult;
9090
/// Whether the result should be converted to an RValue.
9191
bool ConvertResultToRValue = false;
92+
/// Whether we should check if the result has been fully
93+
/// initialized.
94+
bool CheckFullyInitialized = false;
9295

9396
/// Temporaries which require storage.
9497
llvm::DenseMap<unsigned, std::unique_ptr<char[]>> Locals;

clang/lib/AST/Interp/EvaluationResult.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
132132
return Result;
133133
}
134134

135-
bool EvaluationResult::checkFullyInitialized(InterpState &S) const {
135+
bool EvaluationResult::checkFullyInitialized(InterpState &S,
136+
const Pointer &Ptr) const {
136137
assert(Source);
137-
assert(isLValue());
138+
assert(empty());
138139

139140
// Our Source must be a VarDecl.
140141
const Decl *SourceDecl = Source.dyn_cast<const Decl *>();
@@ -143,7 +144,6 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S) const {
143144
assert(VD->getType()->isRecordType() || VD->getType()->isArrayType());
144145
SourceLocation InitLoc = VD->getAnyInitializer()->getExprLoc();
145146

146-
const Pointer &Ptr = *std::get_if<Pointer>(&Value);
147147
assert(!Ptr.isZero());
148148

149149
if (const Record *R = Ptr.getRecord())

clang/lib/AST/Interp/EvaluationResult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class EvaluationResult final {
9797
/// LValue and we can't read from it.
9898
std::optional<APValue> toRValue() const;
9999

100-
bool checkFullyInitialized(InterpState &S) const;
100+
bool checkFullyInitialized(InterpState &S, const Pointer &Ptr) const;
101101

102102
/// Dump to stderr.
103103
void dump() const;

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,15 @@ static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
658658
return true;
659659
}
660660

661+
static bool interp__builtin_launder(InterpState &S, CodePtr OpPC,
662+
const InterpFrame *Frame,
663+
const Function *Func,
664+
const CallExpr *Call) {
665+
const Pointer &Arg = S.Stk.peek<Pointer>();
666+
S.Stk.push<Pointer>(Arg);
667+
return true;
668+
}
669+
661670
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
662671
const CallExpr *Call) {
663672
InterpFrame *Frame = S.Current;
@@ -887,6 +896,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
887896
return false;
888897
break;
889898

899+
case Builtin::BI__builtin_launder:
900+
if (!interp__builtin_launder(S, OpPC, Frame, F, Call))
901+
return false;
902+
break;
903+
890904
default:
891905
return false;
892906
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12047,7 +12047,8 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
1204712047
"vgetq_lane");
1204812048
}
1204912049

12050-
case clang::AArch64::BI_InterlockedAdd: {
12050+
case clang::AArch64::BI_InterlockedAdd:
12051+
case clang::AArch64::BI_InterlockedAdd64: {
1205112052
Address DestAddr = CheckAtomicAlignment(*this, E);
1205212053
Value *Val = EmitScalarExpr(E->getArg(1));
1205312054
AtomicRMWInst *RMWI =

clang/lib/Headers/intrin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
551551
#if defined(__aarch64__)
552552
unsigned __int64 __getReg(int);
553553
long _InterlockedAdd(long volatile *Addend, long Value);
554+
__int64 _InterlockedAdd64(__int64 volatile *Addend, __int64 Value);
554555
__int64 _ReadStatusReg(int);
555556
void _WriteStatusReg(int, __int64);
556557

0 commit comments

Comments
 (0)