On Thu, Oct 05, 2017 at 12:31:23PM +0200, Martin Liška wrote: > As discussed 2 days ago on IRC with Jakub and Jonathan, C++ standard says > that having a non-return > function with missing return statement is undefined behavior. We've got > -fsanitize=return check for > that and we can in such case instrument __builtin_unreachable(). This patch > does that. It produces quite > some fallout in test-suite. > > And there's still some fallout: > > FAIL: g++.dg/cpp0x/constexpr-diag3.C -std=c++11 (test for errors, line 7) > FAIL: g++.dg/cpp0x/constexpr-neg3.C -std=c++11 (test for errors, line 12) > FAIL: g++.dg/cpp1y/constexpr-return2.C -std=c++14 (test for errors, line 7) > FAIL: g++.dg/cpp1y/constexpr-return2.C -std=c++14 (test for excess errors) > FAIL: g++.dg/cpp1y/pr63996.C -std=c++14 (test for errors, line 9) > FAIL: g++.dg/cpp1y/pr63996.C -std=c++14 (test for excess errors) > > 1) there are causing: > > ./xg++ -B. /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/pr63996.C > /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/pr63996.C:9:23: in > constexpr expansion of ‘foo(1)’ > /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/pr63996.C:4:1: error: > ‘__builtin_unreachable()’ is not a constant expression > foo (int i) > ^~~ > > Where we probably should not emit the built-in call. Am I right?
The problem is that I think we save the constexpr function bodies after folding and genericization. We shouldn't be doing that, if we save it before, in addition to fixing quite a few bugs it would fix this as well. If looking for a hack instead of proper fix here, allowing __builtin_unreachable () in constant expressions would be probably undesirable, because then people adding it themselves in their source code would get it accepted. So, either we need some way how to differentiate between user written __builtin_unreachable and one we've added ourselves (doesn't -fsanitize=return fail the similar way though?), either as internal-fn instead, or just by using UNKNOWN_LOCATION or BUILTINS_LOCATION or something similar to find out it is artificial; and of course if we reach it during constexpr evaluation error some way. Jakub