diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-11-09 02:11:40 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-11-09 02:11:40 +0000 |
| commit | 16e6026f019e1117e71e19e450c23c8beabe462d (patch) | |
| tree | 1376ecbbf9687a89fa90e180b384356acef7474d /clang/lib | |
| parent | 5db892142264b0840edb990653d0444fee20130d (diff) | |
| download | bcm5719-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
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 { |

