-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][bytecode] Fix diagnostic difference with opaque call cmps #129702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Try to dig out the call expression and diagnose this as an opaque call.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesTry to dig out the call expression and diagnose this as an opaque call. Full diff: https://github.com/llvm/llvm-project/pull/129702.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2cf7ae2dd6f96..d8f90e45b0ced 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 0c26d40ec5cd5..75380f99901a2 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 {
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/7903 Here is the relevant piece of the build log for the reference
|
…vm#129702) Try to dig out the call expression and diagnose this as an opaque call.
Try to dig out the call expression and diagnose this as an opaque call.