[cfe-commits] r51677 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/const-init.c

Eli Friedman eli.friedman at gmail.com
Thu May 29 04:22:53 PDT 2008


Author: efriedma
Date: Thu May 29 06:22:45 2008
New Revision: 51677

URL: http://llvm.org/viewvc/llvm-project?rev=51677&view=rev
Log:
Add codegen support for a few more kinds of initializer constant 
expressions.


Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGen/const-init.c

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=51677&r1=51676&r2=51677&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu May 29 06:22:45 2008
@@ -296,6 +296,10 @@
       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 @@
 
     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) {

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=51677&r1=51676&r2=51677&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Thu May 29 06:22:45 2008
@@ -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 @@
 int c();
 void *d = c;
 intptr_t e = c;
+
+int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f;





More information about the cfe-commits mailing list