File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,22 @@ TEST_F(ExtractVariableTest, Test) {
72
72
)cpp" ;
73
73
EXPECT_UNAVAILABLE (NoCrashCasesC);
74
74
75
+ ExtraArgs = {" -xc" };
76
+ const char *NoCrashDesignator = R"cpp(
77
+ struct A {
78
+ struct {
79
+ int x;
80
+ };
81
+ };
82
+ struct B {
83
+ int y;
84
+ };
85
+ void foo(struct B *b) {
86
+ struct A a = {.x=b[[->]]y};
87
+ }
88
+ )cpp" ;
89
+ EXPECT_AVAILABLE (NoCrashDesignator);
90
+
75
91
ExtraArgs = {" -xobjective-c" };
76
92
const char *AvailableObjC = R"cpp(
77
93
__attribute__((objc_root_class))
Original file line number Diff line number Diff line change @@ -4604,8 +4604,17 @@ SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const {
4604
4604
SourceLocation DesignatedInitExpr::getBeginLoc () const {
4605
4605
auto *DIE = const_cast <DesignatedInitExpr *>(this );
4606
4606
Designator &First = *DIE->getDesignator (0 );
4607
- if (First.isFieldDesignator ())
4608
- return GNUSyntax ? First.getFieldLoc () : First.getDotLoc ();
4607
+ if (First.isFieldDesignator ()) {
4608
+ // Skip past implicit designators for anonymous structs/unions, since
4609
+ // these do not have valid source locations.
4610
+ for (unsigned int i = 0 ; i < DIE->size (); i++) {
4611
+ Designator &Des = *DIE->getDesignator (i);
4612
+ SourceLocation retval = GNUSyntax ? Des.getFieldLoc () : Des.getDotLoc ();
4613
+ if (!retval.isValid ())
4614
+ continue ;
4615
+ return retval;
4616
+ }
4617
+ }
4609
4618
return First.getLBracketLoc ();
4610
4619
}
4611
4620
You can’t perform that action at this time.
0 commit comments