https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/154496
None >From de2d5cc98607fe8f6427ef24b4f9c228cf59f0e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 20 Aug 2025 11:30:22 +0200 Subject: [PATCH] [clang][bytecode] Call CheckFinalLoad in all language modes --- clang/lib/AST/ByteCode/EvalEmitter.cpp | 4 +--- clang/test/AST/ByteCode/cxx98.cpp | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 68f46c113ff28..1ebadae811bdf 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -213,10 +213,8 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { if (!Ptr.isZero() && !Ptr.isDereferencable()) return false; - if (S.getLangOpts().CPlusPlus11 && Ptr.isBlockPointer() && - !CheckFinalLoad(S, OpPC, Ptr)) { + if (!Ptr.isZero() && !CheckFinalLoad(S, OpPC, Ptr)) return false; - } // Never allow reading from a non-const pointer, unless the memory // has been created in this evaluation. diff --git a/clang/test/AST/ByteCode/cxx98.cpp b/clang/test/AST/ByteCode/cxx98.cpp index c17049b01c1da..1150a4e41edc1 100644 --- a/clang/test/AST/ByteCode/cxx98.cpp +++ b/clang/test/AST/ByteCode/cxx98.cpp @@ -18,13 +18,12 @@ template struct C<cval>; /// FIXME: This example does not get properly diagnosed in the new interpreter. extern const int recurse1; -const int recurse2 = recurse1; // both-note {{declared here}} +const int recurse2 = recurse1; // ref-note {{declared here}} const int recurse1 = 1; int array1[recurse1]; int array2[recurse2]; // ref-warning 2{{variable length array}} \ - // both-note {{initializer of 'recurse2' is not a constant expression}} \ - // expected-warning {{variable length array}} \ - // expected-error {{variable length array}} + // ref-note {{initializer of 'recurse2' is not a constant expression}} \ + // expected-warning 2{{variable length array}} int NCI; // both-note {{declared here}} int NCIA[NCI]; // both-warning {{variable length array}} \ @@ -64,3 +63,20 @@ const int b = 1 / 0; // both-warning {{division by zero is undefined}} \ // both-note {{declared here}} _Static_assert(b, ""); // both-error {{not an integral constant expression}} \ // both-note {{initializer of 'b' is not a constant expression}} + +#ifdef __SIZEOF_INT128__ +/// The if statement tries an ltor conversion on an inactive union member. +union InactiveReadUnion{ + int a; + __uint128_t n; +}; + +int inactiveRead(void) { + const InactiveReadUnion U = {1}; + + if (U.n) + return 1; + + return 0; +} +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits