[cfe-commits] r169068 - in /cfe/trunk: lib/Lex/TokenLexer.cpp test/Misc/caret-diags-macros.c

Eli Friedman eli.friedman at gmail.com
Fri Nov 30 17:15:54 PST 2012


Author: efriedma
Date: Fri Nov 30 19:15:54 2012
New Revision: 169068

URL: http://llvm.org/viewvc/llvm-project?rev=169068&view=rev
Log:
Try to make the source location information for token pastes a bit more consistent.

Fixes a crash printing diagnostics on the gcc testsuite, and also makes
diagnostic range printing print nicer results for token pastes.


Modified:
    cfe/trunk/lib/Lex/TokenLexer.cpp
    cfe/trunk/test/Misc/caret-diags-macros.c

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=169068&r1=169067&r2=169068&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Fri Nov 30 19:15:54 2012
@@ -647,6 +647,12 @@
     StartLoc = getExpansionLocForMacroDefLoc(StartLoc);
   if (EndLoc.isFileID())
     EndLoc = getExpansionLocForMacroDefLoc(EndLoc);
+  FileID MacroFID = SM.getFileID(MacroExpansionStart);
+  while (SM.getFileID(StartLoc) != MacroFID)
+    StartLoc = SM.getImmediateExpansionRange(StartLoc).first;
+  while (SM.getFileID(EndLoc) != MacroFID)
+    EndLoc = SM.getImmediateExpansionRange(EndLoc).second;
+    
   Tok.setLocation(SM.createExpansionLoc(Tok.getLocation(), StartLoc, EndLoc,
                                         Tok.getLength()));
 

Modified: cfe/trunk/test/Misc/caret-diags-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags-macros.c?rev=169068&r1=169067&r2=169068&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Fri Nov 30 19:15:54 2012
@@ -113,21 +113,29 @@
   // CHECK: {{.*}}:102:41: note: expanded from macro 'variadic_pasting_args1'
 
   variadic_pasting_args3a(1, 2, 3, 4);
-  // CHECK: {{.*}}:115:30: warning: expression result unused
-  // CHECK: {{.*}}:106:71: note: expanded from macro 'variadic_pasting_args3a'
-  // CHECK: {{.*}}:104:70: note: expanded from macro 'variadic_pasting_args2a'
-  // CHECK: {{.*}}:102:41: note: expanded from macro 'variadic_pasting_args1'
+  // CHECK:        {{.*}}:115:3: warning: expression result unused
+  // CHECK-NEXT:     variadic_pasting_args3a(1, 2, 3, 4);
+  // CHECK-NEXT: {{  \^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}}
+  // CHECK:        {{.*}}:106:44: note: expanded from macro 'variadic_pasting_args3a'
+  // CHECK-NEXT:   #define variadic_pasting_args3a(x, y, ...) variadic_pasting_args2a(x, y, __VA_ARGS__)
+  // CHECK-NEXT: {{                                           \^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}}
+  // CHECK:        {{.*}}:104:70: note: expanded from macro 'variadic_pasting_args2a'
+  // CHECK-NEXT:   #define variadic_pasting_args2a(x, y, ...) variadic_pasting_args1(x, y ## __VA_ARGS__)
+  // CHECK-NEXT: {{                                                                     \^~~~~~~~~~~~~~~~}}
+  // CHECK:        {{.*}}:102:41: note: expanded from macro 'variadic_pasting_args1'
+  // CHECK-NEXT:   #define variadic_pasting_args1(x, y, z) y
+  // CHECK-NEXT: {{                                        \^}}
 }
 
 #define BAD_CONDITIONAL_OPERATOR (2<3)?2:3
 int test4 = BAD_CONDITIONAL_OPERATOR+BAD_CONDITIONAL_OPERATOR;
-// CHECK:         {{.*}}:122:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
+// CHECK:         {{.*}}:130:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
 // CHECK-NEXT:    #define BAD_CONDITIONAL_OPERATOR (2<3)?2:3
 // CHECK-NEXT: {{^                                      \^}}
-// CHECK:         {{.*}}:122:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
+// CHECK:         {{.*}}:130:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
 // CHECK-NEXT:    #define BAD_CONDITIONAL_OPERATOR (2<3)?2:3
 // CHECK-NEXT: {{^                                      \^}}
-// CHECK:         {{.*}}:122:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
+// CHECK:         {{.*}}:130:39: note: expanded from macro 'BAD_CONDITIONAL_OPERATOR'
 // CHECK-NEXT:    #define BAD_CONDITIONAL_OPERATOR (2<3)?2:3
 // CHECK-NEXT: {{^                                 ~~~~~\^~~~}}
 
@@ -135,32 +143,32 @@
 #define TWOL (2<
 #define X 1+TWOL 3) QMARK 4:5
 int x = X;
-// CHECK:         {{.*}}:137:9: note: place parentheses around the '+' expression to silence this warning
+// CHECK:         {{.*}}:145:9: note: place parentheses around the '+' expression to silence this warning
 // CHECK-NEXT:    int x = X;
 // CHECK-NEXT: {{^        \^}}
-// CHECK-NEXT:    {{.*}}:136:21: note: expanded from macro 'X'
+// CHECK-NEXT:    {{.*}}:144:21: note: expanded from macro 'X'
 // CHECK-NEXT:    #define X 1+TWOL 3) QMARK 4:5
 // CHECK-NEXT: {{^          ~~~~~~~~~ \^}}
-// CHECK-NEXT:    {{.*}}:134:15: note: expanded from macro 'QMARK'
+// CHECK-NEXT:    {{.*}}:142:15: note: expanded from macro 'QMARK'
 // CHECK-NEXT:    #define QMARK ?
 // CHECK-NEXT: {{^              \^}}
-// CHECK-NEXT:    {{.*}}:137:9: note: place parentheses around the '?:' expression to evaluate it first
+// CHECK-NEXT:    {{.*}}:145:9: note: place parentheses around the '?:' expression to evaluate it first
 // CHECK-NEXT:    int x = X;
 // CHECK-NEXT: {{^        \^}}
-// CHECK-NEXT:    {{.*}}:136:21: note: expanded from macro 'X'
+// CHECK-NEXT:    {{.*}}:144:21: note: expanded from macro 'X'
 // CHECK-NEXT:    #define X 1+TWOL 3) QMARK 4:5
 // CHECK-NEXT: {{^            ~~~~~~~~\^~~~~~~~~}}
 
 #define ONEPLUS 1+
 #define Y ONEPLUS (2<3) QMARK 4:5
 int y = Y;
-// CHECK:         {{.*}}:156:9: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first
+// CHECK:         {{.*}}:164:9: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first
 // CHECK-NEXT:    int y = Y;
 // CHECK-NEXT: {{^        \^}}
-// CHECK-NEXT:    {{.*}}:155:25: note: expanded from macro 'Y'
+// CHECK-NEXT:    {{.*}}:163:25: note: expanded from macro 'Y'
 // CHECK-NEXT:    #define Y ONEPLUS (2<3) QMARK 4:5
 // CHECK-NEXT: {{^          ~~~~~~~~~~~~~ \^}}
-// CHECK-NEXT:    {{.*}}:134:15: note: expanded from macro 'QMARK'
+// CHECK-NEXT:    {{.*}}:142:15: note: expanded from macro 'QMARK'
 // CHECK-NEXT:    #define QMARK ?
 // CHECK-NEXT: {{^              \^}}
 
@@ -171,9 +179,29 @@
 #define /* */ BARC(c, /* */b, a, ...) (a+b+/* */c + __VA_ARGS__ +0)
   iequals(__LINE__, BARC(4,3,2,6,8), 8);
 }
-// CHECK:         {{.*}}:172:21: warning: expression result unused
+// CHECK:         {{.*}}:180:21: warning: expression result unused
 // CHECK-NEXT:      iequals(__LINE__, BARC(4,3,2,6,8), 8);
 // CHECK-NEXT: {{^                    \^~~~~~~~~~~~~~~}}
-// CHECK-NEXT:    {{.*}}:171:51: note: expanded from macro 'BARC'
+// CHECK-NEXT:    {{.*}}:179:51: note: expanded from macro 'BARC'
 // CHECK-NEXT:    #define /* */ BARC(c, /* */b, a, ...) (a+b+/* */c + __VA_ARGS__ +0)
 // CHECK-NEXT: {{^                                       ~~~~~~~~~~ \^}}
+
+#define APPEND2(NUM, SUFF) -1 != NUM ## SUFF
+#define APPEND(NUM, SUFF) APPEND2(NUM, SUFF)
+#define UTARG_MAX_U APPEND (MAX_UINT, UL)
+#define MAX_UINT 18446744073709551615
+#if UTARG_MAX_U
+#endif
+
+// CHECK:         {{.*}}:193:5: warning: left side of operator converted from negative value to unsigned: -1 to 18446744073709551615
+// CHECK-NEXT:    #if UTARG_MAX_U
+// CHECK-NEXT: {{^    \^~~~~~~~~~~}}
+// CHECK-NEXT:    {{.*}}:191:21: note: expanded from macro 'UTARG_MAX_U'
+// CHECK-NEXT:    #define UTARG_MAX_U APPEND (MAX_UINT, UL)
+// CHECK-NEXT: {{^                    \^~~~~~~~~~~~~~~~~~~~~}}
+// CHECK-NEXT:    {{.*}}:190:27: note: expanded from macro 'APPEND'
+// CHECK-NEXT:    #define APPEND(NUM, SUFF) APPEND2(NUM, SUFF)
+// CHECK-NEXT: {{^                          \^~~~~~~~~~~~~~~~~~}}
+// CHECK-NEXT:    {{.*}}:189:31: note: expanded from macro 'APPEND2'
+// CHECK-NEXT:    #define APPEND2(NUM, SUFF) -1 != NUM ## SUFF
+// CHECK-NEXT: {{^                           ~~ \^  ~~~~~~~~~~~}}





More information about the cfe-commits mailing list