| Issue |
171005
|
| Summary |
[libscanbuild] analyze-build with CTU enabled fails to handle spaces in compile definitions
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
tonykero
|
LLVM Version: 21.1.0
Steps to reproduce: See Dockerfile attached
With some configure/make based projects, here specifically binutils 2.45.1
When using intercept-build followed by analyze-build with ctu enabled, analyze-builds will fail to execute commands because there is a space in `-DPACKAGE_STRING="zlib 1.1.4"`
Notice here the PACKAGE_STRING is wrongly split in 2 differents arguments: ... '-DPACKAGE_STRING="zlib', '1.1.4"' ....
```subprocess.CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=sarif', '-x', 'c', '-DPACKAGE_NAME="zlib"', '-DPACKAGE_TARNAME="zlib"', '-DPACKAGE_VERSION="1.1.4"'
=> => # , '-DPACKAGE_STRING="zlib', '1.1.4"', '-DPACKAGE_BUGREPORT=""', '-DPACKAGE_URL=""', '-DPACKAGE="zlib"', '-DVERSION="1.1.4"', '-DSTDC_HEADERS=1', '-DHAVE_SYS_TYPES_H=1', '-DHAVE_SYS_STAT_H=1', '-DHAVE
=> => # _STDLIB_H=1', '-DHAVE_STRING_H=1', '-DHAVE_MEMORY_H=1', '-DHAVE_STRINGS_H=1', '-DHAVE_INTTYPES_H=1', '-DHAVE_STDINT_H=1', '-DHAVE_UNISTD_H=1', '-DHAVE_DLFCN_H=1', '-DLT_OBJDIR=".libs/"', '-DHAVE_STDL
=> => # IB_H=1', '-DHAVE_UNISTD_H=1', '-DHAVE_SYS_PARAM_H=1', '-DHAVE_GETPAGESIZE=1', '-DHAVE_MMAP=1', '-DHAVE_MEMCPY=1', '-DHAVE_STRERROR=1', '-DHAVE_UNISTD_H=1', '-I.', '-O2', '/work/repo/zlib/inftrees.c',
=> => # '-fno-color-diagnostics']' returned non-zero exit status 1.
```
Script also fails with:
```
=> => # File "/opt/llvm/lib/libscanbuild/analyze.py", line 691, in map_extdefs
=> => # extdef_ast_list = extdef_map_list_src_to_ast(extdef_src_list)
=> => # File "/opt/llvm/lib/libscanbuild/analyze.py", line 638, in extdef_map_list_src_to_ast
=> => # mangled_name, path = extdef_src_txt.split(" ", 1)
=> => # ValueError: not enough values to unpack (expected 2, got 1)
```
And here is the not-so minimal Dockerfile to reproduce the exact issue.
```Dockerfile
FROM rockylinux/rockylinux:9 AS llvm
ARG VERSION=21.1.0
RUN dnf install -y xz
WORKDIR /tmp
RUN curl -L -o llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/LLVM-${VERSION}-Linux-X64.tar.xz
WORKDIR /opt/llvm
RUN tar -xvf /tmp/llvm.tar.xz --strip-components=1
RUN /bin/bash -O extglob -c 'rm -rf !(bin|lib)'
WORKDIR /opt/llvm/bin
RUN /bin/bash -O extglob -c 'rm -rf !(intercept-build|analyze-build|clang|clang-*)'
WORKDIR /opt/llvm/lib
RUN /bin/bash -O extglob -c 'rm -rf !(libscanbuild|libear|clang)'
FROM rockylinux/rockylinux:9 AS csa
COPY --from=llvm /opt/llvm /opt/llvm
RUN ln -s /opt/llvm/bin/analyze-build /usr/local/bin/analyze-build
RUN ln -s /opt/llvm/bin/intercept-build /usr/local/bin/intercept-build
RUN ln -s /opt/llvm/bin/clang-extdef-mapping /usr/local/bin/clang-extdef-mapping
RUN ln -s /opt/llvm/bin/clang /usr/local/bin/clang
RUN ln -s /opt/llvm/bin/clang-21 /usr/local/bin/clang-21
RUN ln -s /opt/llvm/bin/clang-emit-ast /usr/local/bin/clang-emit-ast
RUN analyze-build --help
RUN intercept-build --help
RUN clang --version
FROM rockylinux/rockylinux:9 AS final
ARG VERSION=2_45_1
RUN dnf install -y git
WORKDIR /work
RUN git clone --filter=tree:0 --single-branch --branch binutils-${VERSION} --depth=1 git://sourceware.org/git/binutils-gdb.git /work/repo
RUN dnf install --enablerepo=devel -y gcc-c++ gmp-devel mpfr-devel texinfo bison flex file
WORKDIR /work/repo
RUN ./configure
COPY --from=csa /opt/llvm /opt/llvm
COPY --from=csa /usr/local/bin /usr/local/bin
RUN intercept-build make -j8
RUN mkdir -p /work/sarif_output
RUN analyze-build -v --ctu --sarif --output /work/sarif_output
```
Note that removing --ctu from the analyze-build command line works perfectly fine.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs