Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated the summary for this revision. zhengkai updated this revision to Diff 34588. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added a comment. In http://reviews.llvm.org/D12379#245849, @rtrieu wrote: > Why are you leaking the raw encoding of locations from the SourceManager? > This is an internal implementation detail and should not be relied on > externally. SourceLocation is the typical way to use locations. Because I want to check if all the ranges fit in the same argument of one macro invocation, they can be different Source Locations. In ExpansionInfo, these locations have the same ExpansionLocStart. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added a comment. In http://reviews.llvm.org/D12379#245861, @rtrieu wrote: > In http://reviews.llvm.org/D12379#245850, @zhengkai wrote: > > > In http://reviews.llvm.org/D12379#245849, @rtrieu wrote: > > > > > Why are you leaking the raw encoding of locations from the SourceManager? > > > This is an internal implementation detail and should not be relied on > > > externally. SourceLocation is the typical way to use locations. > > > > > > Because I want to check if all the ranges fit in the same argument of one > > macro invocation, they can be different Source Locations. In ExpansionInfo, > > these locations have the same ExpansionLocStart. > > > If you call ExpansionInfo::getExpansionLocStart(), then the SourceLocation > will be the same if the ExpansionLocStart is the same. But I still need to change the isMacroArg function to get the result of getExpansionLocStart(), and if I want to compare two SourceLocation, I still need to check the raw encoding. I don't know if it is needed not to leak the raw encoding. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 34826. zhengkai added a comment. Use the rtrieu's method to re write the implementation of SourceManager. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHE
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added a comment. In http://reviews.llvm.org/D12379#245892, @rtrieu wrote: > In http://reviews.llvm.org/D12379#245868, @zhengkai wrote: > > > In http://reviews.llvm.org/D12379#245861, @rtrieu wrote: > > > > > In http://reviews.llvm.org/D12379#245850, @zhengkai wrote: > > > > > > > In http://reviews.llvm.org/D12379#245849, @rtrieu wrote: > > > > > > > > > Why are you leaking the raw encoding of locations from the > > > > > SourceManager? This is an internal implementation detail and should > > > > > not be relied on externally. SourceLocation is the typical way to > > > > > use locations. > > > > > > > > > > > > Because I want to check if all the ranges fit in the same argument of > > > > one macro invocation, they can be different Source Locations. In > > > > ExpansionInfo, these locations have the same ExpansionLocStart. > > > > > > > > > If you call ExpansionInfo::getExpansionLocStart(), then the > > > SourceLocation will be the same if the ExpansionLocStart is the same. > > > > > > But I still need to change the isMacroArg function to get the result of > > getExpansionLocStart(), and if I want to compare two SourceLocation, I > > still need to check the raw encoding. I don't know if it is needed not to > > leak the raw encoding. > > > I kind of see what you are trying to do here, and we should fix it a > different way. > > 1. Get rid of changes to ExpansionInfo > 2. Change the function SourceManager::isMacroArgExpansion to take two > arguments instead of one. The new argument should be a SourceLocation > pointer named MacroBegin. > 3. Change the last line of SourceManager::isMacroArgExpansion from "return > Expansion.isMacroArgExpansion();" to "if (!Expansion.isMacroArgExpansion()) > return false;" After that, add the code to get the macro begin location. > 4. Update DiagnosticRenderer to use SourceLocation instead of raw encodings. Have changed the implementation. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 34943. zhengkai marked 8 inline comments as done. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // C
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added inline comments. Comment at: lib/Frontend/DiagnosticRenderer.cpp:312 @@ +311,3 @@ + +static bool retrieveBeginLocation(SourceLocation &Begin, + FileID &BeginFileID, rtrieu wrote: > Why not return a SourceLocation instead of passing one in by reference? Because this function has two recursive calls inside. So if return a SourceLocation here, I will need to use a temporal variable to store the result of the first call. And this doesn't make it easier. Comment at: lib/Frontend/DiagnosticRenderer.cpp:323 @@ +322,3 @@ + else +Backup = SM->getImmediateSpellingLoc(Backup); + BeginFileID = SM->getFileID(Begin); rtrieu wrote: > In the other function, there is "End = > SM->getImmediateExpansionRange(Backup).second;" Why is there not a "Begin = > SM->getImmediateExpansionRange(Backup).first;" here? Begin = SM->getImmediateMacroCallerLoc(Begin); Use getImmediateMacroCallerLoc function here. Comment at: lib/Frontend/DiagnosticRenderer.cpp:331 @@ +330,3 @@ + +static bool retrieveEndLocation(SourceLocation &End, +FileID &EndFileID, rtrieu wrote: > There is a lot of duplicated code between these two functions. Can they > merged together with an option to select whether to check the start or end > locations? I tried it but the code doesn't seem easier. Comment at: lib/Frontend/DiagnosticRenderer.cpp:352-367 @@ -309,1 +351,18 @@ + +/// Helper function to print out all the backtrace locations +/// for a source location. + +static void retrieveAllBacktraces(SourceLocation Loc, + const SourceManager *SM) { + llvm::errs() << "New level\n"; + llvm::errs() << Loc.printToString(*SM) << " " << + SM->getFileID(Loc).getHashValue() << "\n"; + if (!Loc.isMacroID()) return; + if (SM->isMacroArgExpansion(Loc)) llvm::errs() << "is Macro Arg Expansion\n"; + llvm::errs() << "Down Spelling Loc\n"; + retrieveAllBacktraces(SM->getImmediateSpellingLoc(Loc),SM); + llvm::errs() << "Down Expansion Range\n"; + retrieveAllBacktraces(SM->getImmediateExpansionRange(Loc).first,SM); +} + // Helper function to fix up source ranges. It takes in an array of ranges, rtrieu wrote: > Function not used; remove it. deleted. But I wonder this function is important for those who want to debug this code. Comment at: lib/Frontend/DiagnosticRenderer.cpp:417-418 @@ -374,1 +416,4 @@ +// Do the backtracking. +if (!retrieveBeginLocation(Begin,BeginFileID,CaretLocFileID,SM)) continue; +if (!retrieveEndLocation(End,EndFileID,CaretLocFileID,SM)) continue; rtrieu wrote: > Can these function be rewritten to return SourceLocation's? Then it would be: > Begin = retrieveBeginLocation(Begin, BeginFileID, CaretLocFileID, SM); > End = retrieveEndLocation(End, EndFileID, CaretLocFileID, SM); > > if (Begin.invalid() || End.invalid()) continue; > Replied before. Comment at: lib/Frontend/DiagnosticRenderer.cpp:466 @@ -419,1 +465,3 @@ +static bool checkLocForMacroArgExpansion(SourceLocation Loc, + const SourceManager &SM, rtrieu wrote: > What is this function doing that is not captured by the old > isMacroArgExpansion function? I don't understand what you mean here. Comment at: lib/Frontend/DiagnosticRenderer.cpp:504 @@ -441,2 +503,3 @@ - if (!SM.isMacroArgExpansion(Loc)) + /// Count all valid ranges. + unsigned ValidCount = 0; rtrieu wrote: > Why does the range count matter? Because some ranges passed in are invalid. And if the mapDiagnosticRanges function drops some ranges, this means this macro call doesn't contain all the information needed of all the ranges. Comment at: test/Misc/caret-diags-macros.c:210 @@ -215,3 +209,3 @@ void f(char* pMsgBuf, char* pKeepBuf) { -Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", Cstrlen(pKeepBuf)); +Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", strlen_test(pKeepBuf)); } rtrieu wrote: > Why is Cstrlen changed to strlen_test? The preprocessor can't get right when the argument itself is a function-like macro. This bug is not due to the high-level macro case but due to this problem. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai marked 2 inline comments as done. Comment at: lib/Frontend/DiagnosticRenderer.cpp:455 @@ -419,1 +454,3 @@ +static bool checkLocForMacroArgExpansion(SourceLocation Loc, + const SourceManager &SM, Because the function isMacroArgExpansion doesn't check if all locations are in the same argument location, http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added inline comments. Comment at: lib/Frontend/DiagnosticRenderer.cpp:323 @@ +322,3 @@ + else +Backup = SM->getImmediateSpellingLoc(Backup); + rtrieu wrote: > You did not add that here. The getImmediateMacroCallerLoc is implemented as following: SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const { if (!Loc.isMacroID()) return Loc; if (isMacroArgExpansion(Loc)) return getImmediateSpellingLoc(Loc); return getImmediateExpansionRange(Loc).first; } Comment at: lib/Frontend/DiagnosticRenderer.cpp:471 @@ -422,1 +470,3 @@ + const SourceManager &SM, + SourceLocation &Loc) { SourceLocation BegLoc = Range.getBegin(), EndLoc = Range.getEnd(); rtrieu wrote: > What is this SourceLocation? Why is it passed by reference? Changed http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35554. zhengkai marked 11 inline comments as done. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused //
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35556. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macr
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai marked an inline comment as done. Comment at: lib/Frontend/DiagnosticRenderer.cpp:442 @@ -419,1 +441,3 @@ +static bool checkLocForMacroArgExpansion(SourceLocation Loc, + const SourceManager &SM, I have stated that I need to check if all the locations checked fit in the same location in the expansionInfo. So I need the preLoc to store the previous checked location to see if they are the same. Comment at: lib/Frontend/DiagnosticRenderer.cpp:454 @@ -422,1 +453,3 @@ + const SourceManager &SM, + SourceLocation Loc) { SourceLocation BegLoc = Range.getBegin(), EndLoc = Range.getEnd(); See the comment ahead. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35561. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macr
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai added inline comments. Comment at: lib/Frontend/DiagnosticRenderer.cpp:442 @@ -419,1 +441,3 @@ +/// Check if the current location fit in the macro argument expansion +/// Especially, it should fit in the same argument with all the other locations Explained in the new comments in the updated diff. http://reviews.llvm.org/D12379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35573. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macr
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35574. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macr
Re: [PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai updated this revision to Diff 35575. http://reviews.llvm.org/D12379 Files: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/diag-macro-backtrace2.c test/Misc/reduced-diags-macros.cpp test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/reduced-diags-macros.cpp === --- test/Misc/reduced-diags-macros.cpp +++ test/Misc/reduced-diags-macros.cpp @@ -11,7 +11,7 @@ // CHECK-NEXT: ~~^~ // CHECK-NEXT: {{.*}}:3:34: note: expanded from macro 'NO_INITIATION' // CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 -// CHECK-NEXT: ^ +// CHECK-NEXT: ~ ^ // CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' // CHECK-NEXT: NO_DEFINITION(b); @@ -27,3 +27,18 @@ // CHECK: {{.*}}:25:23: error: use of undeclared identifier 'x' // CHECK-NEXT: int p = SWAP_ARGU(3, x); // CHECK-NEXT: ^ + +#define APPLY(f,x,y) x f y + +struct node { +}; + +node ff; + +int r = APPLY(+,ff,1); +// CHECK: {{.*}}:38:15: error: invalid operands to binary expression ('node' and 'int') +// CHECK-NEXT: int r = APPLY(+,ff,1); +// CHECK-NEXT: ^ ~~ ~ +// CHECK-NEXT: {{.*}}:31:24: note: expanded from macro 'APPLY' +// CHECK-NEXT: #define APPLY(f,x,y) x f y +// CHECK-NEXT: ~ ^ ~ \ No newline at end of file Index: test/Misc/diag-macro-backtrace2.c === --- test/Misc/diag-macro-backtrace2.c +++ test/Misc/diag-macro-backtrace2.c @@ -16,7 +16,7 @@ // CHECK: :15:3: error: invalid operands to binary expression // CHECK: ('const char *' and 'int') // CHECK: a(str); - // CHECK: ^ ~~~ + // CHECK: ^~ // CHECK: :3:11: note: expanded from macro 'a' // CHECK: #define a b // CHECK: ^ @@ -28,7 +28,7 @@ // CHECK: ^~~~ // CHECK: :6:15: note: expanded from macro 'd' // CHECK: #define d(x) x*1 - // CHECK: ^~ + // CHECK: ~^~ e(str); // CHECK: :33:5: warning: expression result unused Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,62 +38,59 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macr
Re: [PATCH] D11778: Improvements on Diagnostic in Macro Expansions
zhengkai added a comment. The helper function checkRangesForMacroArgExpansion is to check if the current Loc and Ranges are expansions of a macro's arguments. If so, the IgnoredEnd will record this position and thus omitting all later expanded macros (Later expanded macros are showed on top of the stack though). Two test cases are added. The reduced-diags-macros-backtrace.cpp is to show that my method works correctly with the option -fmacro-backtrace-limit The reduced-diags-macros.cpp is to show that my method reduced verbose information printed indeed. There are still a lot of other cases in which my method still works as the old version did. And I think there are several bugs in the existing functions like "emitDiagnostic" and "mapDiagnosticRanges". This is issued as a bug, the link is https://llvm.org/bugs/show_bug.cgi?id=24423. Future work will be done to improve the current result. Comment at: test/Misc/reduced-diags-macros.cpp:14-15 @@ +13,4 @@ +// CHECK-NEXT: #define NO_INITIATION(x) int a = x * 2 +// CHECK-NEXT: ^ + +// CHECK: {{.*}}:7:15: error: use of undeclared identifier 'b' Yes. This works like the old version, should be improved later http://reviews.llvm.org/D11778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D11778: Improvements on Diagnostic in Macro Expansions
zhengkai added a comment. The example our method doesn't work: https://llvm.org/bugs/show_bug.cgi?id=24424 http://reviews.llvm.org/D11778 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D12379: Fix the bugs in the mapDiagnosticRanges (Still in progress)
zhengkai created this revision. zhengkai added a reviewer: rtrieu. zhengkai added a subscriber: cfe-commits. Use a new algorithm to find map back the ranges to its spelling locations. But the function is not working properly either, and it breaks a test. In the last case in the test file /llvm/tools/clang/test/Misc/caret-diags-macros.c, it underlined the wrong range. This is reported as a bug in https://llvm.org/bugs/show_bug.cgi?id=24592. The methods which are used to map back the source locations in the macro expansions are questionable in the SourceManager Class. http://reviews.llvm.org/D12379 Files: lib/Frontend/DiagnosticRenderer.cpp test/Index/fix-its.m test/Misc/caret-diags-macros.c test/Misc/serialized-diags.c Index: test/Misc/serialized-diags.c === --- test/Misc/serialized-diags.c +++ test/Misc/serialized-diags.c @@ -55,7 +55,6 @@ // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] -// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 // CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] Index: test/Misc/caret-diags-macros.c === --- test/Misc/caret-diags-macros.c +++ test/Misc/caret-diags-macros.c @@ -16,9 +16,6 @@ void bar() { C(1); // CHECK: {{.*}}:17:5: warning: expression result unused - // CHECK: {{.*}}:15:16: note: expanded from macro 'C' - // CHECK: {{.*}}:14:16: note: expanded from macro 'B' - // CHECK: {{.*}}:13:14: note: expanded from macro 'A' } // rdar://7597492 @@ -41,48 +38,45 @@ void test() { macro_args3(11); - // CHECK: {{.*}}:43:15: warning: expression result unused + // CHECK: {{.*}}:40:15: warning: expression result unused // Also check that the 'caret' printing agrees with the location here where // its easy to FileCheck. // CHECK-NEXT: macro_args3(11); // CHECK-NEXT: {{^ \^~}} - // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' macro_many_args3( 1, 2, 3); - // CHECK: {{.*}}:55:5: warning: expression result unused - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:49:5: warning: expression result unused + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, M2, 3); - // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:58:5: warning: expression result unused // CHECK: {{.*}}:4:12: note: expanded from macro 'M2' - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' macro_many_args3( 1, macro_args2(22), 3); - // CHECK: {{.*}}:74:17: warning: expression result unused + // CHECK: {{.*}}:68:17: warning: expression result unused // This caret location needs to be printed *inside* a different macro's // arguments. // CHECK-NEXT:macro_args2(22), // CHECK-NEXT: {{^\^~}} - // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' - // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' - // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' - // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' - // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + // CHECK: {{.*}}:32:36: note: expanded from macro 'macro_args2' + // CHECK: {{.*}}:31:24: note: expanded from macro 'macro_args1' + // CHECK: {{.*}}:37:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:36:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:35:35: note: expanded from macro 'macro_many_args1' } #d