Skip to content

Commit 53d433e

Browse files
authored
[clang][bytecode] Only emit literal_comparison for string literals (#129691)
This is what the current interpreter does as well.
1 parent cd4c10a commit 53d433e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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/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 {

0 commit comments

Comments
 (0)