summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-05-29 11:22:45 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-05-29 11:22:45 +0000
commit045bf4ff82d728be5e8305670716641fb9685def (patch)
treefcc66ee04e0e382bf4dbc32e34c78209d6c38ad9
parent174d9c26f14b5503082a4c90abdfe1ac00a3369b (diff)
downloadbcm5719-llvm-045bf4ff82d728be5e8305670716641fb9685def.tar.gz
bcm5719-llvm-045bf4ff82d728be5e8305670716641fb9685def.zip
Add codegen support for a few more kinds of initializer constant
expressions. llvm-svn: 51677
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp35
-rw-r--r--clang/test/CodeGen/const-init.c4
2 files changed, 38 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index a0484bc35e1..a642fd236d3 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -296,6 +296,10 @@ public:
static_cast<uint32_t>(CGM.getContext().getTypeSize(E->getType()));
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
}
+
+ llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) {
+ return Visit(E->getSubExpr());
+ }
// Binary operators
llvm::Constant *VisitBinOr(const BinaryOperator *E) {
@@ -380,6 +384,37 @@ public:
return llvm::ConstantExpr::getAnd(LHS, RHS);
}
+
+ llvm::Constant *VisitBinNE(const BinaryOperator *E) {
+ llvm::Constant *LHS = Visit(E->getLHS());
+ llvm::Constant *RHS = Visit(E->getRHS());
+
+ const llvm::Type* ResultType = ConvertType(E->getType());
+ if (!ResultType->isInteger()) {
+ CGM.WarnUnsupported(E, "constant expression");
+ return llvm::Constant::getNullValue(ConvertType(E->getType()));
+ }
+ llvm::Constant *Result =
+ llvm::ConstantExpr::getICmp(llvm::ICmpInst::ICMP_NE, LHS, RHS);
+ return llvm::ConstantExpr::getZExtOrBitCast(Result, ResultType);
+ }
+
+ llvm::Constant *VisitConditionalOperator(const ConditionalOperator *E) {
+ llvm::Constant *Cond = Visit(E->getCond());
+ llvm::Constant *CondVal = EmitConversionToBool(Cond, E->getType());
+ llvm::ConstantInt *CondValInt = dyn_cast<llvm::ConstantInt>(CondVal);
+ if (!CondValInt) {
+ CGM.WarnUnsupported(E, "constant expression");
+ return llvm::Constant::getNullValue(ConvertType(E->getType()));
+ }
+ if (CondValInt->isOne()) {
+ if (E->getLHS())
+ return Visit(E->getLHS());
+ return Cond;
+ }
+
+ return Visit(E->getRHS());
+ }
// Utility methods
const llvm::Type *ConvertType(QualType T) {
diff --git a/clang/test/CodeGen/const-init.c b/clang/test/CodeGen/const-init.c
index e3f110d64ed..ccc34cf1368 100644
--- a/clang/test/CodeGen/const-init.c
+++ b/clang/test/CodeGen/const-init.c
@@ -1,4 +1,4 @@
-// RUN: clang -emit-llvm %s
+// RUN: clang -emit-llvm %s 2>&1 | not grep warning
#include <stdint.h>
@@ -11,3 +11,5 @@ intptr_t b = a;
int c();
void *d = c;
intptr_t e = c;
+
+int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f;
OpenPOWER on IntegriCloud