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" <[email protected]>
To: <[email protected]>
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

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to