2 # Stop at the first error
4 if ! test -d debian
/; then
5 echo "$0: Could not find the debian/ directory"
8 VERSION
=$
(dpkg-parsechangelog |
sed -rne "s,^Version: 1:([0-9]+).*,\1,p")
9 DETAILED_VERSION
=$
(dpkg-parsechangelog |
sed -rne "s,^Version: 1:([0-9.]+)(~|-)(.*),\1\2\3,p")
10 DEB_HOST_ARCH
=$
(dpkg-architecture
-qDEB_HOST_ARCH)
12 LIST
="libomp5-${VERSION}_${DETAILED_VERSION}_amd64.deb libomp-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb lldb-${VERSION}_${DETAILED_VERSION}_amd64.deb python3-lldb-${VERSION}_${DETAILED_VERSION}_amd64.deb libllvm${VERSION}_${DETAILED_VERSION}_amd64.deb llvm-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb liblldb-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb libclang1-${VERSION}_${DETAILED_VERSION}_amd64.deb libclang-common-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb llvm-${VERSION}_${DETAILED_VERSION}_amd64.deb liblldb-${VERSION}_${DETAILED_VERSION}_amd64.deb llvm-${VERSION}-runtime_${DETAILED_VERSION}_amd64.deb lld-${VERSION}_${DETAILED_VERSION}_amd64.deb libfuzzer-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb libclang-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb libc++-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb libc++abi-${VERSION}-dev_${DETAILED_VERSION}_amd64.deb libc++1-${VERSION}_${DETAILED_VERSION}_amd64.deb libc++abi1-${VERSION}_${DETAILED_VERSION}_amd64.deb clang-${VERSION}_${DETAILED_VERSION}_amd64.deb llvm-${VERSION}-tools_${DETAILED_VERSION}_amd64.deb clang-tools-${VERSION}_${DETAILED_VERSION}_amd64.deb clangd-${VERSION}_${DETAILED_VERSION}_amd64.deb clang-${VERSION}-dbgsym_${DETAILED_VERSION}_amd64.deb libclang1-${VERSION}-dbgsym_${DETAILED_VERSION}_amd64.deb libclang-cpp${VERSION}_${DETAILED_VERSION}_amd64.deb clang-tidy-${VERSION}_${DETAILED_VERSION}_amd64.deb libclang-cpp${VERSION}-dev_${DETAILED_VERSION}_amd64.deb"
13 echo "To install everything:"
14 echo "sudo apt --purge remove 'libomp5-*' 'libc++*dev' 'libc++*' 'python3-lldb-*'"
15 echo "sudo dpkg -i $LIST"
18 L
="$L $(echo $f|cut -d_ -f1)"
21 echo "apt-get install $L"
23 if test ! -f /usr
/bin
/llvm-config-
$VERSION; then
24 echo "Install llvm-$VERSION & llvm-$VERSION-dev"
27 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libLLVM-
$VERSION.so
; then
28 echo "Install llvm-$VERSION-dev"
32 echo "Testing llvm-$VERSION and llvm-$VERSION-dev ..."
33 llvm-config-
$VERSION --link-shared --libs &> /dev
/null
35 if llvm-config-
$VERSION --cxxflags |
grep " \-W"; then
36 echo "llvm-config should not export -W warnings"
40 # Test https://bugs.llvm.org/show_bug.cgi?id=40059
41 nm
/usr
/lib
/llvm-
$VERSION/lib
/libLLVMBitWriter.a
&> foo.log
42 if grep "File format not recognized" foo.log
; then
43 echo "nm libLLVMBitWriter.a contains 'File format not recognized'"
47 if test ! -f /usr
/bin
/scan-build-
$VERSION; then
48 echo "Install clang-tools-$VERSION"
51 echo "Testing clang-tools-$VERSION ..."
60 # Ignore if gcc isn't available
61 scan-build-
$VERSION -o scan-build gcc
-c foo.c
&> /dev
/null || true
62 scan-build-
$VERSION -o scan-build clang-
$VERSION -c foo.c
&> /dev
/null
63 scan-build-
$VERSION --exclude non-existing
/ --exclude /tmp
/ -v clang-
$VERSION -c foo.c
&> /dev
/null
64 scan-build-
$VERSION --exclude $
(pwd) -v clang-
$VERSION -c foo.c
&> foo.log
65 if ! grep -q -E "scan-build: 0 bugs found." foo.log
; then
66 echo "scan-build --exclude didn't ignore the defect"
71 echo 'namespace mozilla {
77 clang-tidy-
$VERSION -checks='modernize-concat-nested-namespaces' foo.cpp
-extra-arg=-std=c
++17 &> foo.log
78 if ! grep -q "nested namespaces can " foo.log
; then
79 echo "Clang-tidy didn't detect the issue"
85 rm -rf cmaketest
&& mkdir cmaketest
86 cat > cmaketest
/CMakeLists.txt
<<EOF
87 cmake_minimum_required(VERSION 2.8.12)
89 add_library(MyLibrary foo.cpp)
91 mkdir cmaketest
/standard
95 CXX
=clang-
$VERSION cmake
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
> /dev
/null
97 clang-tidy-
$VERSION -checks='modernize-concat-nested-namespaces' ..
/foo.cpp
-extra-arg=-std=c
++17 -fix &> foo.log
98 if ! grep -q "namespace mozilla::dom" ..
/foo.cpp
; then
99 echo "clang-tidy autofix didn't work"
106 echo "Testing clangd-$VERSION ..."
111 "method": "initialize",
117 "snippetSupport": true
128 "method": "textDocument/didOpen",
131 "uri": "test:///main.cpp",
134 "text": "int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"
142 "method": "textDocument/completion",
145 "uri": "test:///main.cpp"
166 clangd-
$VERSION -lit-test -pch-storage=memory
< a.json
&> foo.log
167 if ! grep -q '"insertText": "func_with_args(${1:int a}, ${2:int b})",' foo.log
; then
168 echo "clangd didn't export what we were expecting"
173 echo 'namespace mozilla {
177 int fonction_avec_args(int a, float b);
185 content
=$
(sed ':a;N;$!ba;s/\n/\\n/g' foo.cpp
)
189 "method": "initialize",
195 "snippetSupport": true
206 "method": "textDocument/didOpen",
209 "uri": "file:///'$
(pwd)'/cmaketest/foo.cpp",
220 "method": "textDocument/completion",
223 "uri": "file:///'$
(pwd)'/cmaketest/foo.cpp"
244 rm -rf cmaketest
&& mkdir cmaketest
245 cat > cmaketest
/CMakeLists.txt
<<EOF
246 cmake_minimum_required(VERSION 2.8.12)
248 add_library(MyLibrary foo.cpp)
250 mkdir cmaketest
/standard
251 cp foo.cpp cmaketest
/
252 cp a.json cmaketest
/standard
253 cd cmaketest
/standard
257 CXX
=clang-
$VERSION cmake
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
> /dev
/null
258 # TODO this test is useless as it doesn't leverage foo.cpp or the compiledb
259 clangd-
$VERSION -lit-test -pch-storage=memory
< a.json
&> foo.log
260 if ! grep -q '"insertText": "fonction_avec_args(${1:int a}, ${2:float b})",' foo.log
; then
261 echo "clangd didn't export what we were expecting"
269 echo "Testing clang-$VERSION ..."
272 echo 'int main() {return 0;}' > foo.c
275 echo '#include <stdio.h>
280 clang-
$VERSION -S -emit-llvm foo.c
282 if ! lli-
$VERSION foo.ll|
grep -q "lli foo"; then
283 echo "Not lli correct output"
287 opt-
$VERSION -S -O3 foo.ll
-o opt.ll
288 if ! lli-
$VERSION opt.ll|
grep -q "lli foo"; then
289 echo "Not lli correct output after opt"
294 clang-
$VERSION -O3 -emit-llvm foo.c
-c -o foo.
bc
296 # only run if the binfmt is installed correctly
297 /usr
/sbin
/update-binfmts
--display llvm-
$VERSION-runtime.binfmt
&> foo.log || true
298 if grep -q "interpreter = /usr/bin/lli-" foo.log
; then
299 /usr
/sbin
/update-binfmts
--enable llvm-
$VERSION-runtime.binfmt || true
300 if ! .
/foo.
bc|
grep -q "lli foo"; then
301 echo "executing ./foo.bc failed"
306 clang-
$VERSION -O3 -emit-llvm foo.c
-c -o foo.
bc
308 if ! .
/foo.
bc|
grep -q "lli foo"; then
309 echo "executing ./foo.bc failed"
315 if ! llvm-dis-
$VERSION < foo.
bc|
grep -q "lli foo"; then
316 echo "llvm assembly code failed"
317 llvm-dis-
$VERSION < foo.
bc
321 echo '#include <stddef.h>' > foo.c
322 clang-
$VERSION -c foo.c
324 # https://bugs.launchpad.net/bugs/1810860
325 clang-
$VERSION -dumpversion &> foo.log
326 if grep -q 4.2.1 foo.log
; then
327 echo "dumpversion still returns 4.2.1"
328 echo "it should return the clang version"
334 echo '#include <stdatomic.h>
335 void increment(atomic_size_t *arg) {
336 atomic_fetch_add(arg, 1);
339 clang-
$VERSION -v -c foo.c
&> /dev
/null
341 echo "#include <fenv.h>" > foo.cc
342 NBLINES
=$
(clang
++-$VERSION -P -E foo.cc|
wc -l)
343 if test $NBLINES -lt 100; then
344 echo "Error: more than 100 lines should be returned"
348 if [ $DEB_HOST_ARCH != "arm64" -a $DEB_HOST_ARCH != "ppc64el" ]; then
349 # Fails on arm64 with
350 # /usr/lib/llvm-10/lib/clang/10.0.0/include/mmintrin.h:33:5: error: use of undeclared identifier '__builtin_ia32_emms'; did you mean '__builtin_isless'?
351 echo '#include <emmintrin.h>' > foo.cc
352 clang
++-$VERSION -c foo.cc
356 echo '#include <limits.h>' | clang-
$VERSION -E - > /dev
/null
358 # Bug launchpad #1488254
361 std::string hello = "Hello, world!\n";
367 extern std::string hello;
373 g
++ -c foo.cc
&& g
++ foo.o bar.cc
&& .
/a.out
> /dev
/null || true
374 clang
++-$VERSION -c foo.cc
&& clang
++-$VERSION foo.o bar.cc
&& .
/a.out
> /dev
/null
375 g
++ -c foo.cc
&& clang
++-$VERSION foo.o bar.cc
&& .
/a.out
> /dev
/null || true
376 clang
++-$VERSION -c foo.cc
-fPIC && g
++ foo.o bar.cc
&& .
/a.out
> /dev
/null || true
380 void clang_analyzer_eval(int);
381 void testBitwiseRules(unsigned int a, int b) {
382 clang_analyzer_eval((1 & a) <= 1); // expected-warning{{TRUE}}
383 // with -analyzer-constraints=z3, it can tell that it is FALSE
384 // without the option, it is unknown
385 clang_analyzer_eval((b | -2) >= 0); // expected-warning{{FALSE}}
388 if dpkg
-l|
grep -q libz3-dev
; then
390 clang-
$VERSION -cc1 -analyze -analyzer-constraints=range
-analyzer-checker=core
,debug.ExprInspection
-verify -analyzer-config eagerly-assume
=false
-analyzer-constraints=z3 foo.c
392 echo "z3 support not available"
396 clang-
$VERSION -cc1 -analyze -analyzer-constraints=range
-analyzer-checker=core
,debug.ExprInspection
-verify -analyzer-config eagerly-assume
=false foo.c
&> foo.log || true
397 if grep -q "File a.c Line 7: UNKNOWN" foo.log
; then
398 echo "Should fail without -analyzer-constraints=z3"
402 if dpkg
-l|
grep -q libz3-dev
; then
403 clang-
$VERSION -cc1 -analyze -analyzer-constraints=range
-analyzer-checker=core
,debug.ExprInspection
-analyzer-constraints=z3 foo.c
&> foo.log
404 if ! grep -q "2 warnings generated." foo.log
; then
405 echo "Should find 2 warnings"
409 echo "z3 support not available"
412 clang-
$VERSION -cc1 -analyze -analyzer-constraints=range
-analyzer-checker=core
,debug.ExprInspection foo.c
&> foo.log
413 if ! grep -q "3 warnings generated." foo.log
; then
414 echo "Should find 3 warnings"
419 echo 'bool testAndSet(void *atomic) {
420 return __atomic_test_and_set(atomic, __ATOMIC_SEQ_CST);
422 clang
++-$VERSION -c -target aarch64-linux-gnu foo.cpp
423 if ! file foo.o
2>&1 |
grep -i -q "aarch64"; then
424 echo "Could not find the string 'aarch64' in the output of file. Output:"
429 clang-
$VERSION --target=arm-linux-gnueabihf
-dM -E -xc - < /dev
/null
&> foo.log
430 if ! grep -q "#define __ARM_ARCH 7" foo.log
; then
432 echo "The target arch for arm should be v7"
445 clang-
$VERSION -c foo.c
447 echo '#include <errno.h>
448 int main() {} ' > foo.c
451 echo '#include <chrono>
452 int main() { }' > foo.cpp
453 clang
++-$VERSION -std=c
++11 foo.cpp
455 echo "Testing linking clang-cpp ..."
457 clang-
$VERSION -lclang-cpp$VERSION -v foo.cpp
-o o
&> /dev
/null || true
458 if ! ldd o
2>&1|
grep -q libclang-cpp
; then
459 echo "Didn't link against libclang-cpp$VERSION"
464 # Check that the symlink is correct
465 ls -al /usr
/lib
/llvm-
$VERSION/lib
/libclang-cpp.so.
$VERSION > /dev
/null
467 echo "Testing code coverage ..."
469 echo '#include <stdio.h>
478 clang-
$VERSION --coverage foo.c
-o foo
480 if test ! -f foo.gcno
; then
481 echo "Coverage failed";
484 echo "#include <iterator>" > foo.cpp
485 clang
++-$VERSION -c foo.cpp
487 echo "Testing linking ..."
488 if test ! -f /usr
/lib
/llvm-
$VERSION/bin
/..
/lib
/LLVMgold.so
; then
489 echo "Install llvm-$VERSION-dev"
493 echo '#include <stdio.h>
504 clang-
$VERSION -flto foo.c
-o foo
507 clang-
$VERSION -fuse-ld=gold foo.c
-o foo
511 echo "int foo(void) { return 0; }"> foo.c
512 echo "int foo(void); int main() {foo(); return 0;}">main.c
513 clang-
$VERSION -flto=thin
-O2 foo.c main.c
-o foo
515 clang-
$VERSION -flto=thin
-O2 foo.c main.c
-c
517 echo "Testing lld-$VERSION ..."
519 if test ! -f /usr
/bin
/lld-
$VERSION; then
520 echo "Install lld-$VERSION"
523 clang-
$VERSION -fuse-ld=lld
-O2 foo.c main.c
-o foo
526 if ls -al1 /usr
/bin
/ld.lld|
grep ld.lld-
$VERSION; then
527 # https://bugs.llvm.org/show_bug.cgi?id=40659
528 # -fuse-ld=lld will call lld
529 # Mismatch of version can fail the check
530 # so, only run it when /usr/bin/lld == $VERSION
531 clang-
$VERSION -fuse-ld=lld
-flto -O2 foo.c main.c
-o foo
535 clang-
$VERSION -fuse-ld=lld-
$VERSION -O2 foo.c main.c
-o foo
540 if ! grep -q "BuildID" foo.log
; then
541 echo "BuildID isn't part of the generated binary (lld generation)"
545 clang-
$VERSION -O2 foo.c main.c
-o foo2
546 file foo2
&> foo2.log
547 if ! grep -q "BuildID" foo2.log
; then
548 echo "BuildID isn't part of the generated binary (ld generation)"
553 file foo2
&> foo2.log
554 if ! grep -q "BuildID" foo2.log
; then
555 echo "BuildID isn't part of the generated binary (stripped)"
560 if test ! -f /usr
/lib
/llvm-
$VERSION/bin
/llvm-symbolizer
; then
561 echo "Install llvm-$VERSION"
565 echo "vzeroupper" | llvm-exegesis-
$VERSION -mode=uops
-snippets-file=- &> foo.log || true
566 if grep -q -E "(built without libpfm|cannot initialize libpfm)" foo.log
; then
567 echo "could not run llvm-exegesis correctly"
572 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libFuzzer.a
; then
573 echo "Install libfuzzer-$VERSION-dev";
577 echo "Testing libfuzzer-$VERSION-dev ..."
579 cat << EOF > test_fuzzer.cc
582 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
583 if (size > 0 && data[0] == 'H')
584 if (size > 1 && data[1] == 'I')
585 if (size > 2 && data[2] == '!')
592 clang
++-$VERSION -fsanitize=address
-fsanitize-coverage=edge
,trace-pc test_fuzzer.cc
/usr
/lib
/llvm-
$VERSION/lib
/libFuzzer.a
593 if ! .
/a.out
2>&1 |
grep -q -E "(Test unit written|PreferSmall)"; then
598 clang
++-$VERSION -fsanitize=address
,fuzzer test_fuzzer.cc
599 if ! .
/a.out
2>&1 |
grep -q "libFuzzer: deadly signal"; then
603 echo 'int main(int argc, char **argv) {
604 int *array = new int[100];
606 return array[argc]; // BOOM
608 clang
++-$VERSION -O1 -g -fsanitize=address
-fno-omit-frame-pointer foo.cpp
609 ASAN_OPTIONS
=verbosity
=1 .
/a.out
&> foo.log || true
610 if ! grep -q "Init done" foo.log
; then
611 echo "asan verbose mode failed"
616 # See also https://bugs.llvm.org/show_bug.cgi?id=39514 why
617 # /usr/bin/llvm-symbolizer-7 doesn't work
618 ASAN_OPTIONS
=verbosity
=2:external_symbolizer_path
=/usr
/lib
/llvm-
$VERSION/bin
/llvm-symbolizer .
/a.out
&> foo.log || true
619 if ! grep -q "Using llvm-symbolizer" foo.log
; then
620 echo "could not find llvm-symbolizer path"
624 if ! grep -q "new\[\](unsigned" foo.log
; then
625 echo "could not symbolize correctly"
630 if ! grep -q "foo.cpp:3:3" foo.log
; then
631 echo "could not symbolize correctly"
635 .
/a.out
&> foo.log || true
636 if ! grep -q "new\[\](unsigned" foo.log
; then
637 echo "could not symbolize correctly"
642 if ! grep -q "foo.cpp:3:3" foo.log
; then
643 echo "could not symbolize correctly"
648 # Example from https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md
650 cat << EOF > StandaloneFuzzTargetMain.c
655 extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
656 __attribute__((weak)) extern int LLVMFuzzerInitialize(int *argc, char ***argv);
657 int main(int argc, char **argv) {
658 fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
659 if (LLVMFuzzerInitialize)
660 LLVMFuzzerInitialize(&argc, &argv);
661 for (int i = 1; i < argc; i++) {
662 fprintf(stderr, "Running: %s\n", argv[i]);
663 FILE *f = fopen(argv[i], "r");
665 fseek(f, 0, SEEK_END);
666 size_t len = ftell(f);
667 fseek(f, 0, SEEK_SET);
668 unsigned char *buf = (unsigned char*)malloc(len);
669 size_t n_read = fread(buf, 1, len, f);
671 assert(n_read == len);
672 LLVMFuzzerTestOneInput(buf, len);
674 fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
679 cat << EOF > fuzz_me.cc
683 bool FuzzMe(const uint8_t *Data, size_t DataSize) {
684 return DataSize >= 3 &&
691 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
696 clang-
$VERSION -fprofile-instr-generate -fcoverage-mapping fuzz_me.cc StandaloneFuzzTargetMain.c
701 .
/a.out CORPUS
/* &> /dev
/null
702 if ! .
/a.out CORPUS
/* 2>&1 |
grep -q "running 1 inputs"; then
703 echo "Coverage fuzzing failed"
706 llvm-profdata-
$VERSION merge
-sparse *.profraw
-o default.profdata
707 llvm-cov-
$VERSION show a.out
-instr-profile=default.profdata
-name=FuzzMe
&> foo.log
708 if ! grep -q "return DataSize >= 3" foo.log
; then
709 echo "llvm-cov didn't show the expected output in fuzzing"
712 echo -n FUZA
> CORPUS
/FUZA
&& .
/a.out CORPUS
/* &> /dev
/null
713 llvm-profdata-
$VERSION merge
-sparse *.profraw
-o default.profdata
714 llvm-cov-
$VERSION show a.out
-instr-profile=default.profdata
-name=FuzzMe
&> foo.log
715 if ! grep -q "Data\[3\] == 'Z';" foo.log
; then
716 echo "llvm-cov didn't show the expected output in fuzzing"
719 rm -rf CORPUS fuzz_me.cc StandaloneFuzzTargetMain.c
721 echo "Testing sanitizers ..."
723 echo '#include <stdlib.h>
725 char *x = (char*)malloc(10 * sizeof(char*));
730 clang-
$VERSION -o foo
-fsanitize=address
-O1 -fno-omit-frame-pointer -g foo.c
731 if ! .
/foo
2>&1 |
grep -q heap-use-after-free
; then
732 echo "sanitize=address is failing"
739 int main(int argc, char **argv)
741 printf("Hello world!\n");
745 # segfaults on 32bit with "-lc" library (also 6.0 does segfault)
746 clang-
$VERSION -fsanitize=address foo.c
-o foo
-lc
747 .
/foo
&> /dev
/null || true
755 void *Thread1(void *x) {
760 void *Thread2(void *x) {
767 pthread_create(&t[0], NULL, Thread1, NULL);
768 pthread_create(&t[1], NULL, Thread2, NULL);
769 pthread_join(t[0], NULL);
770 pthread_join(t[1], NULL);
773 clang-
$VERSION -o foo
-fsanitize=thread
-g -O1 foo.c
774 if ! strings .
/foo
2>&1 |
grep -q "tsan"; then
775 echo "binary doesn't contain tsan code"
779 if ! .
/foo
2>&1 |
grep -q "data race"; then
780 echo "sanitize=address is failing"
789 template <typename, typename> using b = a;
791 template <typename d> using e = b<a, d>;
797 struct : g::c { int i; };
802 template <typename> void __attribute__((noreturn)) j();
807 clang
++-$VERSION -std=c
++14 -O3 -fsanitize=address
-fsanitize=undefined
-c foo.cpp
-fno-crash-diagnostics
810 # fails on 32 bit, seems a real BUG in the package, using 64bit static libs?
811 LANG
=C clang-
$VERSION -fsanitize=fuzzer test_fuzzer.cc
&> foo.log || true
812 if ! grep "No such file or directory" foo.log
; then
813 # This isn't failing on 64, so, look at the results
814 if ! .
/a.out
2>&1 |
grep -q -E "(Test unit written|PreferSmall)"; then
815 echo "fuzzer. Output:"
817 if [ $DEB_HOST_ARCH != "arm64" -a $DEB_HOST_ARCH != "ppc64el" ]; then
818 # Don't fail on arm64 and ppc64el
829 clang-
$VERSION -g -o bar foo.c
831 # ABI issue between gcc & clang with clang 7
832 # https://bugs.llvm.org/show_bug.cgi?id=39427
833 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=913271
834 if test $VERSION -eq 7; then
836 #include <llvm/ADT/ArrayRef.h>
837 #include <llvm/ADT/Optional.h>
838 namespace llvm { class Constant{}; class Type; class Value; }
839 extern llvm::Constant* bar (llvm::Type*, llvm::Constant*, llvm::ArrayRef<llvm::Value*>, bool, llvm::Optional<unsigned> o, llvm::Type*);
841 llvm::Constant* bar (llvm::Type*, llvm::Constant*, llvm::ArrayRef<llvm::Value*>, bool, llvm::Optional<unsigned> o, llvm::Type*)
843 return o.hasValue()?static_cast<llvm::Constant*>(nullptr)+1:nullptr;
847 static llvm::Constant* doConstantRef(llvm::Type* type, llvm::Constant* var, llvm::ArrayRef<llvm::Value*> steps)
849 llvm::Optional<unsigned> inRangeIndex;
850 return bar(type, var, steps, false, inRangeIndex, nullptr);
854 llvm::Constant* var = nullptr;
855 llvm::Value* zero = nullptr;
856 llvm::Value* indexes[2] = {zero, zero};
857 llvm::ArrayRef<llvm::Value*> steps(indexes, 2);
858 auto result = doConstantRef(nullptr, var, steps);
867 FLAGS
="-I/usr/lib/llvm-$VERSION/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -ffunction-sections -fdata-sections -O2 -DNDEBUG -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
869 clang
++-$VERSION -c -o part1.o foo.cpp
$FLAGS
870 if test -f /usr
/bin
/g
++; then
871 g
++ -c -o part2.o
-DPART2 foo.cpp
$FLAGS
872 clang
++-$VERSION -o foo part1.o part2.o
$FLAGS
878 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libomp.so
; then
879 echo "Install libomp-$VERSION-dev";
891 printf("thread %d\n", omp_get_thread_num());
894 clang-
$VERSION foo.c
-fopenmp -o o
897 if test ! -f /usr
/lib
/llvm-
$VERSION/include
/c
++/v
1/vector
; then
898 echo "Install libc++-$VERSION-dev";
902 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libc
++abi.so
; then
903 echo "Install libc++abi-$VERSION-dev";
916 tab.push_back("the");
917 tab.push_back("world");
918 tab.insert(tab.begin(), "Hello");
920 for(vector<string>::iterator it=tab.begin(); it!=tab.end(); ++it)
926 clang
++-$VERSION -stdlib=libc
++ foo.cpp
-o o
927 if ! ldd o
2>&1|
grep -q libc
++.so
.1; then
928 echo "not linked against libc++.so.1"
931 if ! ldd o
2>&1|
grep -q libc
++abi.so
.1; then
932 echo "not linked against libc++abi.so.1"
937 clang
++-$VERSION -std=c
++11 -stdlib=libc
++ foo.cpp
-o o
941 echo '#include <iostream>
942 int main() {}' | clang
++-$VERSION -std=c
++1z
-x c
++ -stdlib=libc
++ -
944 if test ! -f /usr
/lib
/llvm-
$VERSION/include
/cxxabi.h
; then
945 echo "Install libc++abi-$VERSION-dev";
949 # Force the usage of libc++abi
950 clang
++-$VERSION -stdlib=libc
++ -lc++abi foo.cpp
-o o
952 if ! ldd o
2>&1|
grep -q libc
++abi.so
.1; then
953 echo "not linked against libc++abi.so.1"
957 # Use the libc++abi and uses the libstc++ headers
958 clang
++-$VERSION -lc++abi foo.cpp
-o o
960 if ! ldd o
2>&1|
grep -q libstdc
++.so.
; then
961 echo "not linked against libstdc++"
967 #include <filesystem>
968 #include <type_traits>
969 using namespace std::filesystem;
971 static_assert(std::is_same<
973 std::filesystem::path
976 clang
++-$VERSION -std=c
++17 -stdlib=libc
++ foo.cpp
-o o
990 std::cout << z << std::endl;
998 clang
++-$VERSION -stdlib=libc
++ -Wall -Werror foo.cpp
-o foo
1001 # Bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=914201
1011 clang-
$VERSION -Wconversion -Werror foo.c
&> /dev
/null || true
1013 if test -f /usr
/bin
/g
++; then
1014 g
++ -nostdinc++ -I/usr
/lib
/llvm-
$VERSION/bin
/..
/include
/c
++/v
1/ -L/usr
/lib
/llvm-
$VERSION/lib
/ \
1015 foo.cpp
-nodefaultlibs -std=c
++17 -lc++ -lc++abi
-lm -lc -lgcc_s -lgcc|| true
1020 if test ! -f /usr
/lib
/llvm-
$VERSION/include
/polly
/LinkAllPasses.h
; then
1021 echo "Install libclang-common-$VERSION-dev for polly";
1025 echo "Testing polly (libclang-common-$VERSION-dev) ..."
1037 for (i = 0; i < N; i++) {
1038 for (j = 0; j < N; j++) {
1039 A[i][j] = (1+(i*j)%1024)/2.0;
1040 B[i][j] = (1+(i*j)%1024)/2.0;
1048 double t_start, t_end;
1050 for (i = 0; i < N; i++) {
1051 for (j = 0; j < N; j++) {
1053 for (k = 0; k < N; k++)
1054 C[i][j] = C[i][j] + A[i][k] * B[k][j];
1060 clang-
$VERSION -O3 -mllvm -polly -mllvm -polly-parallel -lgomp foo.c
1061 # Comment because of https://bugs.llvm.org/show_bug.cgi?id=43164
1062 #clang-$VERSION -O3 -mllvm -polly -mllvm -lgomp -polly-parallel foo.c
1063 clang-
$VERSION -O3 -mllvm -polly -mllvm -polly-vectorizer=stripmine foo.c
1064 clang-
$VERSION -S -fsave-optimization-record -emit-llvm foo.c
-o matmul.s
1065 opt-
$VERSION -S -polly-canonicalize matmul.s
> matmul.preopt.ll
> /dev
/null
1066 opt-
$VERSION -basicaa -polly-ast -analyze -q matmul.preopt.ll
-polly-process-unprofitable > /dev
/null
1067 if test ! -f /usr
/lib
/llvm-
$VERSION/share
/opt-viewer
/opt-viewer.py
; then
1068 echo "Install llvm-$VERSION-tools"
1071 /usr
/lib
/llvm-
$VERSION/share
/opt-viewer
/opt-viewer.py
-source-dir . matmul.opt.yaml
-o .
/output
> /dev
/null
1073 if ! grep -q "not inlined into" output
/foo.c.html
2>&1; then
1074 echo "Could not find the output from polly"
1079 int foo(int x, int y) __attribute__((always_inline));
1080 int foo(int x, int y) { return x + y; }
1081 int bar(int j) { return foo(j, j - 2); }" > foo.cc
1082 clang-
$VERSION -O2 -Rpass=inline foo.cc
-c &> foo.log
1083 if ! grep -q "cost=always" foo.log
; then
1093 for (i = 0; i < 100; i++)
1097 clang
++-$VERSION -O2 -fprofile-instr-generate foo.cc
-o foo
1098 LLVM_PROFILE_FILE
="foo-%p.profraw" .
/foo
1099 llvm-profdata-
$VERSION merge
-output=foo.profdata foo-
*.profraw
1100 clang
++-$VERSION -O2 -fprofile-instr-use=foo.profdata foo.cc
-o foo
1102 # https://bugs.llvm.org/show_bug.cgi?id=44870
1104 #include <clang/CodeGen/BackendUtil.h>
1106 using namespace clang;
1109 DiagnosticsEngine* diags;
1110 HeaderSearchOptions* hsOpts;
1111 CodeGenOptions* cgOpts;
1112 TargetOptions* tOpts;
1114 llvm::DataLayout* tDesc;
1116 BackendAction* action;
1117 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
1119 EmitBackendOutput(*diags, *hsOpts, *cgOpts, *tOpts, *lOpts, *tDesc, m, *action, std::move(AsmOutStream));
1122 clang
++-$VERSION foo.cpp
-o test -lclangBasic -lclangCodeGen -lclangDriver -lclangFrontend -lclangFrontendTool -lclangCodeGen -lclangRewriteFrontend -lclangARCMigrate -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangCrossTU -lclangIndex -lclangFrontend -lclangDriver -lclangParse -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangFormat -lclangToolingInclusions -lclangToolingCore -lclangRewrite -lclangASTMatchers -lclangAST -lclangLex -lclangBasic -ldl /usr
/lib
/llvm-
$VERSION/lib
/libLLVM-
$VERSION.so
-lclangCodeGen -lclangDriver -lclangFrontend -lclangFrontendTool -lclangRewriteFrontend -lclangARCMigrate -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangCrossTU -lclangIndex -lclangParse -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangFormat -lclangToolingInclusions -lclangToolingCore -lclangRewrite -lclangASTMatchers -lclangAST -lclangLex -ldl -I /usr
/lib
/llvm-
$VERSION/include
/ -L/usr
/lib
/llvm-
$VERSION/lib
/ -lPolly -lPollyPPCG -lPollyISL
1125 if test ! -f /usr
/bin
/lldb-
$VERSION; then
1126 echo "Install lldb-$VERSION";
1133 quit" > lldb-cmd.txt
1135 echo "Testing lldb-$VERSION ..."
1137 lldb-
$VERSION -s lldb-cmd.txt bar
&> foo.log
1139 if dpkg
-l|
grep -q clang-
$VERSION-dbgsym; then
1140 # Testing if clang dbg symbol are here
1141 lldb-
$VERSION -s lldb-cmd.txt clang-
$VERSION &> foo.log
1142 if ! grep "main at driver.cpp" foo.log
; then
1143 echo "Could not find the debug info"
1144 echo "Or the main() of clang isn't in driver.cpp anymore"
1148 echo "clang-$VERSION-dbgsym isn't installed"
1154 { std::vector<int> a;
1158 clang
++-$VERSION -g -o foo foo.cpp
1159 echo 'target create "./foo"
1164 quit' > lldb-cmd.txt
1165 lldb-
$VERSION -s lldb-cmd.txt .
/foo
&> foo.log
1166 if ! grep -q "stop reason = step over" foo.log
; then
1167 echo "Could not find the lldb expected output"
1169 # do not fail on i386, never worked here
1170 if [ $DEB_HOST_ARCH != "i386" ]; then
1175 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libclangToolingInclusions.a
; then
1176 echo "Install libclang-$VERSION-dev";
1180 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=943623
1182 /usr
/bin
/ar x
/usr
/lib
/llvm-
$VERSION/lib
/libclangIndex.a
&> /dev
/null
1185 if grep "LLVM IR bitcode" foo.log
; then
1186 echo "found LLVM IR bitcode in the libclangIndex.a file"
1187 echo "Should be elf"
1191 echo "Testing cmake build ..."
1193 if grep -q lit-cpuid
/usr
/lib
/llvm-
$VERSION/lib
/cmake
/llvm
/LLVMExports
*.cmake
; then
1194 echo "LLVMExports*.cmake should not have lit-cpuid"
1195 echo "it introduces a dependency between llvm-9 => lldb"
1199 rm -rf cmaketest
&& mkdir cmaketest
1200 cat > cmaketest
/CMakeLists.txt
<<EOF
1201 cmake_minimum_required(VERSION 2.8.12)
1202 project(SanityCheck)
1203 find_package(LLVM $VERSION REQUIRED CONFIG)
1204 message(STATUS "LLVM_CMAKE_DIR: \${LLVM_CMAKE_DIR}")
1205 if(NOT EXISTS "\${LLVM_TOOLS_BINARY_DIR}/clang")
1206 message(FATAL_ERROR "Invalid LLVM_TOOLS_BINARY_DIR: \${LLVM_TOOLS_BINARY_DIR}")
1208 # TODO add version to ClangConfig.cmake and use $VERSION below
1209 find_package(Clang REQUIRED CONFIG)
1210 find_file(H clang/AST/ASTConsumer.h PATHS \${CLANG_INCLUDE_DIRS} NO_DEFAULT_PATH)
1211 message(STATUS "CLANG_INCLUDE_DIRS: \${CLANG_INCLUDE_DIRS}")
1213 message(FATAL_ERROR "Invalid Clang header path: \${CLANG_INCLUDE_DIRS}")
1216 mkdir cmaketest
/standard cmaketest
/explicit
1217 # "Test: CMake find LLVM and Clang in default path"
1218 (cd cmaketest
/standard
&& CC
=clang-
$VERSION CXX
=clang
++-$VERSION cmake ..
> /dev
/null
)
1219 # "Test: CMake find LLVM and Clang in explicit prefix path"
1220 (cd cmaketest
/explicit
&& CC
=clang-
$VERSION CXX
=clang
++-$VERSION CMAKE_PREFIX_PATH
=/usr
/lib
/llvm-
$VERSION cmake ..
> /dev
/null
)
1223 # Test case for bug #900440
1224 rm -rf cmaketest
&& mkdir cmaketest
1225 cat > cmaketest
/CMakeLists.txt
<<EOF
1226 cmake_minimum_required(VERSION 2.8.12)
1229 find_package(LLVM CONFIG REQUIRED)
1230 find_package(Clang CONFIG REQUIRED)
1232 if(NOT LLVM_VERSION STREQUAL Clang_VERSION)
1233 #message(FATAL_ERROR "LLVM ${LLVM_VERSION} not matching to Clang ${Clang_VERSION}")
1236 mkdir cmaketest
/foo
/
1237 (cd cmaketest
/foo
&& cmake ..
> /dev
/null
)
1243 CLANG
=clang-
$VERSION
1244 #command -v "$CLANG" 1>/dev/null 2>/dev/null || { printf "Usage:\n%s CLANGEXE [ARGS]\n" "$0" 1>&2; exit 1; }
1247 TEMPDIR
=$
(mktemp
-d); trap "rm -rf \"$TEMPDIR\"" 0
1249 echo "Testing all other sanitizers ..."
1251 echo "int main() { return 1; }" > foo.c
1252 # fails to run on i386 with the following error:
1253 #clang: error: unsupported option '-fsanitize=efficiency-working-set' for target 'i686-pc-linux-gnu'
1254 clang-
$VERSION -fsanitize=efficiency-working-set
-o foo foo.c || true
1255 .
/foo
&> /dev
/null || true
1257 cat > "$TEMPDIR/test.c" <<EOF
1262 #if __has_feature(address_sanitizer)
1263 puts("address_sanitizer");
1265 #if __has_feature(thread_sanitizer)
1266 puts("thread_sanitizer");
1268 #if __has_feature(memory_sanitizer)
1269 puts("memory_sanitizer");
1271 #if __has_feature(undefined_sanitizer)
1272 puts("undefined_sanitizer");
1274 #if __has_feature(dataflow_sanitizer)
1275 puts("dataflow_sanitizer");
1277 #if __has_feature(efficiency_sanitizer)
1278 puts("efficiency_sanitizer");
1281 return EXIT_SUCCESS;
1285 F
=$
(clang-
$VERSION --target=x86_64-unknown-linux-gnu
--rtlib=compiler-rt
--print-libgcc-file-name)
1287 echo "Cannot find $F"
1288 echo "TODO check if the exit1 can be put back"
1291 echo "$F is one of the compiler-rt file"
1294 # only for AMD64 for now
1295 # many sanitizers only work on AMD64
1296 # x32 programs need to be enabled in the kernel bootparams for debian
1297 # (https://wiki.debian.org/X32Port)
1299 # SYSTEM should iterate multiple targets (eg. x86_64-unknown-none-gnu for embedded)
1300 # MARCH should iterate the library architectures via flags
1301 # LIB should iterate the different libraries
1302 echo "if it fails, please run"
1303 echo "apt-get install libc6-dev:i386 libgcc-5-dev:i386 libc6-dev-x32 libx32gcc-5-dev libx32gcc-9-dev"
1304 for SYSTEM
in ""; do
1305 for MARCH
in -m64 -m32 -mx32 "-m32 -march=i686"; do
1306 for LIB
in --rtlib=compiler-rt
-fsanitize=address
-fsanitize=thread
-fsanitize=memory
-fsanitize=undefined
-fsanitize=dataflow
; do # -fsanitize=efficiency-working-set; do
1307 if test "$MARCH" == "-m32" -o "$MARCH" == "-mx32"; then
1308 if test $LIB == "-fsanitize=thread" -o $LIB == "-fsanitize=memory" -o $LIB == "-fsanitize=dataflow" -o $LIB == "-fsanitize=address" -o $LIB == "-fsanitize=undefined"; then
1309 echo "Skip $MARCH / $LIB";
1313 if test "$MARCH" == "-m32 -march=i686"; then
1314 if test $LIB == "-fsanitize=memory" -o $LIB == "-fsanitize=thread" -o $LIB == "-fsanitize=dataflow"; then
1315 echo "Skip $MARCH / $LIB";
1319 XARGS
="$SYSTEM $MARCH $LIB"
1320 printf "\nTest: clang %s\n" "$XARGS"
1321 rm -f "$TEMPDIR/test"
1322 "$CLANG" $XARGS -o "$TEMPDIR/test" "$@" "$TEMPDIR/test.c" || true
1323 [ ! -e "$TEMPDIR/test" ] ||
{ "$TEMPDIR/test" ||
printf 'Error\n'; }
1328 echo "If the following fails, try setting an environment variable such as:"
1329 echo "OBJC_INCLUDE_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/include"
1330 echo "libobjc-9-dev should be also installed"
1331 echo "#include <objc/objc.h>" > foo.m
1332 #clang-$VERSION -c foo.m
1334 if test ! -f /usr
/lib
/llvm-
$VERSION/lib
/libclangBasic.a
; then
1335 echo "Install libclang-$VERSION-dev"
1340 rm -f a.out bar crash-
* foo foo.
* lldb-cmd.txt main.
* test_fuzzer.cc foo.
* o
1341 rm -rf output matmul.
* *profraw opt.ll