}
bool isUsedAsTypeAttr() const { return UsedAsTypeAttr; }
- void setUsedAsTypeAttr() { UsedAsTypeAttr = true; }
+ void setUsedAsTypeAttr(bool Used = true) { UsedAsTypeAttr = Used; }
/// True if the attribute is specified using '#pragma clang attribute'.
bool isPragmaClangAttribute() const { return IsPragmaClangAttribute; }
case ParsedAttr::AT_Regparm: \
case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: \
case ParsedAttr::AT_AnyX86NoCfCheck: \
- case ParsedAttr::AT_NoThrow: \
CALLING_CONV_ATTRS_CASELIST
// Microsoft-specific type qualifiers.
}
if (attr.getKind() == ParsedAttr::AT_NoThrow) {
- if (S.CheckAttrNoArgs(attr))
- return true;
-
// Delay if this is not a function type.
if (!unwrapped.isFunctionType())
return false;
- // Otherwise we can process right away.
- auto *Proto = unwrapped.get()->getAs<FunctionProtoType>();
-
- // In the case where this is a FunctionNoProtoType instead of a
- // FunctionProtoType, let the existing NoThrowAttr implementation do its
- // thing.
- if (!Proto)
- return false;
+ if (S.CheckAttrNoArgs(attr)) {
+ attr.setInvalid();
+ return true;
+ }
- attr.setUsedAsTypeAttr();
+ // Otherwise we can process right away.
+ auto *Proto = unwrapped.get()->castAs<FunctionProtoType>();
// MSVC ignores nothrow if it is in conflict with an explicit exception
// specification.
attr.setInvalid();
break;
+ case ParsedAttr::AT_NoThrow:
+ // Exception Specifications aren't generally supported in C mode throughout
+ // clang, so revert to attribute-based handling for C.
+ if (!state.getSema().getLangOpts().CPlusPlus)
+ break;
+ LLVM_FALLTHROUGH;
FUNCTION_TYPE_ATTRS_CASELIST:
attr.setUsedAsTypeAttr();
--- /dev/null
+// RUN: %clang_cc1 %s -verify
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+// expected-no-diagnostics
+
+// PR42113: The following caused an assertion in mergeFunctionTypes
+// because it causes one side to have an exception specification, which
+// isn't typically supported in C.
+void PR42113a();
+void PR42113a(void) __attribute__((nothrow));
+// CHECK: FunctionDecl {{.*}} PR42113a
+// CHECK: FunctionDecl {{.*}} PR42113a
+// CHECK: NoThrowAttr
+void PR42113b() __attribute__((nothrow));
+// CHECK: FunctionDecl {{.*}} PR42113b
+// CHECK: NoThrowAttr
+ __attribute__((nothrow)) void PR42113c();
+// CHECK: FunctionDecl {{.*}} PR42113c
+// CHECK: NoThrowAttr