diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-12-18 00:52:36 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-12-18 00:52:36 +0000 |
commit | adff43ad96defb28bad20d8335ab30beadd72ee8 (patch) | |
tree | 300aeb97813ad657661713a1bee9562cdcac3580 | |
parent | a6f8a6ed1ab163b3c4c863aa4a198fd1cb62fd97 (diff) |
More conservative fix for <rdar://problem/12847524> (a crash printing diagnostic ranges).
I'm not really happy with this fix, but I'm confident it's correct.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170397 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Frontend/DiagnosticRenderer.cpp | 7 | ||||
-rw-r--r-- | test/Misc/caret-diags-macros.c | 20 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/Frontend/DiagnosticRenderer.cpp b/lib/Frontend/DiagnosticRenderer.cpp index 89d3867aad..88a8706731 100644 --- a/lib/Frontend/DiagnosticRenderer.cpp +++ b/lib/Frontend/DiagnosticRenderer.cpp @@ -363,6 +363,13 @@ static void mapDiagnosticRanges( End = SM->getImmediateExpansionRange(End).second; } BeginFileID = SM->getFileID(Begin); + if (BeginFileID != SM->getFileID(End)) { + // FIXME: Ugly hack to stop a crash; this code is making bad + // assumptions and it's too complicated for me to reason + // about. + Begin = End = SourceLocation(); + break; + } } // Return the spelling location of the beginning and end of the range. diff --git a/test/Misc/caret-diags-macros.c b/test/Misc/caret-diags-macros.c index ce62425e78..95fc64cf3c 100644 --- a/test/Misc/caret-diags-macros.c +++ b/test/Misc/caret-diags-macros.c @@ -205,3 +205,23 @@ void foo_aa() // CHECK-NEXT: {{.*}}:189:31: note: expanded from macro 'APPEND2' // CHECK-NEXT: #define APPEND2(NUM, SUFF) -1 != NUM ## SUFF // CHECK-NEXT: {{^ ~~ \^ ~~~~~~~~~~~}} + +unsigned long strlen_test(const char *s); +#define __darwin_obsz(object) __builtin_object_size (object, 1) +#define sprintf2(str, ...) \ + __builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__) +#define Cstrlen(a) strlen_test(a) +#define Csprintf sprintf2 +void f(char* pMsgBuf, char* pKeepBuf) { +Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", Cstrlen(pKeepBuf)); +} +// CHECK: {{.*}}:216:62: warning: format specifies type 'int' but the argument has type 'unsigned long' +// CHECK-NEXT: Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", Cstrlen(pKeepBuf)); +// CHECK-NEXT: {{^ ~~~ \^}} +// CHECK-NEXT: {{^ %1ld}} +// CHECK-NEXT: {{.*}}:213:21: note: expanded from macro 'Cstrlen' +// CHECK-NEXT: #define Cstrlen(a) strlen_test(a) +// CHECK-NEXT: {{^ \^}} +// CHECK-NEXT: {{.*}}:212:56: note: expanded from macro 'sprintf2' +// CHECK-NEXT: __builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__) +// CHECK-NEXT: {{^ \^}} |