Fwd: Re: [PATCH][Modules][PR26179]

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 18 11:40:32 PST 2016


+      // the when comparing #1 and #2 we should go through their elements
types.

Typo "the when"

+      QualType VarXTy = VarX->getType();
+      QualType VarYTy = VarY->getType();
+      if (VarXTy->isIncompleteArrayType() ||
VarYTy->isIncompleteArrayType())
+        return C.hasSameType(C.getAsArrayType(VarXTy)->getElementType(),
+                             C.getAsArrayType(VarYTy)->getElementType());

This will crash when one type is an incomplete array type and the other is
not an array type.

---------- Forwarded message ----------
From: "Richard Smith" <richard at metafoo.co.uk>
Date: Jan 18, 2016 11:38 AM
Subject: Re: [PATCH][Modules][PR26179]
To: "Vassil Vassilev" <vvasilev at cern.ch>
Cc: "Douglas Gregor" <dgregor at apple.com>, "cfe commits" <
cfe-commits at cs.uiuc.edu>

> Please also add a test case that your old patch would have failed on,
such as:
>
> m1.h:
> extern int a[];
>
> m2.h:
> extern int a[5];
>
> x.cc:
> #include "m1.h"
> #include "m2.h"
> int *p = a;
>
> On Jan 18, 2016 9:28 AM, "Vassil Vassilev" <vvasilev at cern.ch> wrote:
>>
>> On 17/01/16 06:34, Douglas Gregor wrote:
>>>>
>>>> On Jan 16, 2016, at 3:41 PM, Vassil Vassilev <vvasilev at cern.ch> wrote:
>>>>
>>>> Hi,
>>>>   Could somebody review the attached patch. It fixes
https://llvm.org/bugs/show_bug.cgi?id=26179
>>>> Many thanks!
>>>> Vassil
>>>> <0001-modules-Teach-clang-to-how-to-merge-variable-redecls.patch>
>>>
>>>
>>> +      // We can get decls with different types on the redecl chain. Eg.
>>> +      // template <typename T> struct S { static T Var[]; }; // #1
>>> +      // template <typename T> T S<T>::Var[sizeof(T)]; // #2
>>> +      // Trying to compare #1 and #2 should go through their canonical
decls.
>>> +      QualType VarXTy = VarX->getCanonicalDecl()->getType();
>>> +      QualType VarYTy = VarY->getCanonicalDecl()->getType();
>>> +      if (Context.hasSameType(VarXTy, VarYTy))
>>> +        return true;
>>>
>>> Completing an incomplete array is (I think) the only case in which this
can happen. How about checking for that case specifically (i.e., it’s okay
to have one be an incomplete array and the other to be any other kind of
array with the same element type), rather than a blanket check on the
canonical declaration types?
>>>
>>>         - Doug
>>>
>> Thanks for the comments. Patch v2 attached.
>> -- Vassil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160118/165407b2/attachment.html>


More information about the cfe-commits mailing list