Commit 1b307622 authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch...

Merge branch 'float-1537-make-clang-the-default-compiler-in-makefile-and-cmakelists-txt' into 'main'

Resolve "Make Clang the default compiler in Makefile and CMakeLists.txt"

See merge request !2550
parents 6366bfab 52bc91be
Loading
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -16,12 +16,6 @@ Link to test pipeline: XXX

### Ways to reproduce

Activate [origin-tracking](https://clang.llvm.org/docs/MemorySanitizer.html#msan-origins) (more detailed traceback about where the undefined value came from) by appending
```
 -fsanitize-memory-track-origins
```
in the `Makefile` at lines 71 and 72. Note that this may increase runtime heavily.

Using the [scripts](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/Software-development/pyivastest-howto#how-to-reproduce-tests):
<!--- check correct sanitizer type -->
<!--- add error pattern if needed -->
@@ -30,11 +24,12 @@ Using the [scripts](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/
```
python3 scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m MODE -p /path/to/my/local/ci_linux_ltv_local.json
```

or directly:

```
make clean
make -j CLANG=1
make -j CLANG=1 MSAN_TRACK_ORIGINS=1
./IVAS_cod ...
networkSimulator_g192 dly_profile.dat bit bit_err trace_dump 1
./IVAS_dec ...
+12 −5
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ set(CMAKE_C_STANDARD 99)
if(UNIX)
  set(TARGET_PLATFORM ""  CACHE STRING "i686 / x86_64")
  set(CLANG           ""  CACHE STRING "1=msan / 2=asan / 3=usan")
  set(GCOV            OFF CACHE BOOL   "enable GCOV")
  set(MSAN_TRACK_ORIGINS OFF CACHE BOOL "enable origin tracking for Clang MSAN")
  set(COVERAGE            OFF CACHE BOOL   "enable coverage instrumentation")
  set(STRIP           OFF CACHE BOOL   "enable STRIP")

  if(NOT CMAKE_BUILD_TYPE)
@@ -62,13 +63,19 @@ if(UNIX)
  # to be uncommented in CI
  # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")

  # set C compiler
  find_program(cc NAMES clang-18 clang REQUIRED)
  set(CMAKE_C_COMPILER "${cc}" CACHE STRING "")

  # CLANG
  if(CLANG)
    find_program(clangBin NAMES /home/amm-archiv/soft/Linux/clang/current/bin/clang clang REQUIRED)
    set(CMAKE_C_COMPILER "${clangBin}" CACHE STRING "")
    if("${CLANG}" MATCHES "1" OR "${CLANG}" MATCHES "msan")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory")
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory")
      if(MSAN_TRACK_ORIGINS)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins")
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize-memory-track-origins")
      endif()
    elseif("${CLANG}" MATCHES "2" OR "${CLANG}" MATCHES "asan")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
@@ -89,8 +96,8 @@ if(UNIX)
      message(FATAL_ERROR "Unknown CLANG setting: ${CLANG}")
    endif()
  endif()
  # GCOV
  if(GCOV)
  # COVERAGE
  if(COVERAGE)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
  endif()
+24 −11
Original line number Diff line number Diff line
@@ -31,9 +31,8 @@ LIB_LIBISAR ?= libisar.a
LIB_LC3PLUS  	?= liblc3plus.a
LIB_LIBUTIL  	?= libivasutil.a


# Default tool settings
CC        ?= gcc
CC        ?= cc
RM        ?= rm -f
AR        ?= ar

@@ -63,30 +62,44 @@ endif
# C compiler flags
CFLAGS   += -std=c99 -pedantic -Wcast-qual -Wall -W -Wextra -Wno-long-long     \
            -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes  \
            -Wno-implicit-fallthrough -ffp-contract=off
            -Werror-implicit-function-declaration \
            -Wno-implicit-fallthrough -ffp-contract=off \
            -Winit-self -Wunused-but-set-variable
# to be uncommented in CI
# CFLAGS += -Werror

# libs to link
LDLIBS   += -lm

# Clang sanitizer compiler options
CCCLANG = clang
ifeq "$(CLANG)" "0"
CC       = $(CCCLANG)
# check if clang is available on system and use it if it is there
CLANG_EXISTS := $(shell which clang)

ifneq "$(CLANG_EXISTS)" ""
CC = clang
else
$(warning clang compiler not found - falling back to cc)
endif

# Clang sanitizer compiler options
ifeq "$(CLANG)" "1"
CC       = $(CCCLANG)
CC       = clang
CFLAGS  += -fsanitize=memory
LDFLAGS += -fsanitize=memory

# can be set in call to make, e.g. "make CLANG=1 MSAN_TRACK_ORIGINS=1"
ifeq "$(MSAN_TRACK_ORIGINS)" "1"
CFLAGS  += -fsanitize-memory-track-origins
LDFLAGS += -fsanitize-memory-track-origins
endif

endif
ifeq "$(CLANG)" "2"
CC       = $(CCCLANG)
CC       = clang
CFLAGS  += -fsanitize=address
LDFLAGS += -fsanitize=address
endif
ifeq "$(CLANG)" "3"
CC       = $(CCCLANG) 
CC       = clang
# NOTE: keep in sync with list in CMakeLists.txt
usan_checks = undefined,float-divide-by-zero,implicit-conversion,local-bounds
CFLAGS  += -fsanitize=$(usan_checks) 
@@ -105,7 +118,7 @@ CFLAGS += -g3
LDFLAGS  += -g3
endif

ifeq "$(GCOV)" "1"
ifeq "$(COVERAGE)" "1"
CFLAGS  += -fprofile-arcs -ftest-coverage -fprofile-update=atomic
LDFLAGS += -fprofile-arcs -ftest-coverage -fprofile-update=atomic
endif
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ fi
# CI linux container would do this, can stay commented if clang (v13) is in your path
#PATH=$PATH:/usr/lib/llvm-13/bin
make clean
make CLANG=1 -j
make CLANG=1 -j MSAN_TRACK_ORIGINS=1
make clean
make CLANG=2 -j
make clean