Author: Timm Baeder Date: 2026-06-07T09:13:24+02:00 New Revision: 18ad6a5e073f312d3369803cf607fe9bb66a587d
URL: https://github.com/llvm/llvm-project/commit/18ad6a5e073f312d3369803cf607fe9bb66a587d DIFF: https://github.com/llvm/llvm-project/commit/18ad6a5e073f312d3369803cf607fe9bb66a587d.diff LOG: [clang][bytecode] Register global constexpr-unknown variables with their pointee type (#201347) Added: Modified: clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ByteCode/Program.cpp clang/test/SemaCXX/constant-expression-p2280r4.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index ee3813a9287be..501c7f76a0376 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -370,6 +370,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC, if (ID == Builtin::BIstrlen || ID == Builtin::BIwcslen) diagnoseNonConstexprBuiltin(S, OpPC, ID); + if (StrPtr.isConstexprUnknown()) + return false; + if (!CheckArray(S, OpPC, StrPtr)) return false; diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 28ebb21ccbe69..1427724ec427c 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -251,6 +251,12 @@ UnsignedOrNone Program::createGlobal(const DeclTy &D, QualType Ty, bool IsStatic, bool IsExtern, bool IsWeak, bool IsConstexprUnknown, const Expr *Init) { + // Since this global variable is constexpr-unknown and a reference, register + // the pointee type instead. When referencing the variable, the pointer will + // then be of the pointee type instead of just PT_Ptr. + if (Ty->isReferenceType() && IsConstexprUnknown) + Ty = Ty->getPointeeType(); + // Create a descriptor for the global. Descriptor *Desc; const bool IsConst = Ty.isConstQualified(); diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp b/clang/test/SemaCXX/constant-expression-p2280r4.cpp index 8b768f42d1260..57b6f6fb3a3dd 100644 --- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp +++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp @@ -369,8 +369,7 @@ namespace enable_if_2 { namespace GH150015 { extern int (& c)[8]; - constexpr int x = c <= c+8; // interpreter-error {{constexpr variable 'x' must be initialized by a constant expression}} \ - // interpreter-note {{cannot refer to element 8 of non-array object in a constant expression}} + constexpr int x = c <= c+8; struct X {}; struct Y {}; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
