Author: Timm Baeder Date: 2026-09-24T13:04:24+02:00 New Revision: 0145ade4fb7c16780a76fb54138974892a941857
URL: https://github.com/llvm/llvm-project/commit/0145ade4fb7c16780a76fb54138974892a941857 DIFF: https://github.com/llvm/llvm-project/commit/0145ade4fb7c16780a76fb54138974892a941857.diff LOG: [clang][bytecode] Diagnose array-to-pointer-decays on unsized opaque pointers (#226027) Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/test/AST/ByteCode/invalid.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 14988eb9acb53..a106295022f9b 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -3633,10 +3633,19 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) { return true; } - if (!Ptr.getType()->isArrayType()) { + const OpaquePointer &OP = Ptr.asOpaquePointer(); + if (!OP.getFieldType()->isArrayType()) { S.Stk.push<Pointer>(Ptr); return true; } + + if (OP.isUnknownSizeArray() && OP.PathLength != 0) { + S.FFDiag(S.Current->getSource(OpPC), + diag::note_constexpr_unsupported_unsized_array); + S.Stk.push<Pointer>(Ptr); + return true; + } + return arrayElemPtrOpaque(S, OpPC, Ptr, APSInt(APInt::getZero(1), /*IsUnsigned=*/true), /*AllowReplace=*/false); diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp index 565d65f60514a..52c91f46ac16d 100644 --- a/clang/test/AST/ByteCode/invalid.cpp +++ b/clang/test/AST/ByteCode/invalid.cpp @@ -301,3 +301,15 @@ namespace CompositeFieldInit { constexpr S2 s2{}; } + +namespace UnsizedArrayAndNonEmptyPath { + void foo() { + struct S { + int m[]; + } s; + constexpr auto p = s.m; // both-error {{must be initialized by a constant expression}} \ + // both-note {{array-to-pointer decay of array member without known bound is not supported}} + } + + void bar() { foo(); } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
