Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
6 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#include "plist-macros-ctu.h" | ||
|
||
#define M *X = (int *)0 | ||
|
||
void F1(int **X) { | ||
M; | ||
} | ||
|
||
#undef M | ||
#define M *Y = (int *)0 | ||
|
||
void F2(int **Y) { | ||
M; | ||
} | ||
|
||
#define M1 *Z = (int *)0 | ||
|
||
void F3(int **Z) { | ||
M1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#define M_H *A = (int *)0 | ||
void F_H(int **A) { | ||
M_H; | ||
} |
4 changes: 4 additions & 0 deletions
4
clang/test/Analysis/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
c:@F@F1 plist-macros-ctu.c.ast | ||
c:@F@F2 plist-macros-ctu.c.ast | ||
c:@F@F3 plist-macros-ctu.c.ast | ||
c:@F@F_H plist-macros-ctu.c.ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// RUN: rm -rf %t && mkdir %t | ||
// RUN: mkdir -p %t/ctudir | ||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \ | ||
// RUN: -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c | ||
// RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt | ||
|
||
// 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 | ||
|
||
// 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}} | ||
} | ||
// CHECK: <key>name</key><string>M1</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*Z = (int *)0</string> | ||
|
||
|
||
void test1() { | ||
int *X; | ||
F1(&X); | ||
*X = 1; // expected-warning{{Dereference of null pointer}} | ||
} | ||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*X = (int *)0</string> | ||
|
||
void test2() { | ||
int *X; | ||
F2(&X); | ||
*X = 1; // expected-warning{{Dereference of null pointer}} | ||
} | ||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*Y = (int *)0</string> | ||
|
||
#define M F1(&X) | ||
|
||
void test3() { | ||
int *X; | ||
M; | ||
*X = 1; // expected-warning{{Dereference of null pointer}} | ||
} | ||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>F1(&X)</string> | ||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*X = (int *)0</string> | ||
|
||
#undef M | ||
#define M F2(&X) | ||
|
||
void test4() { | ||
int *X; | ||
M; | ||
*X = 1; // expected-warning{{Dereference of null pointer}} | ||
} | ||
|
||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>F2(&X)</string> | ||
// CHECK: <key>name</key><string>M</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*Y = (int *)0</string> | ||
|
||
void test_h() { | ||
int *X; | ||
F_H(&X); | ||
*X = 1; // expected-warning{{Dereference of null pointer}} | ||
} | ||
|
||
// CHECK: <key>name</key><string>M_H</string> | ||
// CHECK-NEXT: <key>expansion</key><string>*A = (int *)0</string> |