Skip to content

Commit f5856f8

Browse files
Merge branch 'main' into constexpr-string-erase
2 parents 073d679 + 53d433e commit f5856f8

File tree

81 files changed

+1736
-597
lines changed

Some content is hidden

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

81 files changed

+1736
-597
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,8 @@ bool Compiler<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
28432843

28442844
assert(Initializing);
28452845
const Record *R = P.getOrCreateRecord(E->getLambdaClass());
2846+
if (!R)
2847+
return false;
28462848

28472849
auto *CaptureInitIt = E->capture_init_begin();
28482850
// Initialize all fields (which represent lambda captures) of the
@@ -4087,9 +4089,8 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
40874089
} else if (D->isRecord()) {
40884090
if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
40894091
return false;
4090-
} else {
4091-
assert(false);
4092-
}
4092+
} else
4093+
return false;
40934094

40944095
if (!this->emitFinishInitPop(E))
40954096
return false;

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ Descriptor::Descriptor(const DeclTy &D, const Record *R, MetadataSize MD,
404404
}
405405

406406
/// Dummy.
407-
Descriptor::Descriptor(const DeclTy &D)
408-
: Source(D), ElemSize(1), Size(1), MDSize(0), AllocSize(MDSize),
409-
ElemRecord(nullptr), IsConst(true), IsMutable(false), IsTemporary(false),
410-
IsDummy(true) {
407+
Descriptor::Descriptor(const DeclTy &D, MetadataSize MD)
408+
: Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
409+
AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false),
410+
IsTemporary(false), IsDummy(true) {
411411
assert(Source && "Missing source");
412412
}
413413

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct Descriptor final {
200200
bool IsTemporary, bool IsMutable);
201201

202202
/// Allocates a dummy descriptor.
203-
Descriptor(const DeclTy &D);
203+
Descriptor(const DeclTy &D, MetadataSize MD = std::nullopt);
204204

205205
/// Make this descriptor a dummy descriptor.
206206
void makeDummy() { IsDummy = true; }
@@ -263,7 +263,7 @@ struct Descriptor final {
263263
bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
264264

265265
/// Checks if the descriptor is of a primitive.
266-
bool isPrimitive() const { return !IsArray && !ElemRecord; }
266+
bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
267267

268268
/// Checks if the descriptor is of an array.
269269
bool isArray() const { return IsArray; }

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,8 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10651065
for (const auto &P : {LHS, RHS}) {
10661066
if (P.isZero())
10671067
continue;
1068-
if (BothNonNull && P.pointsToLiteral()) {
1068+
if (BothNonNull && P.pointsToLiteral() &&
1069+
isa<StringLiteral>(P.getDeclDesc()->asExpr())) {
10691070
const SourceInfo &Loc = S.Current->getSource(OpPC);
10701071
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
10711072
return false;

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
248248
Index = Ptr.getIndex();
249249

250250
QualType ElemType = Desc->getElemQualType();
251-
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
251+
if (const auto *RD = ElemType->getAsRecordDecl();
252+
RD && !RD->getDefinition()) {
253+
// Ignore this for the offset.
254+
} else {
255+
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
256+
}
252257
if (Ptr.getArray().getType()->isArrayType())
253258
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
254259
Ptr = Ptr.getArray();

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
393393
if (const auto *Record = getOrCreateRecord(RT->getDecl()))
394394
return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
395395
IsMutable);
396+
return allocateDescriptor(D, MDSize);
396397
}
397398

398399
// Arrays.

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, const Expr &RHS,
6060
Value *LHSValue = Env.getValue(LHS);
6161
Value *RHSValue = Env.getValue(RHS);
6262

63-
if (LHSValue == RHSValue)
63+
// When two unsupported values are compared, both are nullptr. Only supported
64+
// values should evaluate to equal.
65+
if (LHSValue == RHSValue && LHSValue)
6466
return Env.getBoolLiteralValue(true);
6567

6668
if (auto *LHSBool = dyn_cast_or_null<BoolValue>(LHSValue))
@@ -798,6 +800,14 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
798800
Env.setValue(*S, Env.getIntLiteralValue(S->getValue()));
799801
}
800802

803+
// Untyped nullptr's aren't handled by NullToPointer casts, so they need to be
804+
// handled separately.
805+
void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
806+
auto &NullPointerVal =
807+
Env.getOrCreateNullPointerValue(S->getType()->getPointeeType());
808+
Env.setValue(*S, NullPointerVal);
809+
}
810+
801811
void VisitParenExpr(const ParenExpr *S) {
802812
// The CFG does not contain `ParenExpr` as top-level statements in basic
803813
// blocks, however manual traversal to sub-expressions may encounter them.

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ namespace shufflevector {
10081008

10091009
namespace FunctionStart {
10101010
void a(void) {}
1011-
static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \
1011+
static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an integral constant expression}} \
10121012
// ref-note {{comparison against opaque constant address '&__builtin_function_start(a)'}} \
1013-
// expected-note {{comparison of addresses of potentially overlapping literals has unspecified value}}
1013+
// expected-error {{static assertion failed}}
10141014
}
10151015

10161016
namespace BuiltinInImplicitCtor {

clang/test/AST/ByteCode/functions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,18 @@ namespace AddressOf {
484484
void testAddressof(int x) {
485485
static_assert(&x == __builtin_addressof(x), "");
486486
}
487+
488+
struct TS {
489+
constexpr bool f(TS s) const {
490+
/// The addressof call has a CXXConstructExpr as a parameter.
491+
return this != __builtin_addressof(s);
492+
}
493+
};
494+
constexpr bool exprAddressOf() {
495+
TS s;
496+
return s.f(s);
497+
}
498+
static_assert(exprAddressOf(), "");
487499
}
488500

489501
namespace std {

clang/test/AST/ByteCode/records.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,3 +1747,15 @@ namespace CtorOfInvalidClass {
17471747
template<ReferenceOf<InvalidCtor> auto R, typename Rep> int F; // both-error {{non-type template argument is not a constant expression}}
17481748
#endif
17491749
}
1750+
1751+
namespace IncompleteTypes {
1752+
struct Incomplete;
1753+
1754+
constexpr bool foo() {
1755+
extern Incomplete bounded[10];
1756+
extern Incomplete unbounded[];
1757+
extern Incomplete IT;
1758+
return true;
1759+
}
1760+
static_assert(foo(), "");
1761+
}

0 commit comments

Comments
 (0)