This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug sanitizer/63956] [5 Regression][UBSAN] ICE segfault in cxx_eval_call_expression ../../gcc/cp/constexpr.c


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63956

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
In the light of -std=c++14 constexprs, please try to write testcases like
(-std=c++14 -fsanitize=undefined,float-divide-by-zero,float-cast-overflow):

constexpr int
f1 (int a, int b)
{
  if (b != 2)
    a <<= b;
  return a;
}

constexpr int x1 = f1 (5, 3);
constexpr int x2 = f1 (5, -2);

constexpr int
f2 (int a, int b)
{
  if (b != 2)
    a = a / b;
  return a;
}

constexpr int x3 = f2 (5, 3);
constexpr int x4 = f2 (7, 0);
constexpr int x5 = f2 (-__INT_MAX__ - 1, -1);

constexpr float
f3 (float a, float b)
{
  if (b != 2.0)
    a = a / b;
  return a;
}

constexpr float x6 = f3 (5.0, 3.0);
constexpr float x7 = f3 (7.0, 0.0);

constexpr int
f4 (const int *a, int b)
{
  if (b != 2)
    b = a[b];
  return b;
}

constexpr int x8[4] = { 1, 2, 3, 4 };
constexpr int x9 = f4 (x8, 3);
constexpr int x10 = f4 (x8, 4);

constexpr int
f5 (const int &a, int b)
{
  if (b != 2)
    b = a;
  return b;
}

constexpr int
f6 (const int *a, int b)
{
  if (b != 3)
    return f5 (*a, b);
  return 7;
}

constexpr int x12 = 7;
constexpr int x13 = f6 (&x12, 5);
constexpr int x14 = f6 ((const int *) 0, 8);

(and add for all the other stuff we ubsan instrument in the FEs).
For the first snippet we e.g. emit:
m1.C:10:23:   in constexpr expansion of âf1(5, -2)â
m1.C:5:7: error: â<ubsan routine call>â is not a constant expression
     a <<= b;
       ^
m1.C:10:29: error: constexpr call flows off the end of the function
 constexpr int x2 = f1 (5, -2);
                             ^
I'd say we should not, we should just ignore the ubsan routine call.
If C++14 constexprs are supposed to be invalid if there is undefined behavior
in them while being interpreted by the compiler with the given arguments, then
supposedly the FE should regardless of -fsanitize=undefined error out or warn
and say exactly what is invalid in there, talking about <ubsan routine call>
is just too confusing.  Don't know if rejecting it is just QoI or a requirement
in C++14.
And on the last snippet we ICE, that is the internal call.
Haven't added all the cases there though, and even e.g. for shift I haven't
tried to call it with all the kinds of arguments that are invalid in C++14.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]