https://github.com/alexfh created https://github.com/llvm/llvm-project/pull/137364
Fixes https://github.com/llvm/llvm-project/issues/137276. >From 5431de1664814a7a2dcc93695eed8745ae6bfef5 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko <ale...@google.com> Date: Fri, 25 Apr 2025 17:51:03 +0200 Subject: [PATCH] [CodeGen] Fix handling of nullptr in initializers Fixes https://github.com/llvm/llvm-project/issues/137276. --- clang/lib/CodeGen/CodeGenTypes.cpp | 6 ++++-- clang/test/CodeGenCXX/pr137276.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenCXX/pr137276.cpp diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index b94c11802a268..d1b292f23c2d2 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -850,12 +850,14 @@ CodeGenTypes::getCGRecordLayout(const RecordDecl *RD) { } bool CodeGenTypes::isPointerZeroInitializable(QualType T) { - assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid type"); + assert((T->isAnyPointerType() || T->isBlockPointerType() || + T->isNullPtrType()) && + "Invalid type"); return isZeroInitializable(T); } bool CodeGenTypes::isZeroInitializable(QualType T) { - if (T->getAs<PointerType>()) + if (T->getAs<PointerType>() || T->isNullPtrType()) return Context.getTargetNullPointerValue(T) == 0; if (const auto *AT = Context.getAsArrayType(T)) { diff --git a/clang/test/CodeGenCXX/pr137276.cpp b/clang/test/CodeGenCXX/pr137276.cpp new file mode 100644 index 0000000000000..0664a121ad6a0 --- /dev/null +++ b/clang/test/CodeGenCXX/pr137276.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s + +using ulong = unsigned long; +template <class... Ts> +void g(Ts... args) { + ulong arr[3] = {ulong(args)...}; + (void)arr; +} +extern void f() { + g(nullptr, 17); +} + +// CHECK: {{^}} store i64 0, ptr %arr, align 8{{$}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits