Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Workaround dependent source location issues #106925

Merged
merged 3 commits into from
Sep 4, 2024

Conversation

cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Sep 1, 2024

In #78436 we made some SourceLocExpr dependent to
deal with the fact that their value should reflect the name of specialized function - rather than the rtemplate in which they are first used.

However SourceLocExpr are unusual in two ways

  • They don't depend on template arguments
  • They morally depend on the context in which they are used (rather than called from).

It's fair to say that this is quite novels and confuses clang. In particular, in some cases, we used to create dependent SourceLocExpr and never subsequently transform them, leaving dependent objects in instantiated functions types. To work around that we avoid replacing SourceLocExpr when we think they could remain dependent.
It's certainly not perfect but it fixes a number of reported bugs, and seem to only affect scenarios in which the value of the SourceLocExpr does not matter (overload resolution).

Fixes #106428
Fixes #81155
Fixes #80210
Fixes #85373

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 1, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

In #78436 we made some SourceLocExpr dependent to
deal with the fact that their value should reflect the name of specialized function - rather than the rtemplate in which they are first used.

However SourceLocExpr are unusual in two ways

  • They don't depend on template arguments
  • They morally depend on the context in which they are used (rather than called from).

It's fair to say that this is quite novels and confuses clang. In particular, in some cases, we used to create dependent SourceLocExpr and never subsequently transform them, leaving dependent objects in instantiated functions types. To work around that we avoid replacing SourceLocExpr when we think they could remain dependent.
It's certainly not perfect but it fixes a number of reported bugs, and seem to only affect scenarios in which the value of the SourceLocExpr does not matter (overload resolution).

Fixes #106428
Fixes #81155


Full diff: https://github.com/llvm/llvm-project/pull/106925.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExpr.cpp (+17-4)
  • (modified) clang/test/SemaCXX/source_location.cpp (+60)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 95f53dfefbcc52..d80d5fb516bc64 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5441,11 +5441,24 @@ struct EnsureImmediateInvocationInDefaultArgs
 
   // Rewrite to source location to refer to the context in which they are used.
   ExprResult TransformSourceLocExpr(SourceLocExpr *E) {
-    if (E->getParentContext() == SemaRef.CurContext)
+    DeclContext *DC = E->getParentContext();
+    if (DC == SemaRef.CurContext)
       return E;
-    return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
-                                             E->getBeginLoc(), E->getEndLoc(),
-                                             SemaRef.CurContext);
+
+    // FIXME: During instantiation, because the rebuild of defaults arguments
+    // is not always done in the context of the template instantiator,
+    // we run the risk of producing a dependent source location
+    // that would never be rebuilt.
+    // This usually happen during overload resolution, or in contexts
+    // where the value of the source location does not matter.
+    // However, we should find a better way to deal with source location
+    // of function template.
+    if (!SemaRef.CurrentInstantiationScope ||
+        !SemaRef.CurContext->isDependentContext() || DC->isDependentContext())
+      DC = SemaRef.CurContext;
+
+    return getDerived().RebuildSourceLocExpr(
+        E->getIdentKind(), E->getType(), E->getBeginLoc(), E->getEndLoc(), DC);
   }
 };
 
diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp
index 6b3610d703e716..34177bfe287fc3 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -929,3 +929,63 @@ void test() {
 }
 
 }
+
+namespace GH106428 {
+
+struct add_fn {
+    template <typename T>
+    constexpr auto operator()(T lhs, T rhs,
+                              const std::source_location loc = std::source_location::current())
+        const -> T
+    {
+        return lhs + rhs;
+    }
+};
+
+
+template <class _Fp, class... _Args>
+decltype(_Fp{}(0, 0))
+__invoke(_Fp&& __f);
+
+template<typename T>
+struct type_identity { using type = T; };
+
+template<class Fn>
+struct invoke_result : type_identity<decltype(__invoke(Fn{}))> {};
+
+using i = invoke_result<add_fn>::type;
+static_assert(__is_same(i, int));
+
+}
+
+#if __cplusplus >= 202002L
+
+namespace GH81155 {
+struct buff {
+  buff(buff &, const char * = __builtin_FUNCTION());
+};
+
+template <class Ty>
+Ty declval();
+
+template <class Fx>
+auto Call(buff arg) -> decltype(Fx{}(arg));
+
+template <typename>
+struct F {};
+
+template <class Fx>
+struct InvocableR : F<decltype(Call<Fx>(declval<buff>()))> {
+  static constexpr bool value = false;
+};
+
+template <class Fx, bool = InvocableR<Fx>::value>
+void Help(Fx) {}
+
+void Test() {
+  Help([](buff) {});
+}
+
+}
+
+#endif

@zyn0217
Copy link
Contributor

zyn0217 commented Sep 2, 2024

Does it fix #80210?

EDIT: Tested locally this actually also fixes #80210 and #85373. Can you reference them in the release entry?

In llvm#78436 we made some SourceLocExpr dependent to
deal with the fact that their value should reflect the name of
specialized function - rather than the rtemplate in which they
are first used.

However SourceLocExpr are unusual in two ways
 - They don't depend on template argumente
 - They morally depend on the context in which they are used
   (rather than called from).

It's fair to say that this is quite novels and confuses
clang. In particular, in some cases, we used to create
dependent SourceLocExpr and never subsequently transform them,
leaving dependent objects in instantiated functions types.
To work around that we avoid replacing SourceLocExpr when we think
they could remain dependent.
It's certainly not perfect but it fixes a number of reported bugs,
and seem to only affect scenarios in which the value of the
SourceLocExpr does not matter (overload resolution).

Fixes llvm#106428
Fixes llvm#81155
@cor3ntin
Copy link
Contributor Author

cor3ntin commented Sep 3, 2024

@AaronBallman btw, backporting that would be nice...

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some minor grammatical nits in a comment.

clang/lib/Sema/SemaExpr.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaExpr.cpp Outdated Show resolved Hide resolved
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
// However, we should find a better way to deal with source location
// of function templates.
if (!SemaRef.CurrentInstantiationScope ||
!SemaRef.CurContext->isDependentContext() || DC->isDependentContext())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure the DC is always not a nullptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is always a declaration context (the top one being that of the translation unit)

@cor3ntin cor3ntin merged commit 4bccb01 into llvm:main Sep 4, 2024
9 checks passed
@cor3ntin cor3ntin deleted the corentin/fix_source_loc branch September 4, 2024 08:03
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 4, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux running on sanitizer-buildbot1 while building clang at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3457

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-Test
[382/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[383/384] Generating Msan-x86_64-Test
[383/384] Running compiler_rt regression tests
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10229 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
TIMEOUT: SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c (10229 of 10229)
******************** TEST 'SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c' FAILED ********************
Exit Code: -9
Timeout: Reached timeout of 900 seconds

Command Output (stderr):
--
RUN: at line 1: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -fsanitize-hwaddress-experimental-aliasing  -m64 -funwind-tables  -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp && env HWASAN_OPTIONS=die_after_fork=0  /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -fsanitize-hwaddress-experimental-aliasing -m64 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ env HWASAN_OPTIONS=die_after_fork=0 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
==15509==ERROR: HWAddressSanitizer: tag-mismatch on address 0x4816000000b0 at pc 0x57d8745cbb17
READ of size 160 at 0x4816000000b0 tags: 07/01(65) (ptr/mem) in thread T2
==15398==ERROR: HWAddressSanitizer: tag-mismatch on address 0x481600000000 at pc 0x57d8745cbe37
READ of size 160 at 0x481600000000 tags: 01/02(65) (ptr/mem) in thread T1

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
900.36s: SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c
194.84s: libFuzzer-x86_64-default-Linux :: out-of-process-fuzz.test
188.54s: libFuzzer-x86_64-libcxx-Linux :: out-of-process-fuzz.test
184.71s: libFuzzer-x86_64-static-libcxx-Linux :: out-of-process-fuzz.test
44.46s: libFuzzer-i386-default-Linux :: value-profile-switch.test
44.23s: libFuzzer-i386-static-libcxx-Linux :: fork.test
42.53s: ThreadSanitizer-x86_64 :: bench_threads.cpp
42.11s: libFuzzer-i386-default-Linux :: fork_corpus_groups.test
41.60s: libFuzzer-x86_64-static-libcxx-Linux :: fork.test
41.45s: libFuzzer-x86_64-static-libcxx-Linux :: fork_corpus_groups.test
41.44s: libFuzzer-i386-static-libcxx-Linux :: fork_corpus_groups.test
40.89s: libFuzzer-x86_64-default-Linux :: fork_corpus_groups.test
40.71s: libFuzzer-i386-libcxx-Linux :: fork.test
40.68s: libFuzzer-i386-libcxx-Linux :: value-profile-switch.test
40.65s: libFuzzer-x86_64-default-Linux :: fork.test
40.54s: libFuzzer-i386-default-Linux :: fork.test
40.13s: libFuzzer-x86_64-libcxx-Linux :: fork_corpus_groups.test
40.07s: libFuzzer-i386-libcxx-Linux :: fork_corpus_groups.test
39.68s: libFuzzer-x86_64-libcxx-Linux :: fork.test
Step 9 (test compiler-rt symbolizer) failure: test compiler-rt symbolizer (failure)
...
[379/384] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[380/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[381/384] Generating Msan-x86_64-with-call-Test
[382/384] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[383/384] Generating Msan-x86_64-Test
[383/384] Running compiler_rt regression tests
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10229 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
TIMEOUT: SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c (10229 of 10229)
******************** TEST 'SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c' FAILED ********************
Exit Code: -9
Timeout: Reached timeout of 900 seconds

Command Output (stderr):
--
RUN: at line 1: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -fsanitize-hwaddress-experimental-aliasing  -m64 -funwind-tables  -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp && env HWASAN_OPTIONS=die_after_fork=0  /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -fsanitize-hwaddress-experimental-aliasing -m64 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O0 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
+ env HWASAN_OPTIONS=die_after_fork=0 /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/hwasan-x86_64-Linux/Posix/Output/fork_threaded.c.tmp
==15509==ERROR: HWAddressSanitizer: tag-mismatch on address 0x4816000000b0 at pc 0x57d8745cbb17
READ of size 160 at 0x4816000000b0 tags: 07/01(65) (ptr/mem) in thread T2
==15398==ERROR: HWAddressSanitizer: tag-mismatch on address 0x481600000000 at pc 0x57d8745cbe37
READ of size 160 at 0x481600000000 tags: 01/02(65) (ptr/mem) in thread T1

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
900.36s: SanitizerCommon-hwasan-x86_64-Linux :: Posix/fork_threaded.c
194.84s: libFuzzer-x86_64-default-Linux :: out-of-process-fuzz.test
188.54s: libFuzzer-x86_64-libcxx-Linux :: out-of-process-fuzz.test
184.71s: libFuzzer-x86_64-static-libcxx-Linux :: out-of-process-fuzz.test
44.46s: libFuzzer-i386-default-Linux :: value-profile-switch.test
44.23s: libFuzzer-i386-static-libcxx-Linux :: fork.test
42.53s: ThreadSanitizer-x86_64 :: bench_threads.cpp
42.11s: libFuzzer-i386-default-Linux :: fork_corpus_groups.test
41.60s: libFuzzer-x86_64-static-libcxx-Linux :: fork.test
41.45s: libFuzzer-x86_64-static-libcxx-Linux :: fork_corpus_groups.test
41.44s: libFuzzer-i386-static-libcxx-Linux :: fork_corpus_groups.test
40.89s: libFuzzer-x86_64-default-Linux :: fork_corpus_groups.test
40.71s: libFuzzer-i386-libcxx-Linux :: fork.test
40.68s: libFuzzer-i386-libcxx-Linux :: value-profile-switch.test
40.65s: libFuzzer-x86_64-default-Linux :: fork.test
40.54s: libFuzzer-i386-default-Linux :: fork.test
40.13s: libFuzzer-x86_64-libcxx-Linux :: fork_corpus_groups.test
40.07s: libFuzzer-i386-libcxx-Linux :: fork_corpus_groups.test
39.68s: libFuzzer-x86_64-libcxx-Linux :: fork.test
Step 16 (test standalone compiler-rt) failure: test standalone compiler-rt (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/x86_64-unknown-linux-gnu". This path was found by running ['/home/b/sanitizer-x86_64-linux/build/build_default/bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-nobuiltininc', '-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include', '-idirafter', '/home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include', '-resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build', '-Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux', '-print-runtime-dir'].
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 5948 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80
FAIL: SanitizerCommon-lsan-x86_64-Linux :: Linux/soft_rss_limit_mb_test.cpp (4985 of 5948)
******************** TEST 'SanitizerCommon-lsan-x86_64-Linux :: Linux/soft_rss_limit_mb_test.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=leak  -m64 -funwind-tables -nobuiltininc -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include -idirafter /home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include -resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build -Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux  -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/compiler_rt_build/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m64 -funwind-tables -nobuiltininc -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/include -idirafter /home/b/sanitizer-x86_64-linux/build/build_default/lib/clang/20/include -resource-dir=/home/b/sanitizer-x86_64-linux/build/compiler_rt_build -Wl,-rpath,/home/b/sanitizer-x86_64-linux/build/compiler_rt_build/lib/linux -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -o /home/b/sanitizer-x86_64-linux/build/compiler_rt_build/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
RUN: at line 5: env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1      /home/b/sanitizer-x86_64-linux/build/compiler_rt_build/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp 2>&1 | FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1
+ env LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1 /home/b/sanitizer-x86_64-linux/build/compiler_rt_build/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ FileCheck /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp -check-prefix=CHECK_MAY_RETURN_1
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24: error: CHECK_MAY_RETURN_1: expected string not found in input
// CHECK_MAY_RETURN_1: allocating 512 times
                       ^
<stdin>:52:44: note: scanning from here
Some of the malloc calls returned non-null: 256
                                           ^
<stdin>:52:45: note: possible intended match here
Some of the malloc calls returned non-null: 256
                                            ^

Input file: <stdin>
Check file: /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            .
            .
            .
           47:  [256] 
           48:  [320] 
           49:  [384] 
           50:  [448] 
           51: Some of the malloc calls returned null: 256 
           52: Some of the malloc calls returned non-null: 256 
check:68'0                                                X~~~~ error: no match found
check:68'1                                                 ?    possible intended match

cor3ntin added a commit to cor3ntin/llvm-project that referenced this pull request Sep 4, 2024
In llvm#78436 we made some SourceLocExpr dependent to
deal with the fact that their value should reflect the name of
specialized function - rather than the rtemplate in which they are first
used.

However SourceLocExpr are unusual in two ways
 - They don't depend on template arguments
- They morally depend on the context in which they are used (rather than
called from).

It's fair to say that this is quite novels and confuses clang. In
particular, in some cases, we used to create dependent SourceLocExpr and
never subsequently transform them, leaving dependent objects in
instantiated functions types. To work around that we avoid replacing
SourceLocExpr when we think they could remain dependent.
It's certainly not perfect but it fixes a number of reported bugs, and
seem to only affect scenarios in which the value of the SourceLocExpr
does not matter (overload resolution).

Fixes llvm#106428
Fixes llvm#81155
Fixes llvm#80210
Fixes llvm#85373

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
tru pushed a commit to cor3ntin/llvm-project that referenced this pull request Sep 10, 2024
In llvm#78436 we made some SourceLocExpr dependent to
deal with the fact that their value should reflect the name of
specialized function - rather than the rtemplate in which they are first
used.

However SourceLocExpr are unusual in two ways
 - They don't depend on template arguments
- They morally depend on the context in which they are used (rather than
called from).

It's fair to say that this is quite novels and confuses clang. In
particular, in some cases, we used to create dependent SourceLocExpr and
never subsequently transform them, leaving dependent objects in
instantiated functions types. To work around that we avoid replacing
SourceLocExpr when we think they could remain dependent.
It's certainly not perfect but it fixes a number of reported bugs, and
seem to only affect scenarios in which the value of the SourceLocExpr
does not matter (overload resolution).

Fixes llvm#106428
Fixes llvm#81155
Fixes llvm#80210
Fixes llvm#85373

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
6 participants