https://bugs.llvm.org/show_bug.cgi?id=50722

            Bug ID: 50722
           Summary: Add warnings about violation of aliasing rules
           Product: clang
           Version: 12.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

The following, rather horrible code (which came off a Usenet discussion)
violates C aliasing rules in several places:

#include <stdio.h>
typedef unsigned char uchar;

int
main ()
{
  double d = 2.34;
  int i[2];
  printf ("%lf\n", d);
  *(long *)i = *(long *)&d;
  ((int *)&d)[0] = i[0];
  ((int *)&d)[1] = i[1];
  printf ("%.15lf\n", d);
  ((uchar *)&d)[2] += 123;
  printf ("%.15lf\n", d);
  return 0;
}

It would be nice if clang could warn or issue an error about the lines

*(long *)i = *(long *)&d;
*(long *)i = *(long *)&d;
((int *)&d)[0] = i[0];

with suitable options (preferably -Wall).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to