Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

libclang: unterminated conditional directive when generating preamble #34002

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR35029
Status NEW
Importance P normal
Reported by Ben Jackson (puremourning@gmail.com)
Reported on 2017-10-22 11:23:16 -0700
Last modified on 2017-10-26 16:08:45 -0700
Version 5.0
Hardware All All
CC contact@micbou.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

Since clang 5.0 (and currently in master), libclang reports "unterminated conditional directive" when an "include guarded" file transitively includes itself. Or at least that's how it appears.

There are two simple test cases, both of which compile fine when not in "editing" mode, but raise "unterminated conditional directive" when building a preamble.

More info: https://github.com/Valloric/YouCompleteMe/issues/2795

Tests reproduced with both clang 5.0 prebuilt binaries and a build of master as of yesterday (Sat 21st October).

Test case 1: Header includes itself.

#ifndef TEST_C
#define TEST_C

#include "test.c"

int main() {}

#endif

Normal compilation

BeniMac:basic ben$ /Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local circular.h
// CHECK: <invalid loc>:2:9: macro definition=__llvm__
// CHECK: <invalid loc>:3:9: macro definition=__clang__
// CHECK: <invalid loc>:4:9: macro definition=__clang_major__
// CHECK: <invalid loc>:5:9: macro definition=__clang_minor__
// CHECK: <invalid loc>:6:9: macro definition=__clang_patchlevel__
...
works.

In editing mode:

BeniMac:basic ben$ CINDEXTEST_EDITING=1  /Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local circular.h
// CHECK: circular.h:6:5: FunctionDecl=main:6:5 (Definition) Extent=[6:1 - 6:14]
// CHECK: circular.h:6:12: CompoundStmt= Extent=[6:12 - 6:14]
./circular.h:1:2: error: unterminated conditional directive
Number FIX-ITs = 0

Test case 2 (perhaps more realistic in editor scenarios, where users use -include b.h to make completion work within a.h):

#include "b.h"
#ifndef A_H
#define A_H
int main() {}
#endif /* A_H */
#ifndef B_H
#define B_H
#include "a.h"
#endif /* B_H */

Again, compilation is fine until using the editor flags:

BeniMac:basic ben$ CINDEXTEST_EDITING=1  /Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local a.h
// CHECK: a.h:4:5: FunctionDecl=main:4:5 (Definition) Extent=[4:1 - 4:14]
// CHECK: a.h:4:12: CompoundStmt= Extent=[4:12 - 4:14]
./a.h:2:2: error: unterminated conditional directive
Number FIX-ITs = 0

I suspect (truly a guess), that this commit is the culprit, though I haven't proven it: https://reviews.llvm.org/D15994#95a083c2

Quuxplusone commented 7 years ago
Correction on test case 1, file name was wrong:

```circular.h
#ifndef TEST_C
#define TEST_C

#include "circular.h"

int main() {}

#endif