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 @@ -2135,16 +2135,18 @@ void AttributeChecker::visitExternAttr(ExternAttr *attr) {
2135
2135
if (cName->empty ())
2136
2136
diagnose (attr->getLocation (), diag::extern_empty_c_name);
2137
2137
}
2138
+
2139
+ // Ensure the decl has C compatible interface. Otherwise it produces diagnostics.
2140
+ if (!isCCompatibleFuncDecl (FD)) {
2141
+ attr->setInvalid ();
2142
+ // Mark the decl itself invalid not to require body even with invalid ExternAttr.
2143
+ FD->setInvalid ();
2144
+ }
2138
2145
}
2139
2146
2140
2147
// @_cdecl cannot be mixed with @_extern since @_cdecl is for definitions
2141
2148
if (D->getAttrs ().hasAttribute <CDeclAttr>())
2142
2149
diagnose (attr->getLocation (), diag::extern_only_non_other_attr, " @_cdecl" );
2143
-
2144
- if (!isCCompatibleFuncDecl (FD)) {
2145
- attr->setInvalid ();
2146
- FD->setInvalid ();
2147
- }
2148
2150
}
2149
2151
2150
2152
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