diff options
author | Erik Verbruggen <erikjv@me.com> | 2017-05-30 11:54:55 +0000 |
---|---|---|
committer | Erik Verbruggen <erikjv@me.com> | 2017-05-30 11:54:55 +0000 |
commit | 0289cea07c4cf50b36f6f9c9e60ac2d35c624946 (patch) | |
tree | 777717e284d92304e2db18e5cb00e26c8c999d64 /test/Lexer | |
parent | bccb6a479f9f7afe6912c97223cb0489a231c63c (diff) |
Allow for unfinished #if blocks in preambles
Previously, a preamble only included #if blocks (and friends like
ifdef) if there was a corresponding #endif before any declaration or
definition. The problem is that any header file that uses include guards
will not have a preamble generated, which can make code-completion very
slow.
To prevent errors about unbalanced preprocessor conditionals in the
preamble, and unbalanced preprocessor conditionals after a preamble
containing unfinished conditionals, the conditional stack is stored
in the pch file.
This fixes PR26045.
Differential Revision: http://reviews.llvm.org/D15994
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304207 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Lexer')
-rw-r--r-- | test/Lexer/preamble.c | 11 | ||||
-rw-r--r-- | test/Lexer/preamble2.c | 19 |
2 files changed, 24 insertions, 6 deletions
diff --git a/test/Lexer/preamble.c b/test/Lexer/preamble.c index 5b2739abef..762271f2e3 100644 --- a/test/Lexer/preamble.c +++ b/test/Lexer/preamble.c @@ -9,15 +9,12 @@ #pragma unknown #endif #ifdef WIBBLE -#include "honk" -#else -int foo(); +#include "foo" +int bar; #endif // This test checks for detection of the preamble of a file, which -// includes all of the starting comments and #includes. Note that any -// changes to the preamble part of this file must be mirrored in -// Inputs/preamble.txt, since we diff against it. +// includes all of the starting comments and #includes. // RUN: %clang_cc1 -print-preamble %s > %t // RUN: echo END. >> %t @@ -33,4 +30,6 @@ int foo(); // CHECK-NEXT: #endif // CHECK-NEXT: #pragma unknown // CHECK-NEXT: #endif +// CHECK-NEXT: #ifdef WIBBLE +// CHECK-NEXT: #include "foo" // CHECK-NEXT: END. diff --git a/test/Lexer/preamble2.c b/test/Lexer/preamble2.c new file mode 100644 index 0000000000..499a9a22a5 --- /dev/null +++ b/test/Lexer/preamble2.c @@ -0,0 +1,19 @@ +// Preamble detection test: header with an include guard. +#ifndef HEADER_H +#define HEADER_H +#include "foo" +int bar; +#endif + +// This test checks for detection of the preamble of a file, which +// includes all of the starting comments and #includes. + +// RUN: %clang_cc1 -print-preamble %s > %t +// RUN: echo END. >> %t +// RUN: FileCheck < %t %s + +// CHECK: // Preamble detection test: header with an include guard. +// CHECK-NEXT: #ifndef HEADER_H +// CHECK-NEXT: #define HEADER_H +// CHECK-NEXT: #include "foo" +// CHECK-NEXT: END. |