From 5f14fcbd45870585a136ae735d29d0e085c0d7f8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 23 Oct 2012 02:04:01 +0000 Subject: [PATCH] Don't try to use inreg with 0 sized structs. Thanks to Eli for reporting the regression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166461 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetInfo.cpp | 4 ++++ test/CodeGenCXX/regparm.cpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index a9e11cb954..6a929a17cc 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -810,6 +810,10 @@ bool X86_32ABIInfo::shouldUseInReg(QualType Ty, unsigned &FreeRegs) const { return false; unsigned SizeInRegs = (getContext().getTypeSize(Ty) + 31) / 32; + + if (SizeInRegs == 0) + return false; + if (SizeInRegs > FreeRegs) { FreeRegs = 0; return false; diff --git a/test/CodeGenCXX/regparm.cpp b/test/CodeGenCXX/regparm.cpp index 07e9aa046e..2196c798bf 100644 --- a/test/CodeGenCXX/regparm.cpp +++ b/test/CodeGenCXX/regparm.cpp @@ -21,7 +21,18 @@ struct S2 { }; void __attribute__((regparm(3))) foo3(struct S2 a, int b); -// declare void @_Z4foo12S1i(i32 inreg, i32 inreg) optsize +// CHECK: declare void @_Z4foo32S2i(i32 inreg, i32 inreg) void bar3(struct S2 a, int b) { foo3(a, b); } + +struct S3 { + struct { + struct {} b[0]; + } a; +}; +__attribute((regparm(2))) void foo4(S3 a, int b); +// CHECK: declare void @_Z4foo42S3i(%struct.S3* byval align 4, i32 inreg) +void bar3(S3 a, int b) { + foo4(a, b); +} -- 2.40.0