[PATCH] D52271: [Sema] Ensure that we retain __restrict qualifiers when substituting a reference type.
This revision was automatically updated to reflect the committed changes. Closed by commit rC342672: [Sema] Retain __restrict qualifiers when substituting a reference type. (authored by epilk, committed by ). Changed prior to commit: https://reviews.llvm.org/D52271?vs=166224=166334#toc Repository: rC Clang https://reviews.llvm.org/D52271 Files: lib/Sema/TreeTransform.h test/SemaCXX/subst-restrict.cpp Index: test/SemaCXX/subst-restrict.cpp === --- test/SemaCXX/subst-restrict.cpp +++ test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: lib/Sema/TreeTransform.h === --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +// The only qualifier that applies to a reference type is restrict. +if (!Quals.hasRestrict()) + return T; +Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. Index: test/SemaCXX/subst-restrict.cpp === --- test/SemaCXX/subst-restrict.cpp +++ test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: lib/Sema/TreeTransform.h === --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +// The only qualifier that applies to a reference type is restrict. +if (!Quals.hasRestrict()) + return T; +Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52271: [Sema] Ensure that we retain __restrict qualifiers when substituting a reference type.
rjmccall accepted this revision. rjmccall added a comment. This revision is now accepted and ready to land. Thanks, LGTM. https://reviews.llvm.org/D52271 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52271: [Sema] Ensure that we retain __restrict qualifiers when substituting a reference type.
erik.pilkington updated this revision to Diff 166224. erik.pilkington added a comment. Sure, the new patch just preserves __restrict qualifiers. Thanks! https://reviews.llvm.org/D52271 Files: clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/subst-restrict.cpp Index: clang/test/SemaCXX/subst-restrict.cpp === --- /dev/null +++ clang/test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +// The only qualifier that applies to a reference type is restrict. +if (!Quals.hasRestrict()) + return T; +Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. Index: clang/test/SemaCXX/subst-restrict.cpp === --- /dev/null +++ clang/test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +// The only qualifier that applies to a reference type is restrict. +if (!Quals.hasRestrict()) + return T; +Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52271: [Sema] Ensure that we retain __restrict qualifiers when substituting a reference type.
rjmccall added inline comments. Comment at: clang/lib/Sema/TreeTransform.h:4268 +Quals.removeVolatile(); + } `restrict` is unique in being able to be applied to reference types. You should just rebuild `Quals` from scratch, preserving only `restrict`. Repository: rC Clang https://reviews.llvm.org/D52271 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52271: [Sema] Ensure that we retain __restrict qualifiers when substituting a reference type.
erik.pilkington created this revision. erik.pilkington added reviewers: rsmith, rjmccall. Herald added a subscriber: dexonsmith. Fixes rdar://43760099. Thanks for taking a look! Repository: rC Clang https://reviews.llvm.org/D52271 Files: clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/subst-restrict.cpp Index: clang/test/SemaCXX/subst-restrict.cpp === --- /dev/null +++ clang/test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + // Presumably, [dcl.fct]p7 would have applied to __restrict (and all the other + // qualifiers we support). + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +Quals.removeConst(); +Quals.removeVolatile(); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. Index: clang/test/SemaCXX/subst-restrict.cpp === --- /dev/null +++ clang/test/SemaCXX/subst-restrict.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s + +// expected-no-diagnostics + +template struct add_restrict { + typedef T __restrict type; +}; + +template struct is_same { + static constexpr bool value = false; +}; + +template struct is_same { + static constexpr bool value = true; +}; + +static_assert(is_same::type>::value, ""); +static_assert(is_same::type>::value, ""); Index: clang/lib/Sema/TreeTransform.h === --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4252,14 +4252,20 @@ // C++ [dcl.fct]p7: // [When] adding cv-qualifications on top of the function type [...] the // cv-qualifiers are ignored. + // Presumably, [dcl.fct]p7 would have applied to __restrict (and all the other + // qualifiers we support). + if (T->isFunctionType()) +return T; + // C++ [dcl.ref]p1: // when the cv-qualifiers are introduced through the use of a typedef-name // or decltype-specifier [...] the cv-qualifiers are ignored. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be // applied to a reference type. - // FIXME: This removes all qualifiers, not just cv-qualifiers! - if (T->isFunctionType() || T->isReferenceType()) -return T; + if (T->isReferenceType()) { +Quals.removeConst(); +Quals.removeVolatile(); + } // Suppress Objective-C lifetime qualifiers if they don't make sense for the // resulting type. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits