1// Tests for macro expansion backtraces. The RUN and CHECK lines are grouped
2// below the test code to reduce noise when updating them.
3
4#define M1(A, B) ((A) < (B))
5#define M2(A, B) M1(A, B)
6#define M3(A, B) M2(A, B)
7#define M4(A, B) M3(A, B)
8#define M5(A, B) M4(A, B)
9#define M6(A, B) M5(A, B)
10#define M7(A, B) M6(A, B)
11#define M8(A, B) M7(A, B)
12#define M9(A, B) M8(A, B)
13#define M10(A, B) M9(A, B)
14#define M11(A, B) M10(A, B)
15#define M12(A, B) M11(A, B)
16
17void f(int *ip, float *fp) {
18  if (M12(ip, fp)) { }
19  // RUN: %clang_cc1 -fsyntax-only -fmacro-backtrace-limit 5 %s 2>&1 \
20  // RUN:   | FileCheck %s -check-prefix=CHECK-LIMIT
21  // CHECK-LIMIT: macro-backtrace.c:18:7: warning: comparison of distinct pointer types ('int *' and 'float *')
22  // CHECK-LIMIT: if (M12(ip, fp)) { }
23  // CHECK-LIMIT: macro-backtrace.c:15:19: note: expanded from macro 'M12'
24  // CHECK-LIMIT: #define M12(A, B) M11(A, B)
25  // CHECK-LIMIT: macro-backtrace.c:14:19: note: expanded from macro 'M11'
26  // CHECK-LIMIT: #define M11(A, B) M10(A, B)
27  // CHECK-LIMIT: note: (skipping 7 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
28  // CHECK-LIMIT: macro-backtrace.c:6:18: note: expanded from macro 'M3'
29  // CHECK-LIMIT: #define M3(A, B) M2(A, B)
30  // CHECK-LIMIT: macro-backtrace.c:5:18: note: expanded from macro 'M2'
31  // CHECK-LIMIT: #define M2(A, B) M1(A, B)
32  // CHECK-LIMIT: macro-backtrace.c:4:23: note: expanded from macro 'M1'
33  // CHECK-LIMIT: #define M1(A, B) ((A) < (B))
34
35  // RUN: %clang_cc1 -fsyntax-only -fno-caret-diagnostics %s 2>&1 \
36  // RUN:   | FileCheck %s -check-prefix=CHECK-NO-CARETS
37  // CHECK-NO-CARETS: macro-backtrace.c:18:7: warning: comparison of distinct pointer types ('int *' and 'float *')
38  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:15:19: note: expanded from macro 'M12'
39  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:14:19: note: expanded from macro 'M11'
40  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:13:19: note: expanded from macro 'M10'
41  // CHECK-NO-CARETS-NEXT: note: (skipping 6 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
42  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:6:18: note: expanded from macro 'M3'
43  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:5:18: note: expanded from macro 'M2'
44  // CHECK-NO-CARETS-NEXT: macro-backtrace.c:4:23: note: expanded from macro 'M1'
45
46  // Check that the expansion notes respect the same formatting options as
47  // other diagnostics.
48  // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-format vi %s 2>&1 \
49  // RUN:   | FileCheck %s -check-prefix=CHECK-NOTE-FORMAT
50  // CHECK-NOTE-FORMAT: macro-backtrace.c +18:7: warning:
51  // CHECK-NOTE-FORMAT: macro-backtrace.c +15:19: note:
52  // CHECK-NOTE-FORMAT: macro-backtrace.c +14:19: note:
53  // CHECK-NOTE-FORMAT: note:
54  // CHECK-NOTE-FORMAT: macro-backtrace.c +6:18: note:
55  // CHECK-NOTE-FORMAT: macro-backtrace.c +5:18: note:
56  // CHECK-NOTE-FORMAT: macro-backtrace.c +4:23: note:
57}
58