[cfe-commits] r170397 - in /cfe/trunk: lib/Frontend/DiagnosticRenderer.cpp test/Misc/caret-diags-macros.c
Eli Friedman
eli.friedman at gmail.com
Mon Dec 17 16:52:36 PST 2012
Author: efriedma
Date: Mon Dec 17 18:52:36 2012
New Revision: 170397
URL: http://llvm.org/viewvc/llvm-project?rev=170397&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/test/Misc/caret-diags-macros.c
Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=170397&r1=170396&r2=170397&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original)
+++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Mon Dec 17 18:52:36 2012
@@ -363,6 +363,13 @@
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.
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=170397&r1=170396&r2=170397&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Mon Dec 17 18:52:36 2012
@@ -205,3 +205,23 @@
// 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: {{^ \^}}
More information about the cfe-commits
mailing list