diff --git a/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C b/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C
new file mode 100644
index 00000000000..544bf0396b8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/noncall-this-method-1.C
@@ -0,0 +1,25 @@
+// PR tree-optimization/127183
+// { dg-do compile }
+// { dg-options "-O2 -fnon-call-exceptions -fdump-tree-optimized" }
+
+struct s1
+{
+    int f();
+    int a;
+};
+
+int s1::f()
+{
+    try {
+      this->a = 1;
+    }catch(...)
+    {
+        __builtin_trap ();
+    }
+    return 0;
+}
+
+// An write access to this should be still considered as trapping
+// and an throwable for non-call exceptions.
+
+// { dg-final { scan-tree-dump "__builtin_trap " "optimized" } } */
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 2d2d391f0a9..d2c2f3b3157 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2118,7 +2118,7 @@ lower_eh_constructs_2 (struct leh_state *state, gimple_stmt_iterator *gsi)
       if (stmt_could_throw_p (cfun, stmt)
 	  && gimple_has_lhs (stmt)
 	  && gimple_stmt_may_fallthru (stmt)
-	  && !tree_could_throw_p (gimple_get_lhs (stmt))
+	  && !lhs_could_trap_p (gimple_get_lhs (stmt))
 	  && is_gimple_reg_type (TREE_TYPE (gimple_get_lhs (stmt))))
 	{
 	  tree lhs = gimple_get_lhs (stmt);
@@ -3057,7 +3057,7 @@ stmt_could_throw_1_p (gassign *stmt)
     }
 
   /* First check the LHS.  */
-  if (tree_could_trap_p (gimple_assign_lhs (stmt)))
+  if (tree_could_trap_1 (gimple_assign_lhs (stmt), true))
     return true;
 
   /* Check if the main expression may trap.  */
@@ -3144,7 +3144,7 @@ tree_could_throw_p (tree t)
   if (TREE_CODE (t) == MODIFY_EXPR)
     {
       if (cfun->can_throw_non_call_exceptions
-          && tree_could_trap_p (TREE_OPERAND (t, 0)))
+	  && tree_could_trap_1 (TREE_OPERAND (t, 0), true))
         return true;
       t = TREE_OPERAND (t, 1);
     }
