Skip to content

Commit 5431de1

Browse files
committed
[CodeGen] Fix handling of nullptr in initializers
Fixes #137276.
1 parent df21288 commit 5431de1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,14 @@ CodeGenTypes::getCGRecordLayout(const RecordDecl *RD) {
850850
}
851851

852852
bool CodeGenTypes::isPointerZeroInitializable(QualType T) {
853-
assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid type");
853+
assert((T->isAnyPointerType() || T->isBlockPointerType() ||
854+
T->isNullPtrType()) &&
855+
"Invalid type");
854856
return isZeroInitializable(T);
855857
}
856858

857859
bool CodeGenTypes::isZeroInitializable(QualType T) {
858-
if (T->getAs<PointerType>())
860+
if (T->getAs<PointerType>() || T->isNullPtrType())
859861
return Context.getTargetNullPointerValue(T) == 0;
860862

861863
if (const auto *AT = Context.getAsArrayType(T)) {

clang/test/CodeGenCXX/pr137276.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
2+
3+
using ulong = unsigned long;
4+
template <class... Ts>
5+
void g(Ts... args) {
6+
ulong arr[3] = {ulong(args)...};
7+
(void)arr;
8+
}
9+
extern void f() {
10+
g(nullptr, 17);
11+
}
12+
13+
// CHECK: {{^}} store i64 0, ptr %arr, align 8{{$}}

0 commit comments

Comments
 (0)