summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-27 07:32:15 +0000
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-27 07:32:15 +0000
commita92cfd5bc3e37e855df1414875ac13c18ea3133f (patch)
tree98b4d6b1187515b5a9a82b3c8a4fc13b1bffa2ed
parentd7a0bf41601ea933d5732c9604326678a80cfd66 (diff)
downloadgcc-a92cfd5bc3e37e855df1414875ac13c18ea3133f.tar.gz
Backport r249833
2017-07-27 Martin Liska <mliska@suse.cz> Backport from mainline 2017-06-30 Martin Liska <mliska@suse.cz> PR sanitizer/81021 * tree-eh.c (lower_resx): Call BUILT_IN_ASAN_HANDLE_NO_RETURN before BUILT_IN_UNWIND_RESUME when ASAN is used. 2017-07-27 Martin Liska <mliska@suse.cz> Backport from mainline 2017-06-30 Martin Liska <mliska@suse.cz> PR sanitizer/81021 * g++.dg/asan/pr81021.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@250604 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/asan/pr81021.C33
-rw-r--r--gcc/tree-eh.c15
4 files changed, 65 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f57ae1eac9a..979e4456afe 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,15 @@
2017-07-27 Martin Liska <mliska@suse.cz>
Backport from mainline
+ 2017-06-30 Martin Liska <mliska@suse.cz>
+
+ PR sanitizer/81021
+ * tree-eh.c (lower_resx): Call BUILT_IN_ASAN_HANDLE_NO_RETURN
+ before BUILT_IN_UNWIND_RESUME when ASAN is used.
+
+2017-07-27 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
2017-06-28 Martin Liska <mliska@suse.cz>
PR sanitizer/81224
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 15dd9a66284..fc57e369242 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,14 @@
2017-07-27 Martin Liska <mliska@suse.cz>
Backport from mainline
+ 2017-06-30 Martin Liska <mliska@suse.cz>
+
+ PR sanitizer/81021
+ * g++.dg/asan/pr81021.C: New test.
+
+2017-07-27 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
2017-06-28 Martin Liska <mliska@suse.cz>
PR sanitizer/81224
diff --git a/gcc/testsuite/g++.dg/asan/pr81021.C b/gcc/testsuite/g++.dg/asan/pr81021.C
new file mode 100644
index 00000000000..4904f19bf84
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr81021.C
@@ -0,0 +1,33 @@
+// { dg-do run }
+
+#include <string>
+
+struct ConfigFile {
+ ConfigFile(std::string filename, std::string delimiter) { throw "error"; }
+ ConfigFile(std::string filename) {}
+};
+
+struct Configuration {
+ ConfigFile _configFile;
+
+ Configuration(const std::string &root, const char *baseName)
+ : _configFile(root + baseName, "=") { }
+ Configuration(const std::string &root, const char *a, const char *b)
+ : _configFile(root + a + b) { }
+};
+
+
+void test() {
+ std::string root("etc");
+ try {
+ Configuration config(root, "notthere");
+ }
+ catch (...) {
+ // exception is thrown, caught here and ignored...
+ }
+ Configuration config(root, "a", "b"); // ASAN error during constructor here
+}
+
+int main(int argc, const char *argv[]) {
+ test();
+}
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index fc016d795b7..ad50b32220e 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see
#include "langhooks.h"
#include "cfgloop.h"
#include "gimple-low.h"
+#include "asan.h"
/* In some instances a tree and a gimple need to be stored in a same table,
i.e. in hash tables. This is a structure to do this. */
@@ -3304,6 +3305,20 @@ lower_resx (basic_block bb, gresx *stmt,
gimple_call_set_lhs (x, var);
gsi_insert_before (&gsi, x, GSI_SAME_STMT);
+ /* When exception handling is delegated to a caller function, we
+ have to guarantee that shadow memory variables living on stack
+ will be cleaner before control is given to a parent function. */
+ if ((flag_sanitize & SANITIZE_ADDRESS) != 0
+ && !lookup_attribute ("no_sanitize_address",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ tree decl
+ = builtin_decl_implicit (BUILT_IN_ASAN_HANDLE_NO_RETURN);
+ gimple *g = gimple_build_call (decl, 0);
+ gimple_set_location (g, gimple_location (stmt));
+ gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+ }
+
fn = builtin_decl_implicit (BUILT_IN_UNWIND_RESUME);
x = gimple_build_call (fn, 1, var);
gsi_insert_before (&gsi, x, GSI_SAME_STMT);