Index: lib/AST/ItaniumMangle.cpp =================================================================== --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -1459,8 +1459,6 @@ // 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()); } @@ -2208,6 +2206,9 @@ break; } + if (Quals.hasUnaligned()) + mangleVendorQualifier("__unaligned"); + // ::= [r] [V] [K] # restrict (C99), volatile, const if (Quals.hasRestrict()) Out << 'r'; @@ -4327,7 +4328,7 @@ /// substitutions. static bool hasMangledSubstitutionQualifiers(QualType T) { Qualifiers Qs = T.getQualifiers(); - return Qs.getCVRQualifiers() || Qs.hasAddressSpace(); + return Qs.getCVRQualifiers() || Qs.hasAddressSpace() || Qs.hasUnaligned(); } bool CXXNameMangler::mangleSubstitution(QualType T) { Index: test/CodeGenCXX/pr33080.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/pr33080.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -fms-extensions -emit-llvm -o- %s | FileCheck %s + +void fa(__unaligned struct A *) {} +// CHECK: define void @_Z2faPU11__unaligned1A( + +void ga(struct A *, struct A *) {} +// CHECK: define void @_Z2gaP1AS0_( + +void gb(__unaligned struct A *, struct A *) {} +// CHECK: define void @_Z2gbPU11__unaligned1APS_( + +void gc(struct A *, __unaligned struct A *) {} +// CHECK: define void @_Z2gcP1APU11__unalignedS_( + +void gd(__unaligned struct A *, __unaligned struct A *) {} +// CHECK: define void @_Z2gdPU11__unaligned1AS1_( + +void hb(__unaligned struct A *, __unaligned const struct A *) {} +// CHECK: define void @_Z2hbPU11__unaligned1APU11__unalignedKS_( + +void ja(__unaligned struct A *, __unaligned struct A *__unaligned *, __unaligned struct A *__unaligned *__unaligned *) {} +// CHECK: define void @_Z2jaPU11__unaligned1APU11__unalignedS1_PU11__unalignedS3_( + +void jb(__unaligned struct A *, __unaligned struct A **, __unaligned struct A *__unaligned *__unaligned *) {} +// CHECK: @_Z2jbPU11__unaligned1APS1_PU11__unalignedPU11__unalignedS1_( + +template +void ta(T &, Q *) {} + +void ia(__unaligned struct A &a) { + ta(a, &a); +} +// CHECK: @_Z2taIU11__unaligned1AS1_EvRT_PT0_( Index: test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp =================================================================== --- test/CodeGenCXX/unaligned-duplicated-mangle-name.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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++; -} - Index: test/CodeGenCXX/unaligned-member-qualifier.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/unaligned-member-qualifier.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -fms-extensions -emit-llvm %s -o- | FileCheck %s + +struct A { + void foo() __unaligned; + void foo() const __unaligned; + void foo() volatile __unaligned; + void foo() const volatile __unaligned; +}; + +void A::foo() __unaligned {} +// CHECK: define void @_ZNU11__unaligned1A3fooEv( + +void A::foo() const __unaligned {} +// CHECK: define void @_ZNU11__unalignedK1A3fooEv( + +void A::foo() volatile __unaligned {} +// CHECK: define void @_ZNU11__unalignedV1A3fooEv( + +void A::foo() const volatile __unaligned {} +// CHECK: define void @_ZNU11__unalignedVK1A3fooEv(