https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/155151
>From 8110e1f0b9059ed08fd005fe6d537520e72dc03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sun, 24 Aug 2025 11:09:51 +0200 Subject: [PATCH] [clang][bytecode] Check that a ltor cast to a complex value is possible When we get to this point, the pointer might _not_ be backed by a primitive array, so the later code will fail. Fixes #155144 --- clang/lib/AST/ByteCode/Pointer.cpp | 5 ++++- clang/test/AST/ByteCode/c.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 38856ad256a63..c3c67227d0236 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -785,8 +785,11 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx, // Complex types. if (const auto *CT = Ty->getAs<ComplexType>()) { - QualType ElemTy = CT->getElementType(); + // Can happen via C casts. + if (!Ptr.getFieldDesc()->isPrimitiveArray()) + return false; + QualType ElemTy = CT->getElementType(); if (ElemTy->isIntegerType()) { OptPrimType ElemT = Ctx.classify(ElemTy); assert(ElemT); diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index 73469d7fd6cc4..eb46330c7d35f 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -173,6 +173,10 @@ _Static_assert(CTB3, ""); // pedantic-ref-warning {{GNU extension}} \ // pedantic-expected-warning {{GNU extension}} +void nonComplexToComplexCast(void) { + _Complex double z = *(_Complex double *)&(struct { double r, i; }){0.0, 1.0}; +} + int t1 = sizeof(int); void test4(void) { t1 = sizeof(int); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits