File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -2132,16 +2132,18 @@ void AttributeChecker::visitExternAttr(ExternAttr *attr) {
2132
2132
if (cName->empty ())
2133
2133
diagnose (attr->getLocation (), diag::extern_empty_c_name);
2134
2134
}
2135
+
2136
+ // Ensure the decl has C compatible interface. Otherwise it produces diagnostics.
2137
+ if (!isCCompatibleFuncDecl (FD)) {
2138
+ attr->setInvalid ();
2139
+ // Mark the decl itself invalid not to require body even with invalid ExternAttr.
2140
+ FD->setInvalid ();
2141
+ }
2135
2142
}
2136
2143
2137
2144
// @_cdecl cannot be mixed with @_extern since @_cdecl is for definitions
2138
2145
if (D->getAttrs ().hasAttribute <CDeclAttr>())
2139
2146
diagnose (attr->getLocation (), diag::extern_only_non_other_attr, " @_cdecl" );
2140
-
2141
- if (!isCCompatibleFuncDecl (FD)) {
2142
- attr->setInvalid ();
2143
- FD->setInvalid ();
2144
- }
2145
2147
}
2146
2148
2147
2149
void AttributeChecker::visitUsedAttr (UsedAttr *attr) {
Original file line number Diff line number Diff line change @@ -86,8 +86,22 @@ func mixedAttrs_C_Wasm()
86
86
class NonC {}
87
87
@_extern(c)
88
88
func nonCReturnTypes() -> NonC // expected-error {{'NonC' cannot be represented in C}}
89
+ // @_extern(wasm) have no interface limitation
90
+ @_extern(wasm, module: " non- c" , name: " return _wasm" )
91
+ func nonCReturnTypesWasm() -> NonC
92
+ @_extern(c)
93
+ @_extern(wasm, module: " non- c" , name: " return _mixed" )
94
+ func nonCReturnTypesMixed() -> NonC // expected-error {{'NonC' cannot be represented in C}}
95
+
89
96
@_extern(c)
90
97
func nonCParamTypes(_: Int, _: NonC) // expected-error {{'NonC' cannot be represented in C}}
98
+ @_extern(wasm, module: " non- c" , name: " param_wasm" )
99
+ func nonCParamTypesWasm(_: Int, _: NonC)
100
+
101
+ @_extern(c)
102
+ @_extern(wasm, module: " non- c" , name: " param_mixed" )
103
+ func nonCParamTypesMixed(_: Int, _: NonC) // expected-error {{'NonC' cannot be represented in C}}
104
+
91
105
92
106
@_extern(c)
93
107
func asyncFuncC() async // expected-error {{async functions cannot be represented in C}}
You can’t perform that action at this time.
0 commit comments