Author: rogfer01
Date: Wed Apr 19 07:23:28 2017
New Revision: 300686

URL: http://llvm.org/viewvc/llvm-project?rev=300686&view=rev
Log:
Avoid assert when a non-static member function is qualified with __unaligned

Under -fms-extensions __unaligned is a type-qualifier that can be applied to a
non-static member function declaration.

This causes an assertion when mangling the name under Itanium, where that
qualifier is not mangled.

This patch justs makes the minimal change to avoid the crash and avoid mangling
__unaligned, as it currently happens with non-member functions.

Differential Revision: https://reviews.llvm.org/D31976


Added:
    cfe/trunk/test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp
Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=300686&r1=300685&r2=300686&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Apr 19 07:23:28 2017
@@ -1455,10 +1455,12 @@ void CXXNameMangler::mangleNestedName(co
   Out << 'N';
   if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
     Qualifiers MethodQuals =
-        Qualifiers::fromCVRMask(Method->getTypeQualifiers());
+        Qualifiers::fromCVRUMask(Method->getTypeQualifiers());
     // We do not consider restrict a distinguishing attribute for overloading
     // purposes so we must not mangle it.
     MethodQuals.removeRestrict();
+    // __unaligned is not currently mangled in any way, so remove it.
+    MethodQuals.removeUnaligned();
     mangleQualifiers(MethodQuals);
     mangleRefQualifier(Method->getRefQualifier());
   }

Added: cfe/trunk/test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp?rev=300686&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp Wed Apr 19 
07:23:28 2017
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fms-extensions -emit-llvm-only 
%s -verify
+
+struct A
+{
+    int x;
+    void foo() __unaligned;
+    void foo();
+};
+
+void A::foo() __unaligned
+{
+    this->x++;
+}
+
+void A::foo() // expected-error {{definition with same mangled name as another 
definition}}
+              // expected-note@-6 {{previous definition is here}}
+{
+    this->x++;
+}
+


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to