https://bugs.llvm.org/show_bug.cgi?id=35029

            Bug ID: 35029
           Summary: libclang: unterminated conditional directive when
                    generating preamble
           Product: clang
           Version: 5.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.

```circular.h
#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`):

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

```b.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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to