[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
// RUN: rm -rf %t && mkdir %t
|
|
|
|
// RUN: mkdir -p %t/ctudir
|
2019-07-25 20:46:42 +08:00
|
|
|
// RUN: %clang_cc1 -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
// RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt
|
2021-02-22 18:12:22 +08:00
|
|
|
//
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
|
|
|
|
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
|
|
|
|
// RUN: -analyzer-config ctu-dir=%t/ctudir \
|
|
|
|
// RUN: -analyzer-config expand-macros=true \
|
|
|
|
// RUN: -analyzer-output=plist-multi-file -o %t.plist -verify %s
|
2021-02-22 18:12:22 +08:00
|
|
|
//
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
// Check the macro expansions from the plist output here, to make the test more
|
|
|
|
// understandable.
|
|
|
|
// RUN: FileCheck --input-file=%t.plist %s
|
|
|
|
|
|
|
|
extern void F1(int **);
|
|
|
|
extern void F2(int **);
|
|
|
|
extern void F3(int **);
|
|
|
|
extern void F_H(int **);
|
|
|
|
|
|
|
|
void test0() {
|
|
|
|
int *X;
|
|
|
|
F3(&X);
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
2021-02-22 18:12:22 +08:00
|
|
|
// FIXME: Macro expansion for other TUs should also work.
|
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: </array>
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
|
|
|
|
void test1() {
|
|
|
|
int *X;
|
|
|
|
F1(&X);
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
2021-02-22 18:12:22 +08:00
|
|
|
|
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: </array>
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
|
|
|
|
void test2() {
|
|
|
|
int *X;
|
|
|
|
F2(&X);
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
2021-02-22 18:12:22 +08:00
|
|
|
|
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: </array>
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
|
|
|
|
#define M F1(&X)
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
int *X;
|
|
|
|
M;
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
2021-02-22 18:12:22 +08:00
|
|
|
// Macro expansions for the main TU still works, even in CTU mode.
|
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: <dict>
|
|
|
|
// CHECK-NEXT: <key>location</key>
|
|
|
|
// CHECK-NEXT: <dict>
|
|
|
|
// CHECK-NEXT: <key>line</key><integer>55</integer>
|
|
|
|
// CHECK-NEXT: <key>col</key><integer>3</integer>
|
|
|
|
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
|
|
|
// CHECK-NEXT: </dict>
|
|
|
|
// CHECK-NEXT: <key>name</key><string>M</string>
|
|
|
|
// CHECK-NEXT: <key>expansion</key><string>F1 (&X )</string>
|
|
|
|
// CHECK-NEXT: </dict>
|
|
|
|
// CHECK-NEXT: </array>
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
|
|
|
|
#undef M
|
|
|
|
#define M F2(&X)
|
|
|
|
|
|
|
|
void test4() {
|
|
|
|
int *X;
|
|
|
|
M;
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:12:22 +08:00
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: <dict>
|
|
|
|
// CHECK-NEXT: <key>location</key>
|
|
|
|
// CHECK-NEXT: <dict>
|
|
|
|
// CHECK-NEXT: <key>line</key><integer>78</integer>
|
|
|
|
// CHECK-NEXT: <key>col</key><integer>3</integer>
|
|
|
|
// CHECK-NEXT: <key>file</key><integer>0</integer>
|
|
|
|
// CHECK-NEXT: </dict>
|
|
|
|
// CHECK-NEXT: <key>name</key><string>M</string>
|
|
|
|
// CHECK-NEXT: <key>expansion</key><string>F2 (&X )</string>
|
|
|
|
// CHECK-NEXT: </dict>
|
|
|
|
// CHECK-NEXT: </array>
|
[CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.
Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov
Reviewed By: Szelethus
Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64638
llvm-svn: 367006
2019-07-25 18:53:22 +08:00
|
|
|
|
|
|
|
void test_h() {
|
|
|
|
int *X;
|
|
|
|
F_H(&X);
|
|
|
|
*X = 1; // expected-warning{{Dereference of null pointer}}
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:12:22 +08:00
|
|
|
// CHECK: <key>macro_expansions</key>
|
|
|
|
// CHECK-NEXT: <array>
|
|
|
|
// CHECK-NEXT: </array>
|