diff options
| -rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 11 | ||||
| -rw-r--r-- | clang/test/CodeGen/bool-init.c | 4 | 
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 4cb3c7bb2a0..be9eaad9acf 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -793,13 +793,18 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,                                                  CodeGenFunction *CGF)  {    QualType type = E->getType().getCanonicalType(); -   +    if (type->isIntegerType()) {      llvm::APSInt Value(static_cast<uint32_t>(Context.getTypeSize(type)));      if (E->isIntegerConstantExpr(Value, Context)) {        return llvm::ConstantInt::get(Value);      }     } -   -  return ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); + +  llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); +  if (C->getType() == llvm::Type::Int1Ty) { +    const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); +    C = llvm::ConstantExpr::getZExt(C, BoolTy); +  } +  return C;  } diff --git a/clang/test/CodeGen/bool-init.c b/clang/test/CodeGen/bool-init.c new file mode 100644 index 00000000000..2e5d56a0a1c --- /dev/null +++ b/clang/test/CodeGen/bool-init.c @@ -0,0 +1,4 @@ +// RUN: clang -emit-llvm < %s | grep i1 | count 1 + +// Check that the type of this global isn't i1 +_Bool test = &test;  | 

