Skip to content

Conversation

@davidmrdavid
Copy link
Contributor

Follow up to: #159618

Context

The linked PR ^ introduced a new test to ensure that ASan on Windows no longer instruments catch-parameters. This test used a non-standard constructor of std::exception,one that accepted strings as their input, which somehow passed the PR CI but would fail to compile on mingw with libc++.

This was originally reported by @mstorsjo, in this comment:

This testcase fails to compile in mingw environments, with libc++ as a C++ standard library - https://github.com/mstorsjo/llvm-mingw/actions/runs/18608410056/job/53074081871:

D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:11:32: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception'
   11 | void throwInFunction() { throw std::exception("test2"); }
      |                                ^~~~~~~~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument
   75 |   _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT            = default;
      |                         ^         ~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
   74 |   _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {}
      |                         ^
D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:16:11: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception'
   16 |     throw std::exception("test1");
      |           ^~~~~~~~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument
   75 |   _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT            = default;
      |                         ^         ~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
   74 |   _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {}
      |                         ^
2 errors generated.
Looking at https://en.cppreference.com/w/cpp/error/exception/exception.html, I don't see any std::exception constructor taking a const char* parameter.

from: #159618 (comment)

This PR adjusts the faulty test case to rely on std::runtime_error, which contains a standard constructor accepting a string. This should suffice to make the test pass on mingw. I tested this on godbolt: https://godbolt.org/z/M4hPv5Wvx

@llvmbot
Copy link
Member

llvmbot commented Oct 19, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David Justo (davidmrdavid)

Changes

Follow up to: #159618

Context

The linked PR ^ introduced a new test to ensure that ASan on Windows no longer instruments catch-parameters. This test used a non-standard constructor of std::exception,one that accepted strings as their input, which somehow passed the PR CI but would fail to compile on mingw with libc++.

This was originally reported by @mstorsjo, in this comment:

This testcase fails to compile in mingw environments, with libc++ as a C++ standard library - https://github.com/mstorsjo/llvm-mingw/actions/runs/18608410056/job/53074081871:

D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:11:32: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception'
   11 | void throwInFunction() { throw std::exception("test2"); }
      |                                ^~~~~~~~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument
   75 |   _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT            = default;
      |                         ^         ~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
   74 |   _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {}
      |                         ^
D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:16:11: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception'
   16 |     throw std::exception("test1");
      |           ^~~~~~~~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument
   75 |   _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT            = default;
      |                         ^         ~~~~~~~~~~~~~~~~
C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
   74 |   _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {}
      |                         ^
2 errors generated.
Looking at https://en.cppreference.com/w/cpp/error/exception/exception.html, I don't see any std::exception constructor taking a const char* parameter.

from: #159618 (comment)

This PR adjusts the faulty test case to rely on std::runtime_error, which contains a standard constructor accepting a string. This should suffice to make the test pass on mingw. I tested this on godbolt: https://godbolt.org/z/M4hPv5Wvx


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

1 Files Affected:

  • (modified) compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp (+3-2)
diff --git a/compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp b/compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp
index 6f028147c9049..8d1b9ef17393f 100644
--- a/compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp
@@ -7,13 +7,14 @@
 // This code is based on the repro in https://github.com/google/sanitizers/issues/749
 #include <cstdio>
 #include <exception>
+#include <stdexcept>
 
-void throwInFunction() { throw std::exception("test2"); }
+void throwInFunction() { throw std::runtime_error("test2"); }
 
 int main() {
   // case 1: direct throw
   try {
-    throw std::exception("test1");
+    throw std::runtime_error("test1");
   } catch (const std::exception &ex) {
     puts(ex.what());
     // CHECK: test1

@thurstond
Copy link
Contributor

Thanks for the fix-forward!

Btw, some quirks of LLVM:

  • 'You are allowed to commit patches without approval which you think are obvious. This is clearly a subjective decision — we simply expect you to use good judgement. Examples include: fixing build breakage, reverting obviously broken patches, documentation/comment changes, any other minor changes.'
  • 'we tend to make much heavier use of reverts to keep the tree healthy than some other open source projects, and our norms are a bit different. ... Any time you learn of a serious problem with a change, you should revert it. We strongly encourage “revert to green” as opposed to “fixing forward”. We encourage reverting first, investigating offline, and then reapplying the fixed patch - possibly after another round of review if warranted.'
    (https://llvm.org/docs/DeveloperPolicy.html)

@thurstond thurstond merged commit 52f5683 into llvm:main Oct 19, 2025
14 checks passed
@davidmrdavid
Copy link
Contributor Author

thanks for the info! Next time I'll do a quick revert, and fix later. Got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants