c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

clang and llvm mismatch not detected

Open chrysn opened this issue 4 years ago • 0 comments

It can easily happen that the installed llvm and clang are in different versions, resulting in errors like this, eg. on a Debian sid system with clang=clang-12 from experimental:

[ 91%] Building CXX object CMakeFiles/clangAstExporter.dir/ExportResult.cpp.o

--- stderr
make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
In file included from /usr/lib/llvm-12/include/clang/Basic/Version.h:18,
                 from /home/chrysn/git/crates/c2rust/c2rust-ast-exporter/src/AstExporter.cpp:26:
/usr/lib/llvm-12/include/clang/Basic/Version.inc:2: warning: "CLANG_VERSION_STRING" redefined
    2 | #define CLANG_VERSION_STRING "12.0.1"
      | 
<command-line>: note: this is the location of the previous definition
In file included from /usr/lib/llvm-12/include/clang/Basic/FileEntry.h:25,
                 from /usr/lib/llvm-12/include/clang/Basic/SourceManager.h:38,
                 from /usr/lib/llvm-12/include/clang/Frontend/ASTUnit.h:23,
                 from /usr/lib/llvm-12/include/clang/Frontend/FrontendAction.h:23,
                 from /usr/lib/llvm-12/include/clang/Frontend/FrontendActions.h:12,
                 from /home/chrysn/git/crates/c2rust/c2rust-ast-exporter/src/AstExporter.cpp:15:
/usr/lib/llvm-12/include/llvm/Support/FileSystem/UniqueID.h:23:7: error: redefinition of ‘class llvm::sys::fs::UniqueID’
   23 | class UniqueID {
      |       ^~~~~~~~
In file included from /usr/lib/llvm-11/include/llvm/Support/VirtualFileSystem.h:24,
                 from /usr/lib/llvm-11/include/llvm/Support/CommandLine.h:34,
                 from /home/chrysn/git/crates/c2rust/c2rust-ast-exporter/src/AstExporter.cpp:11:
/usr/lib/llvm-11/include/llvm/Support/FileSystem.h:134:7: note: previous definition of ‘class llvm::sys::fs::UniqueID’
  134 | class UniqueID {
      |       ^~~~~~~~
In file included from /usr/lib/llvm-12/include/clang/AST/DeclOpenMP.h:21,
                 from /usr/lib/llvm-12/include/clang/AST/DeclVisitor.h:21,
                 from /home/chrysn/git/crates/c2rust/c2rust-ast-exporter/src/AstExporter.cpp:18:
/usr/lib/llvm-12/include/clang/AST/OpenMPClause.h:7901:8: error: ‘bool clang::TargetOMPContext::matchesISATrait(llvm::StringRef) const’ marked ‘override’, but does not override
 7901 |   bool matchesISATrait(StringRef RawString) const override;
      |        ^~~~~~~~~~~~~~~
In file included from /usr/lib/llvm-12/include/clang/Frontend/CompilerInstance.h:17,
                 from /home/chrysn/git/crates/c2rust/c2rust-ast-exporter/src/AstExporter.cpp:27:
/usr/lib/llvm-12/include/clang/Frontend/Utils.h:155:24: error: ‘PathCanonicalizer’ in ‘class llvm::FileCollector’ does not name a type
  155 |   llvm::FileCollector::PathCanonicalizer Canonicalizer;
      |                        ^~~~~~~~~~~~~~~~~
gmake[3]: *** [CMakeFiles/clangAstExporter.dir/build.make:82: CMakeFiles/clangAstExporter.dir/AstExporter.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:103: CMakeFiles/clangAstExporter.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:110: CMakeFiles/clangAstExporter.dir/rule] Error 2

The clue to what went wrong was that both -11 and -12 LLVM headers were included in the same file. The above error went away when I removed the old llvm-11 installation that was still present.

It might be convenient to check for this condition at some point in the build system. (But this is also reported to make the error and the workaround discoverable more easily until then).

chrysn avatar Aug 25 '21 08:08 chrysn