1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515set -o xtrace
16- cd /build_dir/llvm-project
17- rm -rf ./build
18- mkdir build
19-
20- capitalize () {
21- if [ -z " $1 " ]; then
22- return 1
23- fi
24-
25- local first_char rest
26- first_char=$( echo " ${1: 0: 1} " | tr ' [:lower:]' ' [:upper:]' )
27- rest=" ${1: 1} "
28- echo " ${first_char}${rest} "
29- }
16+ set -e
17+ cd build_dir/llvm-project
3018
3119CXX_FLAGS=" "
3220LDFLAGS=" "
3321ADDITIONAL_FLAGS=" "
3422if [ " $STDLIB " == " libcxx" ]; then
35- CXXFLAGS=" -stdlib=libc++ -std=c++23"
36- LDFLAGS=" -lc++"
23+ if [ " $ENABLE_SANITIZER " = " none" ]; then
24+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx"
25+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1"
26+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib"
27+ elif [ " $ENABLE_SANITIZER " = " asan" ]; then
28+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Address"
29+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=address"
30+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=address"
31+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
32+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Thread"
33+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=thread"
34+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=thread"
35+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
36+ cmake -G Ninja -S runtimes -B build-libcxx -DLLVM_ENABLE_RUNTIMES=" libcxx;libcxxabi;libunwind" -DCMAKE_INSTALL_PREFIX=" /build_dir/libcxx" -DLLVM_USE_SANITIZER=" Undefined"
37+ CXXFLAGS=" -std=c++23 -nostdinc++ -isystem /build_dir/libcxx/include/c++/v1 -fsanitize=undefined"
38+ LDFLAGS=" -L/build_dir/libcxx/lib -lc++ -rpath /build_dir/libcxx/lib -fsanitize=undefined"
39+ else
40+ echo unexpected sanitizer: $SANITIZER ;
41+ exit 1
42+ fi
43+ ninja -C build-libcxx install-cxx install-cxxabi install-unwind
3744elif [ " $STDLIB " == " libstdcxx" ]; then
3845 CXXFLAGS=" -std=c++23"
3946 LDFLAGS=" "
4249 exit 1
4350fi
4451
45- if [ ! " ${ENABLE_SANITIZER} " = " none" ]; then
46- ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=$( capitalize ${ENABLE_SANITIZER} ) "
47- fi
48-
49- if [ " ${ENABLE_SANITIZER} " = " undefined" ]; then
50- ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_ENABLE_RTTI=ON"
51- fi
52-
53- if [ " ${ENABLE_SANITIZER} " = " thread" ]; then
52+ if [ " $ENABLE_SANITIZER " = " none" ]; then
53+ echo " Not using a sanitizer"
54+ elif [ " $ENABLE_SANITIZER " = " asan" ]; then
55+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Address"
56+ elif [ " $ENABLE_SANITIZER " = " tsan" ]; then
57+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Thread"
5458 export TSAN_OPTIONS=" report_bugs=0"
59+ elif [ " $ENABLE_SANITIZER " = " ubsan" ]; then
60+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_ENABLE_RTTI=ON"
61+ ADDITIONAL_FLAGS=" ${ADDITIONAL_FLAGS} -DLLVM_USE_SANITIZER=Undefined"
62+ else
63+ echo unexpected sanitizer: $SANITIZER ;
64+ exit 1
5565fi
5666
5767if [ ! -z " ${CXXFLAGS} " ]; then
@@ -62,6 +72,7 @@ if [ ! -z "${LDFLAGS}" ]; then
6272 export LDFLAGS
6373fi
6474
75+
6576cmake -G Ninja -S llvm -B build -DCMAKE_BUILD_TYPE=Release \
6677 -DLLVM_ENABLE_PROJECTS=" mlir" \
6778 -DLLVM_TARGETS_TO_BUILD=Native \
0 commit comments