Skip to content

Commit f838a5e

Browse files
authored
[clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702)
Try to dig out the call expression and diagnose this as an opaque call.
1 parent b2d70e8 commit f838a5e

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,14 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10061006
}
10071007
}
10081008

1009+
static inline bool IsOpaqueConstantCall(const CallExpr *E) {
1010+
unsigned Builtin = E->getBuiltinCallee();
1011+
return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
1012+
Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
1013+
Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
1014+
Builtin == Builtin::BI__builtin_function_start);
1015+
}
1016+
10091017
template <>
10101018
inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10111019
using BoolT = PrimConv<PT_Bool>::T;
@@ -1065,11 +1073,19 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10651073
for (const auto &P : {LHS, RHS}) {
10661074
if (P.isZero())
10671075
continue;
1068-
if (BothNonNull && P.pointsToLiteral() &&
1069-
isa<StringLiteral>(P.getDeclDesc()->asExpr())) {
1070-
const SourceInfo &Loc = S.Current->getSource(OpPC);
1071-
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
1072-
return false;
1076+
if (BothNonNull && P.pointsToLiteral()) {
1077+
const Expr *E = P.getDeclDesc()->asExpr();
1078+
if (isa<StringLiteral>(E)) {
1079+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1080+
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
1081+
return false;
1082+
} else if (const auto *CE = dyn_cast<CallExpr>(E);
1083+
CE && IsOpaqueConstantCall(CE)) {
1084+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1085+
S.FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
1086+
<< P.toDiagnosticString(S.getASTContext());
1087+
return false;
1088+
}
10731089
}
10741090
}
10751091

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

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

10091009
namespace FunctionStart {
10101010
void a(void) {}
1011-
static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an integral constant expression}} \
1012-
// ref-note {{comparison against opaque constant address '&__builtin_function_start(a)'}} \
1013-
// expected-error {{static assertion failed}}
1011+
static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \
1012+
// both-note {{comparison against opaque constant address '&__builtin_function_start(a)'}}
10141013
}
10151014

10161015
namespace BuiltinInImplicitCtor {

0 commit comments

Comments
 (0)