forked from OSchip/llvm-project
Add codegen support for a few more kinds of initializer constant
expressions. llvm-svn: 51677
This commit is contained in:
parent
174d9c26f1
commit
045bf4ff82
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue