Skip to content

Commit 82c6897

Browse files
committed
Pre-commit test: [Preprocessor] Do not expand macros if the input is already preprocessed
1 parent fe0dbe0 commit 82c6897

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED
2+
// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=EXPANDED
3+
4+
// EXPANDED: void __attribute__((__attribute__((always_inline)))) foo()
5+
6+
#define always_inline __attribute__((always_inline))
7+
void __attribute__((always_inline)) foo() {
8+
return 4;
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -E -x c %s | FileCheck %s
2+
// RUN: %clang_cc1 -x c -fsyntax-only %s -verify
3+
// RUN: %clang_cc1 -x cpp-output -fsyntax-only -verify %s
4+
// expected-no-diagnostics
5+
6+
// The preprocessor does not expand macro-identifiers in #pragma directives.
7+
// When we preprocess & parse the code, clang expands the macros in directives.
8+
// When we parse already preprocessed code, clang still has to expand the
9+
// macros in the directives.
10+
// This means that we're not always able to parse the preprocessor's output
11+
// without preserving the definitions (-dD).
12+
13+
#define FACTOR 4
14+
15+
void foo() {
16+
// CHECK: #pragma unroll FACTOR
17+
#pragma unroll FACTOR
18+
for(;;) {
19+
}
20+
return;
21+
}

0 commit comments

Comments
 (0)