<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Object invariant violation: FunctionType set"
   href="https://llvm.org/bugs/show_bug.cgi?id=27936">27936</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Object invariant violation: FunctionType set
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eugvelesevich@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16434" name="attach_16434" title="test">attachment 16434</a> <a href="attachment.cgi?id=16434&action=edit" title="test">[details]</a></span>
test

I added this assert code to FoldingSetImpl::InsertNode function
(lib/Support/FoldingSet.cpp):

 void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
+#ifndef NDEBUG
+  FoldingSetNodeID ID; 
+  GetNodeProfile(N, ID);
+  void *InsertPos2 = 0;
+  Node *N2 = FindNodeOrInsertPos(ID, InsertPos2);
+  assert(!N2 && "Node has already been in the set");
+  assert(InsertPos == InsertPos2 && "Incorrect InsertPos");
+#endif



The first assert fails (if compile with -std=c++11) on the attached test with
stacktrace:

llvm/lib/Support/FoldingSet.cpp:336: void
llvm::FoldingSetImpl::InsertNode(llvm::FoldingSetImpl::Node*, void*): Assertion
`!N2 && "Node has already been in the set"' failed.
...
#9 0x0000000002f94b5e
llvm::FoldingSetImpl::InsertNode(llvm::FoldingSetImpl::Node*, void*)
llvm/lib/Support/FoldingSet.cpp:337:0
#10 0x0000000002f94943 llvm::FoldingSetImpl::GrowHashTable()
llvm/lib/Support/FoldingSet.cpp:294:0
#11 0x0000000002f94bf0
llvm::FoldingSetImpl::InsertNode(llvm::FoldingSetImpl::Node*, void*)
llvm/lib/Support/FoldingSet.cpp:343:0
#12 0x0000000005275306 clang::ASTContext::getFunctionType(clang::QualType,
llvm::ArrayRef<clang::QualType>, clang::FunctionProtoType::ExtProtoInfo const&)
const clang/lib/AST/ASTContext.cpp:3115:0
#13 0x00000000052750c5 clang::ASTContext::getFunctionType(clang::QualType,
llvm::ArrayRef<clang::QualType>, clang::FunctionProtoType::ExtProtoInfo const&)
const clang/lib/AST/ASTContext.cpp:3071:0
...

Thats means there are two same FunctionProtoType objects in the set. So it
follows that we modify an object (and change hash) placed in the set.

I researched the issue placing a couple of breakpoints and found this:

A hash of FunctionProtoType depends on CanonicalDecl of ExceptionSpec
SourceDecl stored in ExtProtoInfo.
FunctionProtoType::Profile:
..
ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl())
..
But when clang create destructor(dtor) via clang::Sema::ActOnFunctionDeclarator
at lib/Sema/SemaDecl.cpp:7341 we use the created dtor as SourceDecl in
ExceptionSpec(in function Sema::AdjustDestructorExceptionSpec called
immediately after dtor creation) that results in creation new FunctionProtoType
because there cannot be a type in the set with just created dtor(without
previous decl) as set key. Later we call FunctionDecl::setPreviousDeclaration
for the dtor setting new canonical decl and changing the hash.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>