aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/AST/ByteCode/Interp.h26
-rw-r--r--clang/test/AST/ByteCode/builtin-functions.cpp5
2 files changed, 23 insertions, 8 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2cf7ae2..d8f90e4 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1006,6 +1006,14 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
}
}
+static inline bool IsOpaqueConstantCall(const CallExpr *E) {
+ unsigned Builtin = E->getBuiltinCallee();
+ return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
+ Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+ Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
+ Builtin == Builtin::BI__builtin_function_start);
+}
+
template <>
inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
using BoolT = PrimConv<PT_Bool>::T;
@@ -1065,11 +1073,19 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
for (const auto &P : {LHS, RHS}) {
if (P.isZero())
continue;
- if (BothNonNull && P.pointsToLiteral() &&
- isa<StringLiteral>(P.getDeclDesc()->asExpr())) {
- const SourceInfo &Loc = S.Current->getSource(OpPC);
- S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
- return false;
+ if (BothNonNull && P.pointsToLiteral()) {
+ const Expr *E = P.getDeclDesc()->asExpr();
+ if (isa<StringLiteral>(E)) {
+ const SourceInfo &Loc = S.Current->getSource(OpPC);
+ S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
+ return false;
+ } else if (const auto *CE = dyn_cast<CallExpr>(E);
+ CE && IsOpaqueConstantCall(CE)) {
+ const SourceInfo &Loc = S.Current->getSource(OpPC);
+ S.FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
+ << P.toDiagnosticString(S.getASTContext());
+ return false;
+ }
}
}
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0c26d40..75380f9 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1008,9 +1008,8 @@ namespace shufflevector {
namespace FunctionStart {
void a(void) {}
- static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an integral constant expression}} \
- // ref-note {{comparison against opaque constant address '&__builtin_function_start(a)'}} \
- // expected-error {{static assertion failed}}
+ static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \
+ // both-note {{comparison against opaque constant address '&__builtin_function_start(a)'}}
}
namespace BuiltinInImplicitCtor {