[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 3 18:45:14 PDT 2022
lebedev.ri created this revision.
lebedev.ri added reviewers: rjmccall, morehouse, aaron.ballman, dvyukov, MaskRay, vsk, Sanitizers.
lebedev.ri added a project: LLVM.
Herald added subscribers: Enna1, StephenFan, dberris.
Herald added a project: All.
lebedev.ri requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added a subscriber: cfe-commits.
I've stumbled into this in https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52989&q=label%3AProj-librawspeed
which manifested as an obscure leak, and originated from a seemingly simple refactoring:
https://github.com/darktable-org/rawspeed/commit/1fd09b9cffbddc65753eb523f7ba5528d35fe34d#diff-c832cc8366d36ca1165ecef7f4a256a2643ec09c4405a1238222a4529df619a1R172-R174
Reduced, this looked like:
#include <vector>
std::vector<int> handle() {
std::vector<int> v(42, 42); // this somehow leaks
return v;
}
__attribute__((pure)) // double yikes
std::vector<int> footgun(int argc) {
std::vector<int> v(24, 24);
if(argc != 42)
throw int(0); // yikes
return v;
}
int main(int argc, char* argv[]) {
try {
auto v = handle();
auto v2 = footgun(argc);
} catch(...) {}
return 0;
}
https://godbolt.org/z/zdavdKnfa
Surprisingly, we did not handle it before.
I'm not yet sure if we can pretty-print the actual exception on compiler-rt side.
(I may need to update a couple tests still)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137381
Files:
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CMakeLists.txt
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGenCXX/catch-exception-escape.cpp
compiler-rt/lib/ubsan/ubsan_checks.inc
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
compiler-rt/test/ubsan/TestCases/Misc/exception-escape.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137381.473097.patch
Type: text/x-patch
Size: 26568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221104/c21c713d/attachment-0001.bin>
More information about the cfe-commits
mailing list