[clang] 0a8ac91 - Permit nowthrow and nonnull with multiversioning.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 4 07:40:41 PDT 2020
Author: Erich Keane
Date: 2020-08-04T07:40:27-07:00
New Revision: 0a8ac91a084504929b1ef4ec1fee693455bd796d
URL: https://github.com/llvm/llvm-project/commit/0a8ac91a084504929b1ef4ec1fee693455bd796d
DIFF: https://github.com/llvm/llvm-project/commit/0a8ac91a084504929b1ef4ec1fee693455bd796d.diff
LOG: Permit nowthrow and nonnull with multiversioning.
Some shipped versions of stdlib.h use nonnull and nothrow with function
multiversioning. Support these, as they are generally harmless.
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-cpuspecific.c
clang/test/Sema/attr-target-mv.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 288e8232ca74..054b81c4a72b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10754,6 +10754,9 @@ def err_multiversion_noproto : Error<
def err_multiversion_disallowed_other_attr : Error<
"attribute '%select{target|cpu_specific|cpu_dispatch}0' multiversioning cannot be combined"
" with attribute %1">;
+def err_multiversion_mismatched_attrs
+ : Error<"attributes on multiversioned functions must all match, attribute "
+ "%0 %select{is missing|has
diff erent arguments}1">;
def err_multiversion_
diff : Error<
"multiversioned function declaration has a
diff erent %select{calling convention"
"|return type|constexpr specification|inline specification|storage class|"
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ba05b0d32cf4..77e15f187e53 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10029,11 +10029,16 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) {
// multiversion functions.
static bool AttrCompatibleWithMultiVersion(attr::Kind Kind,
MultiVersionKind MVType) {
+ // Note: this list/diagnosis must match the list in
+ // checkMultiversionAttributesAllSame.
switch (Kind) {
default:
return false;
case attr::Used:
return MVType == MultiVersionKind::Target;
+ case attr::NonNull:
+ case attr::NoThrow:
+ return true;
}
}
@@ -10201,8 +10206,6 @@ static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD,
MVType == MultiVersionKind::CPUDispatch ||
MVType == MultiVersionKind::CPUSpecific;
- // For now, disallow all other attributes. These should be opt-in, but
- // an analysis of all of them is a future FIXME.
if (CausesMV && OldFD &&
checkNonMultiVersionCompatAttributes(S, OldFD, NewFD, MVType))
return true;
diff --git a/clang/test/Sema/attr-cpuspecific.c b/clang/test/Sema/attr-cpuspecific.c
index e32c7a22894d..9cfeef8a2356 100644
--- a/clang/test/Sema/attr-cpuspecific.c
+++ b/clang/test/Sema/attr-cpuspecific.c
@@ -115,3 +115,5 @@ int use3(void) {
// expected-warning at +1 {{CPU list contains duplicate entries; attribute ignored}}
int __attribute__((cpu_dispatch(pentium_iii, pentium_iii_no_xmm_regs))) dupe_p3(void);
+
+void __attribute__((cpu_specific(atom), nothrow, nonnull(1))) addtl_attrs(int*);
diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c
index 33a2c4fa54eb..3f072b19083f 100644
--- a/clang/test/Sema/attr-target-mv.c
+++ b/clang/test/Sema/attr-target-mv.c
@@ -101,3 +101,10 @@ __vectorcall int __attribute__((target("arch=sandybridge")))
diff _cc(void);
int __attribute__((target("sse4.2")))
diff _ret(void);
// expected-error at +1 {{multiversioned function declaration has a
diff erent return type}}
short __attribute__((target("arch=sandybridge")))
diff _ret(void);
+
+void __attribute__((target("sse4.2"), nothrow, used, nonnull(1))) addtl_attrs5(int*);
+void __attribute__((target("arch=sandybridge"))) addtl_attrs5(int*);
+
+void __attribute__((target("sse4.2"))) addtl_attrs6(int*);
+void __attribute__((target("arch=sandybridge"), nothrow, used, nonnull)) addtl_attrs6(int*);
+
More information about the cfe-commits
mailing list