Fix PR3509 by providing correct starting locations for initializer lists

llvm-svn: 65777
This commit is contained in:
Douglas Gregor 2009-03-01 17:12:46 +00:00
parent 6f8d4ae3c0
commit 5741efbba0
2 changed files with 12 additions and 12 deletions

View File

@ -410,7 +410,7 @@ InitListChecker::InitListChecker(Sema &S, InitListExpr *IL, QualType &T)
unsigned newIndex = 0; unsigned newIndex = 0;
unsigned newStructuredIndex = 0; unsigned newStructuredIndex = 0;
FullyStructuredList FullyStructuredList
= getStructuredSubobjectInit(IL, newIndex, T, 0, 0, SourceRange()); = getStructuredSubobjectInit(IL, newIndex, T, 0, 0, IL->getSourceRange());
CheckExplicitInitList(IL, T, newIndex, FullyStructuredList, newStructuredIndex, CheckExplicitInitList(IL, T, newIndex, FullyStructuredList, newStructuredIndex,
/*TopLevelObject=*/true); /*TopLevelObject=*/true);
@ -470,7 +470,8 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
InitListExpr *StructuredSubobjectInitList InitListExpr *StructuredSubobjectInitList
= getStructuredSubobjectInit(ParentIList, Index, T, StructuredList, = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList,
StructuredIndex, StructuredIndex,
ParentIList->getInit(Index)->getSourceRange()); SourceRange(ParentIList->getInit(Index)->getSourceRange().getBegin(),
ParentIList->getSourceRange().getEnd()));
unsigned StructuredSubobjectInitIndex = 0; unsigned StructuredSubobjectInitIndex = 0;
// Check the element types and build the structural subobject. // Check the element types and build the structural subobject.
@ -481,7 +482,7 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
TopLevelObject); TopLevelObject);
unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1); unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
// Update the structured sub-object initialize so that it's ending // Update the structured sub-object initializer so that it's ending
// range corresponds with the end of the last initializer it used. // range corresponds with the end of the last initializer it used.
if (EndIndex < ParentIList->getNumInits()) { if (EndIndex < ParentIList->getNumInits()) {
SourceLocation EndLoc SourceLocation EndLoc
@ -1088,8 +1089,8 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
// Determine the structural initializer list that corresponds to the // Determine the structural initializer list that corresponds to the
// current subobject. // current subobject.
StructuredList = IsFirstDesignator? SyntacticToSemantic[IList] StructuredList = IsFirstDesignator? SyntacticToSemantic[IList]
: getStructuredSubobjectInit(IList, Index, CurrentObjectType, StructuredList, : getStructuredSubobjectInit(IList, Index, CurrentObjectType,
StructuredIndex, StructuredList, StructuredIndex,
SourceRange(D->getStartLocation(), SourceRange(D->getStartLocation(),
DIE->getSourceRange().getEnd())); DIE->getSourceRange().getEnd()));
assert(StructuredList && "Expected a structured initializer list"); assert(StructuredList && "Expected a structured initializer list");
@ -1421,7 +1422,8 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
// Here, xs[0].a == 0 and xs[0].b == 3, since the second, // Here, xs[0].a == 0 and xs[0].b == 3, since the second,
// designated initializer re-initializes the whole // designated initializer re-initializes the whole
// subobject [0], overwriting previous initializers. // subobject [0], overwriting previous initializers.
SemaRef.Diag(InitRange.getBegin(), diag::warn_subobject_initializer_overrides) SemaRef.Diag(InitRange.getBegin(),
diag::warn_subobject_initializer_overrides)
<< InitRange; << InitRange;
SemaRef.Diag(ExistingInit->getSourceRange().getBegin(), SemaRef.Diag(ExistingInit->getSourceRange().getBegin(),
diag::note_previous_initializer) diag::note_previous_initializer)
@ -1429,12 +1431,10 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
<< ExistingInit->getSourceRange(); << ExistingInit->getSourceRange();
} }
SourceLocation StartLoc;
if (Index < IList->getNumInits())
StartLoc = IList->getInit(Index)->getSourceRange().getBegin();
InitListExpr *Result InitListExpr *Result
= new (SemaRef.Context) InitListExpr(StartLoc, 0, 0, = new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0,
IList->getSourceRange().getEnd()); InitRange.getEnd());
Result->setType(CurrentObjectType); Result->setType(CurrentObjectType);
// Link this new initializer list into the structured initializer // Link this new initializer list into the structured initializer

View File

@ -15,7 +15,7 @@ int f1_a(struct FPRec* foo) {
int f1_b() { int f1_b() {
int x; int x;
return bar(x)+1; // expected-warning{{Pass-by-value argument in function is undefined.}} return bar(x)+1; // expected-warning{{Pass-by-value argument in function call is undefined.}}
} }
int f2() { int f2() {