summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-11-09 02:11:40 +0000
committerTed Kremenek <kremenek@apple.com>2010-11-09 02:11:40 +0000
commit16e6026f019e1117e71e19e450c23c8beabe462d (patch)
tree1376ecbbf9687a89fa90e180b384356acef7474d
parent5db892142264b0840edb990653d0444fee20130d (diff)
downloadbcm5719-llvm-16e6026f019e1117e71e19e450c23c8beabe462d.tar.gz
bcm5719-llvm-16e6026f019e1117e71e19e450c23c8beabe462d.zip
Fix InitListExpr::getSourceRange() to work in the case of no locations for '(' and ')'. This can happen
in the case of transparent unions. llvm-svn: 118472
-rw-r--r--clang/include/clang/AST/Expr.h5
-rw-r--r--clang/lib/AST/Expr.cpp29
2 files changed, 31 insertions, 3 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 3ba0667efc1..d7e8fd8d908 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2934,9 +2934,8 @@ public:
HadArrayRangeDesignator = ARD;
}
- virtual SourceRange getSourceRange() const {
- return SourceRange(LBraceLoc, RBraceLoc);
- }
+ virtual SourceRange getSourceRange() const;
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == InitListExprClass;
}
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 078bd7c8a1b..7d05bdb2648 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1028,6 +1028,35 @@ Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) {
return Result;
}
+SourceRange InitListExpr::getSourceRange() const {
+ if (SyntacticForm)
+ return SyntacticForm->getSourceRange();
+ SourceLocation Beg = LBraceLoc, End = RBraceLoc;
+ if (Beg.isInvalid()) {
+ // Find the first non-null initializer.
+ for (InitExprsTy::const_iterator I = InitExprs.begin(),
+ E = InitExprs.end();
+ I != E; ++I) {
+ if (Stmt *S = *I) {
+ Beg = S->getLocStart();
+ break;
+ }
+ }
+ }
+ if (End.isInvalid()) {
+ // Find the first non-null initializer from the end.
+ for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
+ E = InitExprs.rend();
+ I != E; ++I) {
+ if (Stmt *S = *I) {
+ End = S->getSourceRange().getEnd();
+ break;
+ }
+ }
+ }
+ return SourceRange(Beg, End);
+}
+
/// getFunctionType - Return the underlying function type for this block.
///
const FunctionType *BlockExpr::getFunctionType() const {
OpenPOWER on IntegriCloud