Quuxplusone / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
https://p1144.godbolt.org/z/jf67zx5hq
Other
1 stars 2 forks source link

CodeGen-emitted diagnostics lack "in instantiation of function template" notes #27

Open Quuxplusone opened 9 months ago

Quuxplusone commented 9 months ago

https://godbolt.org/z/4MGx14osY

struct S {
    constexpr bool operator==(int) const { return false; }
};

template<class T> int f() {
    while (T() == 0) [[likely]] {
        return 0;
    }
}

template int f<S>();
template int f<int>();

Clang correctly diagnoses one warning for f<S> and one warning for f<int>:

<source>:9:1: warning: non-void function does not return a value [-Wreturn-type]
    9 | }
      | ^
<source>:11:14: note: in instantiation of function template specialization 'f<S>' requested here
   11 | template int f<S>();
      |              ^
<source>:6:24: warning: attribute 'likely' has no effect when annotating an infinite loop [-Wignored-attributes]
    6 |     while (T() == 0) [[likely]] {
      |                        ^~~~~~
<source>:6:5: note: annotating the infinite loop here
    6 |     while (T() == 0) [[likely]] {
      |     ^~~~~~~~~~~~~~~~
2 warnings generated.

The -Wreturn-type warning (produced by Sema) helpfully includes a note pointing the user at f<S>. The -Wignored-attributes warning (produced by CodeGen) unhelpfully doesn't include any note pointing the user at f<int>. Presumably that information is difficult to come by, in CodeGen, but it sure would be useful.