[llvm-bugs] [Bug 31069] New: Crash with checkDLLAttributeRedeclaration in SemaDecl.cpp (regression in 3.9)

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Nov 19 03:18:29 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31069

            Bug ID: 31069
           Summary: Crash with checkDLLAttributeRedeclaration in
                    SemaDecl.cpp (regression in 3.9)
           Product: clang
           Version: 3.9
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: l.joly at castsoftware.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

If you compile the following example: 

    #include "Zorg.h" // Non existing file

    template<typename _Tp, std::size_t _Nm = 42>
    struct array
    {
    };

    class __declspec(dllimport) DBConnectivity
    {
        static bool myFunc(array<int> args);
    };


    bool
    DBConnectivity::myFunc(array<int> args)
    {
    }

There is a crash in checkDLLAttributeRedeclaration: The dllimport attribute of
the definition is not correctly merged with the one from the declaration,but
the code currently assume that this cannot happen, and unconditionally
dereferences a pointer to the attribute in the definition.

  if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember &&
      !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) {
    if (IsMicrosoft && IsDefinition) {
      S.Diag(NewDecl->getLocation(),
             diag::warn_redeclaration_without_import_attribute)
          << NewDecl;
      S.Diag(OldDecl->getLocation(), diag::note_previous_declaration);
      NewDecl->dropAttr<DLLImportAttr>();
      NewDecl->addAttr(::new (S.Context) DLLExportAttr(
          NewImportAttr->getRange(), S.Context, // Here is the crash!
          NewImportAttr->getSpellingListIndex()));
    } else {

For this merge to fail, we need a combination of the following elements (if you
remove one, the code compiles with no crash):
- An unresolved #include directive
- Some dllimport on the declaration but not on the definition
- The function needs to have a parameter that is the instance of a template
- This  instantiation needs to have some unspecified template argument value,
picked up as the default value (if I write static bool myFunc(array<int, 42>
args); the code no longer crashes).



This bug was introduced by the following commit:

Revision: 270686
Author: dzobnin
Date: mercredi 25 mai 2016 13:32:42
Message:
[ms][dll] #26935 Defining a dllimport function should cause it to be exported

If we have some function with dllimport attribute and then we have the function
definition in the same module but without dllimport attribute we should add
dllexport attribute to this function definition.
The same should be done for variables.

Example:
struct __declspec(dllimport) C3 {
  ~C3();
};
C3::~C3() {;} // we should export this definition.

Patch by Andrew V. Tischenko

Differential revision: http://reviews.llvm.org/D18953

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161119/4d6cc1b4/attachment.html>


More information about the llvm-bugs mailing list