[llvm-bugs] [Bug 50722] New: Add warnings about violation of	aliasing rules
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Tue Jun 15 10:35:04 PDT 2021
    
    
  
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: unassignedclangbugs at nondot.org
          Reporter: tk at tkoenig.net
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210615/999668e7/attachment.html>
    
    
More information about the llvm-bugs
mailing list