llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.5k stars 11.78k forks source link

[Clang] Regression in 18 from 17: shows deprecation warnings from system headers #76515

Open nabijaczleweli opened 9 months ago

nabijaczleweli commented 9 months ago

Debian clang version 18.0.0 (++20231228112336+9d3fbf97bef3-1~exp1~20231228112400.427) (from http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm) on bookworm with libstdc++-12-dev:amd64 12.2.0-14:

$ make -j25
c++ -g -O3 -pipe -Wall -Wextra -fPIC -fno-math-errno -MD -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -Wno-missing-field-initializers -Wno-string-plus-int -fno-common -flto    -DVOREUTILS_LIBSELINUX  -DVOREUTILS_LIBGMP   -Iinclude/ -DVOREUTILS_VERSION='"b41d9cc8"' -DVOREUTILS_DATE='"December 28, 2023"' -DVOREUTILS_SO='".so"' -DVOREUTILS_LIB_PREFIX='"/home/nabijaczleweli/code/voreutils/out/lib/"'   -include vore-id.h  -std=c++17 -fno-exceptions -fno-rtti -c -o out/obj/cmd/tsort.o cmd/tsort.cpp
In file included from cmd/tsort.cpp:4:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/algorithm:61:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:61:
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:263:8: warning: 'get_temporary_buffer<const std::basic_string_view<char> *>' is deprecated [-Wdeprecated-declarations]
  263 |                 std::get_temporary_buffer<value_type>(_M_original_len));
      |                      ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:4996:15: note: in instantiation of member function 'std::_Temporary_buffer<__gnu_cxx::__normal_iterator<const std::basic_string_view<char> **, std::vector<const std::basic_string_view<char> *>>, const std::basic_string_view<char> *>::_Temporary_buffer' requested here
 4996 |       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
      |               ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:5070:23: note: in instantiation of function template specialization 'std::__stable_sort<__gnu_cxx::__normal_iterator<const std::basic_string_view<char> **, std::vector<const std::basic_string_view<char> *>>, __gnu_cxx::__ops::_Iter_comp_iter<(lambda at cmd/tsort.cpp:79:51)>>' requested here
 5070 |       _GLIBCXX_STD_A::__stable_sort(__first, __last,
      |                       ^
cmd/tsort.cpp:79:7: note: in instantiation of function template specialization 'std::stable_sort<__gnu_cxx::__normal_iterator<const std::basic_string_view<char> **, std::vector<const std::basic_string_view<char> *>>, (lambda at cmd/tsort.cpp:79:51)>' requested here
   79 |         std::stable_sort(std::begin(out), std::end(out), [&](auto lhs, auto rhs) { return tree_cmp(tree, *lhs, *rhs); });
      |              ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:99:5: note: 'get_temporary_buffer<const std::basic_string_view<char> *>' has been explicitly marked deprecated here
   99 |     _GLIBCXX17_DEPRECATED
      |     ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12/bits/c++config.h:119:34: note: expanded from macro '_GLIBCXX17_DEPRECATED'
  119 | # define _GLIBCXX17_DEPRECATED [[__deprecated__]]
      |                                  ^
1 warning generated.

This is a system header; previous Clang didn't show this warning and nor does GCC.

Minimal reproducer:

#include <algorithm>
int main() {
    std::stable_sort((int *)0, (int *)0);
}

yields

$ c++ repro.cpp
In file included from repro.cpp:1:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/algorithm:61:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:61:
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:263:8: warning: 'get_temporary_buffer<int>' is deprecated [-Wdeprecated-declarations]
  263 |                 std::get_temporary_buffer<value_type>(_M_original_len));
      |                      ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:4996:15: note: in instantiation of member function 'std::_Temporary_buffer<int *, int>::_Temporary_buffer' requested here
 4996 |       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
      |               ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:5034:23: note: in instantiation of function template specialization 'std::__stable_sort<int *, __gnu_cxx::__ops::_Iter_less_iter>' requested here
 5034 |       _GLIBCXX_STD_A::__stable_sort(__first, __last,
      |                       ^
repro.cpp:3:7: note: in instantiation of function template specialization 'std::stable_sort<int *>' requested here
    3 |         std::stable_sort((int *)0, (int *)0);
      |              ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:99:5: note: 'get_temporary_buffer<int>' has been explicitly marked deprecated here
   99 |     _GLIBCXX17_DEPRECATED
      |     ^
/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12/bits/c++config.h:119:34: note: expanded from macro '_GLIBCXX17_DEPRECATED'
  119 | # define _GLIBCXX17_DEPRECATED [[__deprecated__]]
      |                                  ^
1 warning generated.

From the dpkg log (

2023-12-06 04:05:50 upgrade clang-18:amd64 1:18~++20231112112638+40671bbdefb6-1~exp1~20231112112751.330 1:18~++20231205112210+b21175258b9a-1~exp1~20231205112231.380
2023-12-28 18:07:13 upgrade clang-18:amd64 1:18~++20231205112210+b21175258b9a-1~exp1~20231205112231.380 1:18~++20231228112336+9d3fbf97bef3-1~exp1~20231228112400.427

) I want to say either 1:18~++20231205112210+b21175258b9a-1~exp1~20231205112231.380 or 1:18~++20231112112638+40671bbdefb6-1~exp1~20231112112751.330 were good (didn't show the warning).

shafik commented 9 months ago

I can't reproduce on godbolt: https://godbolt.org/z/Ke7a65vhh

CC @MaskRay @erichkeane

MaskRay commented 9 months ago

I cannot reproduce the reported issue using clang built from trunk with libstdc++-13-dev on Debian (which provides /usr/include/c++/13/algorithm).

nabijaczleweli commented 9 months ago

13 is sid, I'm on bookworm with libstdc++-12-dev.

Indeed, I can reproduce this in a clean bookworm chroot with clang 18.0.0 (++20240101112328+703e83611cd8-1\~exp1\~20240101112345.435).

simark commented 7 months ago

I hit this while building gdb on a Ubuntu 22.04 system, and this clang (installed from apt.llvm.org):

Ubuntu clang version 19.0.0 (++20240307042122+38a73fb1575f-1~exp1~20240307042240.1542)
$ ccache clang++-18 -x c++    -I. -I/home/smarchi/src/binutils-gdb/gdb -I/home/smarchi/src/binutils-gdb/gdb/config -DLOCALEDIR="\"/usr/share/locale\"" -DHAVE_CONFIG_H -I/home/smarchi/src/binutils-gdb/gdb/../include/opcode -I../bfd -I/home/smarchi/src/binutils-gdb/gdb/../bfd -I/home/smarchi/src/binutils-gdb/gdb/../include -I/home/smarchi/src/binutils-gdb/gdb/../readline/readline/.. -I/home/smarchi/src/binutils-gdb/gdb/../zlib  -I../libdecnumber -I/home/smarchi/src/binutils-gdb/gdb/../libdecnumber  -I/home/smarchi/src/binutils-gdb/gdb/../gnulib/import -I../gnulib/import -I/home/smarchi/src/binutils-gdb/gdb/.. -I.. -I/home/smarchi/src/binutils-gdb/gdb/../libbacktrace/ -I../libbacktrace/ -DTUI=1    -I/usr/include/guile/3.0 -I/usr/include/python3.10 -I/usr/include/python3.10   -I/home/smarchi/src/binutils-gdb/gdb/.. -pthread   -I/opt/rocm/share/pkgconfig/../../include -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-mismatched-tags -Wno-error=deprecated-register -Wsuggest-override -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wmissing-declarations -Wno-vla-cxx-extension -Wmissing-prototypes -Wformat -Wformat-nonliteral -Werror -ferror-limit=6 -g3 -O0 -fcolor-diagnostics   -c -o buildsym.o -MT buildsym.o -MMD -MP -MF ./.deps/buildsym.Tpo /home/smarchi/src/binutils-gdb/gdb/buildsym.c
In file included from /home/smarchi/src/binutils-gdb/gdb/buildsym.c:19:
In file included from /home/smarchi/src/binutils-gdb/gdb/defs.h:26:
In file included from /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:197:
In file included from /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/ptid.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/functional:64:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:61:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:263:8: error: 'get_temporary_buffer<block *>' is deprecated [-Werror,-Wdeprecated-declarations]
  263 |                 std::get_temporary_buffer<value_type>(_M_original_len));
      |                      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:4996:15: note: in instantiation of member function 'std::_Temporary_buffer<__gnu_cxx::__normal_iterator<block **, std::vector<block *>>, block *>::_Temporary_buffer' requested here
 4996 |       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
      |               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:5070:23: note: in instantiation of function template specialization 'std::__stable_sort<__gnu_cxx::__normal_iterator<block **, std::vector<block *>>, __gnu_cxx::__ops::_Iter_comp_iter<(lambda at /home/smarchi/src/binutils-gdb/gdb/buildsym.c:802:4)>>' requested here
 5070 |       _GLIBCXX_STD_A::__stable_sort(__first, __last,
      |                       ^
/home/smarchi/src/binutils-gdb/gdb/buildsym.c:801:12: note: in instantiation of function template specialization 'std::stable_sort<__gnu_cxx::__normal_iterator<block **, std::vector<block *>>, (lambda at /home/smarchi/src/binutils-gdb/gdb/buildsym.c:802:4)>' requested here
  801 |       std::stable_sort (barray.begin (), barray.end (),
      |            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:99:5: note: 'get_temporary_buffer<block *>' has been explicitly marked deprecated here
   99 |     _GLIBCXX17_DEPRECATED
      |     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12/bits/c++config.h:119:34: note: expanded from macro '_GLIBCXX17_DEPRECATED'
  119 | # define _GLIBCXX17_DEPRECATED [[__deprecated__]]
      |                                  ^

I attempted to reproduce the issue in an isolated docker container but I didn't manage so far.

simark commented 7 months ago

Ah ok, I diff the output on clang++ repro.cpp -v between the host and the container and I think I found the missing piece to reproduce. It only happens when I have g++-12 installed, in which case clang picks up libstc++ from gcc 12 (instead of gcc 11, the default system compiler).

Here's a Dockerfile that reproduces the problem:

FROM ubuntu:22.04

RUN apt-get update && \
    apt-get -y full-upgrade && \
    apt-get -y install wget gnupg build-essential

RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" > /etc/apt/sources.list.d/llvm.list
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN apt-get update && \
    apt-get -y install clang

RUN echo "#include <algorithm>\nint main() {    std::stable_sort((int *)0, (int *)0); }" > repro.cpp

# Commenting this makes clang use libstdc++ from g++ 11, and the warning doesn't show up.
RUN apt-get -y install g++-12

RUN clang++ repro.cpp -Werror

If you're unfamiliar with docker: put the above in a file called Dockerfile and run docker build -t repro ..

simark commented 7 months ago

Eh, it's late, I read the thread too fast, I now see in the previous messages that it was already known that libstdc++ from gcc 12 was a key to reproduce. Sorry for the noise.

jabraham17 commented 5 months ago

Noting here that the Chapel project saw this same issue when upgrading our support for LLVM 18, see chapel-lang/chapel#24848 (commit to workaround issue: https://github.com/chapel-lang/chapel/pull/24848/commits/3a212a8ac1fabba6565cf0ca4061e1aea375d289)

joker-eph commented 4 months ago

Here is a preprocessed file 17.cpp.txt

The issue reproduces with clang++ 17.cpp -std=c++17 -Wdeprecated-declarations

MitalAshok commented 1 month ago

Here's a reproducer without libstdc++: https://godbolt.org/z/K7dxd9sW5

Two files:

// system_header.h
#pragma once
#pragma GCC system_header

template<typename T>
[[__deprecated__]]
T* get_temporary_buffer(int) {
  return nullptr;
}

template<typename T>
void stable_sort(T, T) {
  get_temporary_buffer<T>(4);
}
// main.cpp
#include "system_header.h"

int main() {
  stable_sort(0, 0);
}

If stable_sort is not templated, this warning is not emitted. e.g.:

// in system header
template<typename T>
void f() {
  get_temporary_buffer<int>(4);
}

void g() {
  get_temporary_buffer<int>(4);
}

// in main file
int main() {
  f<int>();  // Warning
  g(); // No warning
}
keith commented 1 week ago

I bisected this to https://github.com/llvm/llvm-project/commit/aafad2d214246bae4d53ce3178b11486ebc83890, based on the commit message there it looks like this was intentional?

nabijaczleweli commented 1 week ago

Reads to me like behaviour yes intentional, but this effect not intentional?

keith commented 1 week ago

Maybe @cor3ntin can advise