Skip to content

Commit 7133283

Browse files
committed
[clang] Do not attempt to zero-extend _BitInt(1) when not required
`ConvertTypeForMem` doesn't return wider type for _BitInt unless it is used in a bitfield, so no need to extend when trying to initialize a global variable. Fixes #62207 Reviewed By: erichkeane, shafik Differential Revision: https://reviews.llvm.org/D149436
1 parent 1d0cceb commit 7133283

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ Bug Fixes in This Version
337337
(`#62296 <https://github.com/llvm/llvm-project/issues/62296>`_)
338338
- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
339339
(`#60082` <https://github.com/llvm/llvm-project/issues/60082>`_)
340+
- Fix the assertion hit when generating code for global variable initializer of
341+
_BitInt(1) type.
342+
(`#62207 <https://github.com/llvm/llvm-project/issues/62207>`_)
340343

341344
Bug Fixes to Compiler Builtins
342345
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM,
17301730
}
17311731

17321732
// Zero-extend bool.
1733-
if (C->getType()->isIntegerTy(1)) {
1733+
if (C->getType()->isIntegerTy(1) && !destType->isBitIntType()) {
17341734
llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType);
17351735
return llvm::ConstantExpr::getZExt(C, boolTy);
17361736
}

clang/test/CodeGen/ext-int.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN32
44
// RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
55

6+
//GH62207
7+
unsigned _BitInt(1) GlobSize1 = 0;
8+
// CHECK: @GlobSize1 = {{.*}}global i1 false
9+
610
void GenericTest(_BitInt(3) a, unsigned _BitInt(3) b, _BitInt(4) c) {
711
// CHECK: define {{.*}}void @GenericTest
812
int which = _Generic(a, _BitInt(3): 1, unsigned _BitInt(3) : 2, _BitInt(4) : 3);

0 commit comments

Comments
 (0)