[cfe-commits] r46480 - in /cfe/trunk: CodeGen/CGExprConstant.cpp CodeGen/CGExprScalar.cpp test/CodeGen/globalinit.c test/CodeGen/init.c
Chris Lattner
clattner at apple.com
Tue Jan 29 21:57:55 PST 2008
On Jan 28, 2008, at 5:15 PM, Anders Carlsson wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=46480&view=rev
> Log:
> Correctly handle scalars in braces.
Hey Anders,
I think that redundant braces can occur anywhere, not just around
scalars (Steve, please verify). If so, it seems like all the codegen
logic should check for these, and perhaps InitListExpr should grow an
"isRedundantInitList() method or something to decide this. Given
this, we can simplify some code:
> llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
> + const llvm::CompositeType *CType =
> + dyn_cast<llvm::CompositeType>(ConvertType(ILE->getType()));
> +
> + if (!CType) {
> + // We have a scalar in braces. Just use the first element.
> + return Visit(ILE->getInit(0));
> }
1) This should just check to see if the init list expr is 'redundant'
2) you have some crazy indentation here
3) ILE may not have an element #0: "{}"
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
> +++ cfe/trunk/CodeGen/CGExprScalar.cpp Mon Jan 28 19:15:48 2008
> @@ -130,7 +130,11 @@
> unsigned NumInitElements = E->getNumInits();
>
> const llvm::VectorType *VType =
> - cast<llvm::VectorType>(ConvertType(E->getType()));
> + dyn_cast<llvm::VectorType>(ConvertType(E->getType()));
In general, treat ConvertType as an expensive method. Is there any
other way to tell this information? Maybe you can get it from the C
type?
-Chris
More information about the cfe-commits
mailing list