[PATCH] Wrong output from built-in size function
Nuno Lopes
nunoplopes at sapo.pt
Tue Mar 18 14:49:34 PDT 2014
Hi,
I don't think this is the right fix.
On that file, lines 1512-1515, and after calling isAllocSiteRemovable(), the
objectsize intrinsic is replaced with the "don't know" value. Which is
fine, semantics wise, but we can do better as you expect.
I think that at that point we could try to infer the size of the object, and
only resort to the don't know value if we fail. Take a look at the
getObjectSize() function, and InstCombineCalls.cpp for an example usage.
Nuno
P.S.: BTW, this patch is not for clang, so please send the new version to
llvm-commits.
----- Original Message -----
From: "MAYUR PANDEY" <mayur.p at samsung.com>
To: <cfe-commits at cs.uiuc.edu>
Sent: Tuesday, March 18, 2014 8:19 AM
Subject: [PATCH] Wrong output from built-in size function
> Hi,
>
> Please find attached the fix for wrong output from built-in size function.
> The Testcase attached is a standard gcc testsuite TC.
>
>
>
> extern void abort (void);
>
> extern inline __attribute__ ((__always_inline__)) int
> foo (char *dest)
> {
> return __builtin_object_size (dest, 1);
> }
>
> struct S
> {
> union
> {
> struct { int a, b; char c, d; } f;
> struct { struct { int a, b; char c, d[255]; } e; } g;
> } u;
> };
>
> int
> main (void)
> {
> struct S s;
> if (foo (s.u.g.e.d) != 255)
> abort ();
> return 0;
> }
>
>
>
> In the TC above the abort function is called as clang is unable to return
> correct output on calling built-in size function. the reason seems to be
> that in Instruction Combination pass for optimization,
>
> Clang was not able to properly handle built-in size function as per new
> DFS implementation. So Moving it back to follow iterative way specifically
> for built-in size function.
>
>
>
> Please Review.
>
>
>
> Thanks,
>
> Mayur
More information about the cfe-commits
mailing list