r242973 - Downgrade error about adding 'dllimport' to used free function to warning (PR24215)

Hans Wennborg hans at chromium.org
Mon Jul 27 13:20:26 PDT 2015


Ping?

On Thu, Jul 23, 2015 at 4:45 PM, Hans Wennborg <hans at chromium.org> wrote:
> This isn't fixing a regression, but would be nice to have in 3.7 I think.
>
> Richard, is this OK for merging?
>
> On Wed, Jul 22, 2015 at 4:54 PM, Hans Wennborg <hans at hanshq.net> wrote:
>> Author: hans
>> Date: Wed Jul 22 18:54:51 2015
>> New Revision: 242973
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=242973&view=rev
>> Log:
>> Downgrade error about adding 'dllimport' to used free function to warning (PR24215)
>>
>> The code will still work as it can reference the function via its thunk.
>>
>> Modified:
>>     cfe/trunk/lib/Sema/SemaDecl.cpp
>>     cfe/trunk/test/Sema/dllimport.c
>>
>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=242973&r1=242972&r2=242973&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 22 18:54:51 2015
>> @@ -5368,10 +5368,9 @@ static void checkDLLAttributeRedeclarati
>>    bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
>>
>>    if (AddsAttr && !IsSpecialization && !OldDecl->isImplicit()) {
>> -    // If the declaration hasn't been used yet, allow with a warning for
>> -    // free functions and global variables.
>> +    // Allow with a warning for free functions and global variables.
>>      bool JustWarn = false;
>> -    if (!OldDecl->isUsed() && !OldDecl->isCXXClassMember()) {
>> +    if (!OldDecl->isCXXClassMember()) {
>>        auto *VD = dyn_cast<VarDecl>(OldDecl);
>>        if (VD && !VD->getDescribedVarTemplate())
>>          JustWarn = true;
>> @@ -5380,6 +5379,13 @@ static void checkDLLAttributeRedeclarati
>>          JustWarn = true;
>>      }
>>
>> +    // We cannot change a declaration that's been used because IR has already
>> +    // been emitted. Dllimported functions will still work though (modulo
>> +    // address equality) as they can use the thunk.
>> +    if (OldDecl->isUsed())
>> +      if (!isa<FunctionDecl>(OldDecl) || !NewImportAttr)
>> +        JustWarn = false;
>> +
>>      unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
>>                                 : diag::err_attribute_dll_redeclaration;
>>      S.Diag(NewDecl->getLocation(), DiagID)
>>
>> Modified: cfe/trunk/test/Sema/dllimport.c
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport.c?rev=242973&r1=242972&r2=242973&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/Sema/dllimport.c (original)
>> +++ cfe/trunk/test/Sema/dllimport.c Wed Jul 22 18:54:51 2015
>> @@ -143,7 +143,7 @@ __declspec(dllimport) void redecl3(); //
>>
>>                        void redecl4(); // expected-note{{previous declaration is here}}
>>  void useRedecl4() { redecl4(); }
>> -__declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}}
>> +__declspec(dllimport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
>>
>>  // Allow with a warning if the decl hasn't been used yet.
>>                        void redecl5(); // expected-note{{previous declaration is here}}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list