[llvm-bugs] [Bug 35029] New: libclang: unterminated conditional directive when generating preamble

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 22 11:23:16 PDT 2017


            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: unassignedclangbugs at nondot.org
          Reporter: puremourning at gmail.com
                CC: llvm-bugs at lists.llvm.org

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

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() {}


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__

In editing mode:

BeniMac:basic ben$ CINDEXTEST_EDITING=1 
/Users/ben/Development/llvm.git-build/bin/c-index-test -test-load-source local
// CHECK: circular.h:6:5: FunctionDecl=main:6:5 (Definition) Extent=[6:1 -
// 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
// 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171022/24db4c68/attachment-0001.html>

More information about the llvm-bugs mailing list