diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-17 18:43:32 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-17 18:43:32 +0000 |
commit | 38ad1e6138a964f7412df28f55da13fa4dce4caf (patch) | |
tree | eff6a42c641ca4686a06e52ca391f845fe22f1a7 /clang/lib/CodeGen/CGDecl.cpp | |
parent | 3d926cbf7970c3a072b9c57957f52de3ec7ba5ca (diff) | |
download | bcm5719-llvm-38ad1e6138a964f7412df28f55da13fa4dce4caf.tar.gz bcm5719-llvm-38ad1e6138a964f7412df28f55da13fa4dce4caf.zip |
Change EmitConstantExpr to allow failure.
IRgen no longer relies on isConstantInitializer, instead we just try
to emit the constant. If that fails then in C we emit an error
unsupported (this occurs when Sema accepted something that it doesn't
know how to fold, and IRgen doesn't know how to emit) and in C++ we
emit a guarded initializer.
This ends up handling a few more cases, because IRgen was actually
able to emit some of the constants Sema accepts but can't Evaluate().
For example, PR3398.
llvm-svn: 64780
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index bb2705ff60a..f2fec65cc36 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -88,12 +88,17 @@ CodeGenFunction::GenerateStaticBlockVarDecl(const VarDecl &D, if ((D.getInit() == 0) || NoInit) { Init = llvm::Constant::getNullValue(LTy); } else { - if (D.getInit()->isConstantInitializer(getContext())) - Init = CGM.EmitConstantExpr(D.getInit(), this); - else { - assert(getContext().getLangOptions().CPlusPlus && - "only C++ supports non-constant static initializers!"); - return GenerateStaticCXXBlockVarDecl(D); + Init = CGM.EmitConstantExpr(D.getInit(), this); + + // If constant emission failed, then this should be a C++ static + // initializer. + if (!Init) { + if (!getContext().getLangOptions().CPlusPlus) { + CGM.ErrorUnsupported(D.getInit(), "constant l-value expression"); + Init = llvm::Constant::getNullValue(LTy); + } else { + return GenerateStaticCXXBlockVarDecl(D); + } } } |