mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C++: Turn header variant tests that use PCH files into integration tests
These tests currently test a code path in the extractor that only exists for these tests. By turning them into integration tests, we actually use the code path that normal database creation uses.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
#include "a.h"
|
||||
#define FOUR 4
|
||||
@@ -0,0 +1 @@
|
||||
#define ONE 1
|
||||
@@ -0,0 +1,7 @@
|
||||
#define TWO 2
|
||||
#include "b.h"
|
||||
|
||||
int main() {
|
||||
return ONE + TWO + THREE + FOUR;
|
||||
}
|
||||
// semmle-extractor-options: --clang -include-pch ${testdir}/clang-pch.testproj/a.pch -Iextra_dummy_path
|
||||
@@ -0,0 +1 @@
|
||||
#define THREE 3
|
||||
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return ONE + FOUR;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
| b.c:5:3:5:34 | return ... | 10 |
|
||||
| c.c:2:3:2:20 | return ... | 5 |
|
||||
| e.c:2:3:2:19 | return ... | 17 |
|
||||
| g.c:3:3:3:12 | return ... | 20 |
|
||||
| i.c:3:3:3:12 | return ... | 30 |
|
||||
| i.c:8:3:8:12 | return ... | 31 |
|
||||
| i.c:13:3:13:12 | return ... | 32 |
|
||||
@@ -0,0 +1,4 @@
|
||||
import cpp
|
||||
|
||||
from ReturnStmt rs
|
||||
select rs, rs.getExpr().getValue()
|
||||
@@ -0,0 +1 @@
|
||||
#import "d.h"
|
||||
@@ -0,0 +1 @@
|
||||
enum { SEVENTEEN = 17 };
|
||||
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return SEVENTEEN;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#if 1
|
||||
#pragma hdrstop
|
||||
extern int x;
|
||||
#define SEEN_F
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifdef SEEN_F
|
||||
static int g() {
|
||||
return 20;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "h1.h"
|
||||
#pragma hdrstop
|
||||
#include "h2.h"
|
||||
#define SEEN_H
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
#define H1
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
#define H2
|
||||
|
||||
15
cpp/ql/integration-tests/header-variant-tests/clang-pch/i.c
Normal file
15
cpp/ql/integration-tests/header-variant-tests/clang-pch/i.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifdef SEEN_H
|
||||
static int h() {
|
||||
return 30;
|
||||
}
|
||||
#endif
|
||||
#ifdef H1
|
||||
static int h1() {
|
||||
return 31;
|
||||
}
|
||||
#endif
|
||||
#ifdef H2
|
||||
static int h2() {
|
||||
return 32;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
|
||||
def test(codeql, cpp):
|
||||
os.mkdir("pch")
|
||||
codeql.database.create(command=[
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/a.pch a.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/a.pch -Iextra_dummy_path b.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -include pch/a -Iextra_dummy_path c.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/d.pch d.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/d.pch e.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/f.pch f.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/f.pch g.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/h.pch h.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-clang -include-pch pch/h.pch i.c',
|
||||
])
|
||||
@@ -0,0 +1 @@
|
||||
#include "a.h"
|
||||
@@ -0,0 +1 @@
|
||||
#define A 1
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma hdrstop
|
||||
#include "b.h"
|
||||
|
||||
int b() {
|
||||
return A;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "d.h"
|
||||
#include "c.h"
|
||||
|
||||
int c() {
|
||||
return A;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
| b | 1 |
|
||||
| c | 1 |
|
||||
@@ -0,0 +1,4 @@
|
||||
import cpp
|
||||
|
||||
from ReturnStmt rs
|
||||
select rs.getEnclosingFunction().getName(), rs.getExpr().(Literal).getValue()
|
||||
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
|
||||
|
||||
def test(codeql, cpp):
|
||||
os.mkdir("pch")
|
||||
codeql.database.create(command=[
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-cl /Yca.h /Fppch/a.pch a.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-cl /Yub.h /Fppch/a.pch b.c',
|
||||
f'"{cpp.get_tool("extractor")}" --mimic-cl /Yuc.h /Fppch/a.pch c.c',
|
||||
])
|
||||
Reference in New Issue
Block a user