<p dir="ltr">+      // the when comparing #1 and #2 we should go through their elements types.</p>
<p dir="ltr">Typo "the when"</p>
<p dir="ltr">+      QualType VarXTy = VarX->getType();<br>
+      QualType VarYTy = VarY->getType();<br>
+      if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType())<br>
+        return C.hasSameType(C.getAsArrayType(VarXTy)->getElementType(),<br>
+                             C.getAsArrayType(VarYTy)->getElementType());</p>
<p dir="ltr">This will crash when one type is an incomplete array type and the other is not an array type.</p>
<p dir="ltr">---------- Forwarded message ----------<br>
From: "Richard Smith" <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>><br>
Date: Jan 18, 2016 11:38 AM<br>
Subject: Re: [PATCH][Modules][PR26179]<br>
To: "Vassil Vassilev" <<a href="mailto:vvasilev@cern.ch">vvasilev@cern.ch</a>><br>
Cc: "Douglas Gregor" <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>>, "cfe commits" <<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a>></p>
<p dir="ltr">> Please also add a test case that your old patch would have failed on, such as:<br>
><br>
> m1.h:<br>
> extern int a[];<br>
><br>
> m2.h:<br>
> extern int a[5];<br>
><br>
> x.cc:<br>
> #include "m1.h"<br>
> #include "m2.h"<br>
> int *p = a;<br>
><br>
> On Jan 18, 2016 9:28 AM, "Vassil Vassilev" <<a href="mailto:vvasilev@cern.ch">vvasilev@cern.ch</a>> wrote:<br>
>><br>
>> On 17/01/16 06:34, Douglas Gregor wrote:<br>
>>>><br>
>>>> On Jan 16, 2016, at 3:41 PM, Vassil Vassilev <<a href="mailto:vvasilev@cern.ch">vvasilev@cern.ch</a>> wrote:<br>
>>>><br>
>>>> Hi,<br>
>>>>   Could somebody review the attached patch. It fixes <a href="https://llvm.org/bugs/show_bug.cgi?id=26179">https://llvm.org/bugs/show_bug.cgi?id=26179</a><br>
>>>> Many thanks!<br>
>>>> Vassil<br>
>>>> <0001-modules-Teach-clang-to-how-to-merge-variable-redecls.patch><br>
>>><br>
>>><br>
>>> +      // We can get decls with different types on the redecl chain. Eg.<br>
>>> +      // template <typename T> struct S { static T Var[]; }; // #1<br>
>>> +      // template <typename T> T S<T>::Var[sizeof(T)]; // #2<br>
>>> +      // Trying to compare #1 and #2 should go through their canonical decls.<br>
>>> +      QualType VarXTy = VarX->getCanonicalDecl()->getType();<br>
>>> +      QualType VarYTy = VarY->getCanonicalDecl()->getType();<br>
>>> +      if (Context.hasSameType(VarXTy, VarYTy))<br>
>>> +        return true;<br>
>>><br>
>>> 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?<br>
>>><br>
>>>         - Doug<br>
>>><br>
>> Thanks for the comments. Patch v2 attached.<br>
>> -- Vassil<br>
</p>