Author: Timm Baeder Date: 2025-03-04T15:04:57+01:00 New Revision: f838a5e96cb15f3cd70b2f26db0b520004350c7e
URL: https://github.com/llvm/llvm-project/commit/f838a5e96cb15f3cd70b2f26db0b520004350c7e DIFF: https://github.com/llvm/llvm-project/commit/f838a5e96cb15f3cd70b2f26db0b520004350c7e.diff LOG: [clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702) Try to dig out the call expression and diagnose this as an opaque call. Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/test/AST/ByteCode/builtin-functions.cpp Removed: ################################################################################ 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 { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits