[clang] [CodeGen] Fix handling of nullptr in initializers (PR #137364)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 25 10:02:34 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Alexander Kornienko (alexfh)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/137276.
---
Full diff: https://github.com/llvm/llvm-project/pull/137364.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+4-2)
- (added) clang/test/CodeGenCXX/pr137276.cpp (+13)
``````````diff
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{{$}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/137364
More information about the cfe-commits
mailing list