blob: 7aeaf21a13d53048542f3f7d4e79182300113069 [file] [log] [blame]
Chandler Carruth1aaddf22011-10-16 07:20:21 +00001// Tests for macro expansion backtraces. The RUN and CHECK lines are grouped
2// below the test code to reduce noise when updating them.
Douglas Gregor6c1cb992010-05-04 17:13:42 +00003
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) {
Chandler Carruth1aaddf22011-10-16 07:20:21 +000018 if (M12(ip, fp)) { }
Chandler Carruthe0376c02011-10-16 07:20:23 +000019 // 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)) { }
Chandler Carruth9875c602011-10-24 18:51:08 +000023 // CHECK-LIMIT: macro-backtrace.c:15:19: note: expanded from macro 'M12'
Chandler Carruthe0376c02011-10-16 07:20:23 +000024 // CHECK-LIMIT: #define M12(A, B) M11(A, B)
Chandler Carruth9875c602011-10-24 18:51:08 +000025 // CHECK-LIMIT: macro-backtrace.c:14:19: note: expanded from macro 'M11'
Chandler Carruthe0376c02011-10-16 07:20:23 +000026 // 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)
Chandler Carruth9875c602011-10-24 18:51:08 +000028 // CHECK-LIMIT: macro-backtrace.c:6:18: note: expanded from macro 'M3'
Chandler Carruthe0376c02011-10-16 07:20:23 +000029 // CHECK-LIMIT: #define M3(A, B) M2(A, B)
Chandler Carruth9875c602011-10-24 18:51:08 +000030 // CHECK-LIMIT: macro-backtrace.c:5:18: note: expanded from macro 'M2'
Chandler Carruthe0376c02011-10-16 07:20:23 +000031 // CHECK-LIMIT: #define M2(A, B) M1(A, B)
Chandler Carruth9875c602011-10-24 18:51:08 +000032 // CHECK-LIMIT: macro-backtrace.c:4:23: note: expanded from macro 'M1'
Chandler Carruthe0376c02011-10-16 07:20:23 +000033 // CHECK-LIMIT: #define M1(A, B) ((A) < (B))
Chandler Carruth4ba55652011-10-16 07:20:28 +000034
Chandler Carruth4ba55652011-10-16 07:20:28 +000035 // 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 *')
Chandler Carruth9875c602011-10-24 18:51:08 +000038 // 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'
Chandler Carruth4ba55652011-10-16 07:20:28 +000041 // CHECK-NO-CARETS-NEXT: note: (skipping 6 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
Chandler Carruth9875c602011-10-24 18:51:08 +000042 // 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'
Chandler Carruth4c3fd512011-10-16 21:33:06 +000045
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:
Douglas Gregor6c1cb992010-05-04 17:13:42 +000057}