Introduce a limit on the depth of the macro instantiation backtrace
printed in a diagnostic, similar to the limit we already have on the
depth of the template instantiation backtrace. The macro instantiation
backtrace is limited to 10 "instantiated from:" diagnostics; when it's
longer than that, we'll show the first half, then say how many were
suppressed, then show the second half. The limit can be changed with
-fmacro-instantiation-limit=N, and turned off with N=0.

This eliminates a lot of note spew with libraries making use of the
Boost.Preprocess library.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103014 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Misc/macro-backtrace-limit.c b/test/Misc/macro-backtrace-limit.c
new file mode 100644
index 0000000..bc7a4da
--- /dev/null
+++ b/test/Misc/macro-backtrace-limit.c
@@ -0,0 +1,32 @@
+// RUN: %clang-cc1 -fsyntax-only -fmacro-backtrace-limit 5 %s > %t 2>&1 
+// RUN: FileCheck %s < %t
+
+#define M1(A, B) ((A) < (B))
+#define M2(A, B) M1(A, B)
+#define M3(A, B) M2(A, B)
+#define M4(A, B) M3(A, B)
+#define M5(A, B) M4(A, B)
+#define M6(A, B) M5(A, B)
+#define M7(A, B) M6(A, B)
+#define M8(A, B) M7(A, B)
+#define M9(A, B) M8(A, B)
+#define M10(A, B) M9(A, B)
+#define M11(A, B) M10(A, B)
+#define M12(A, B) M11(A, B)
+
+void f(int *ip, float *fp) {
+  // CHECK: macro-backtrace-limit.c:31:7: warning: comparison of distinct pointer types ('int *' and 'float *')
+  // CHECK: if (M12(ip, fp)) { }
+  // CHECK: macro-backtrace-limit.c:15:19: note: instantiated from:
+  // CHECK: #define M12(A, B) M11(A, B)
+  // CHECK: macro-backtrace-limit.c:14:19: note: instantiated from:
+  // CHECK: #define M11(A, B) M10(A, B)
+  // CHECK: note: (skipping 7 contexts in backtrace; use -fmacro-backtrace-limit=0 to see all)
+  // CHECK: macro-backtrace-limit.c:6:18: note: instantiated from:
+  // CHECK: #define M3(A, B) M2(A, B)
+  // CHECK: macro-backtrace-limit.c:5:18: note: instantiated from:
+  // CHECK: #define M2(A, B) M1(A, B)
+  // CHECK: macro-backtrace-limit.c:4:23: note: instantiated from:
+  // CHECK: #define M1(A, B) ((A) < (B))
+  if (M12(ip, fp)) { }
+}