Scan-build from llvm 7.0 seems broken on macOS Mojave


(Sergey Elin) #1

Hi there,

tried to run scan-build against rocksdb source code failed with a lot of similar errors like below:

% scan-build make       
scan-build: Using '/usr/local/Cellar/llvm/7.0.0/bin/clang-7' for static analysis
Makefile:133: Warning: Compiling in debug mode. Don't use the resulting binary in production
  GEN      util/build_version.cc
In file included from db/malloc_stats.cc:10:
In file included from ./db/malloc_stats.h:14:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string:500:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string_view:176:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/__string:56:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/algorithm:642:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/cstring:61:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.

but file is actually here

% stat /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string.h
16777220 8630791949 -rw-r--r-- 1 yes staff 0 4661 "Oct  5 15:15:49 2018" "Sep 11 11:39:31 2018" "Oct  5 13:30:54 2018" "Sep 11 11:39:31 2018" 4096 16 0 /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string.h

at the same time I can run make command to get work done without errors.

% brew config
HOMEBREW_VERSION: 1.7.6-107-gd5444b6
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: d5444b62562949edd3b4494341333e1897078c9b
Last commit: 10 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 79545d05fae26468c30628519b3d4985329063e5
Core tap last commit: 2 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DEV_CMD_RUN: 1
CPU: quad-core 64-bit broadwell
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 10.0 build 1000
Git: 2.19.0 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: 1.8.0_112, 1.8.0_60
macOS: 10.14-x86_64
CLT: 10.0.0.0.1.1535735448
Xcode: 10.0
XQuartz: 2.7.11 => /opt/X11

How can I fix that?


(Sergey Elin) #2

Here is verbose output for scan-build

b% scan-build -v -v -v make
scan-build: Using '/usr/local/Cellar/llvm/7.0.0/bin/clang-7' for static analysis
scan-build: Emitting reports for this run to '/var/folders/sc/pk6mltk53nv_rh7k1r3nf1z00000gn/T/scan-build-2018-10-05-155219-71079-1'.
Makefile:137: Warning: Compiling in debug mode. Don't use the resulting binary in production
  GEN      util/build_version.cc
  CC       util/filelock_test.o
In file included from util/filelock_test.cc:6:
In file included from ./include/rocksdb/status.h:20:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string:500:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/string_view:176:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/__string:56:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/algorithm:642:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/cstring:61:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.
clang++ -DROCKSDB_USE_RTTI -g -W -Wextra -Wall -Wsign-compare -Wshadow -Wunused-parameter -Werror -I. -I./include -std=c++11 -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DOS_MACOSX -DLZ4 -Wshorten-64-to-32 -march=native -DROCKSDB_SUPPORT_THREAD_LOCAL -isystem ./third-party/gtest-1.7.0/fused-src -O2 -fno-omit-frame-pointer -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -c util/filelock_test.cc -o util/filelock_test.o
make: *** [util/filelock_test.o] Error 1
scan-build: Removing directory '/var/folders/sc/pk6mltk53nv_rh7k1r3nf1z00000gn/T/scan-build-2018-10-05-155219-71079-1' because it contains no reports.
scan-build: No bugs found.

(Sergey Elin) #3
% /usr/local/opt/llvm/bin/clang++ bug.cpp
In file included from bug.cpp:1:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/ios:215:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iosfwd:90:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

(Sergey Elin) #4
% cat bug.cpp 
#include <iostream>

int main(int argc, char *argv[]) {
        std::cout << "main() end\n";
        return 0;
}


(Sean Molenaar) #5

Not really sure where the issue is here. What makes you think it’s a brew issue?


(Sergey Elin) #6

Because “system” clang ang brewed gcc works just fine, but brewed llvm 7.0 and 6.0.1 gives the same error, and I trying to understand why

% g++-8 --version
g++-8 (Homebrew GCC 8.2.0) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

yes@arben:Projects/cpp% g++-8 bug.cpp  
yes@arben:Projects/cpp% /usr/bin/clang++ --version
Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
yes@arben:Projects/cpp% /usr/bin/clang++ bug.cpp  

(Sergey Elin) #7

Here is another person with the same error: https://stackoverflow.com/questions/52629110/clang-installed-via-homebrew-macos-compilation-errors

And more info in my case: https://github.com/Homebrew/homebrew-core/issues/32765


(Sergey Elin) #8

Also I tried to completely reinstall XCode and Apple CLT (thinking that the problem in broken internals) but the problem still persist.


(Sergey Elin) #9

So it seems llvm now requires explicit include specification:

% /usr/local/Cellar/llvm/7.0.0/bin/clang++ -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include bug.cpp
% ./a.out 
main() end


(Andrey Fedorov) #10

I had the same error as in the initial post. It went away after I installed (uncompressed and copied to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs) 10.13 SDK from here: https://github.com/phracker/MacOSX-SDKs/releases/tag/10.13.