From f31b5ea1e6a28baa008796672b333f8b6ff1caca Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 29 Oct 2022 19:27:47 -0500 Subject: [PATCH] Allow "extern inline" functions. A function declared "inline" with an explicit "extern" storage class has the same semantics as if "inline" was omitted. (It is not an inline definition as defined in the C standards.) The "inline" specifier suggests that the function should be inlined, but it is legal to just ignore it, as we already do for "static inline" functions. Also add a test for the inline function specifier. --- Parser.pas | 2 +- Scanner.pas | 2 +- Tests/Conformance/DOIT3 | 1 + Tests/Conformance/c99inline.c | 33 +++++++++++++++++++++++++++++++++ cc.notes | 2 +- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Tests/Conformance/c99inline.c diff --git a/Parser.pas b/Parser.pas index d86eb7e..580053f 100644 --- a/Parser.pas +++ b/Parser.pas @@ -3779,7 +3779,7 @@ if isFunction then begin goto 1; end; {if} if isInline then - if declSpecifiers.storageClass <> staticsy then + if not (declSpecifiers.storageClass in [staticsy,externsy]) then Error(120); if isInline or isNoreturn then if not (isNewDeskAcc or isClassicDeskAcc or isCDev or isNBA or isXCMD) then diff --git a/Scanner.pas b/Scanner.pas index 8b9656e..e43b637 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -714,7 +714,7 @@ if list or (numErr <> 0) then begin 117: msg := @'field cannot have incomplete or function type'; 118: msg := @'flexible array must be last member of structure'; 119: msg := @'inline specifier is only allowed on functions'; - 120: msg := @'non-static inline functions are not supported'; + 120: msg := @'inline functions without ''static'' or ''extern'' are not supported'; 121: msg := @'invalid digit for binary constant'; 122: msg := @'arithmetic is not allowed on a pointer to an incomplete or function type'; 123: msg := @'array element type may not be an incomplete or function type'; diff --git a/Tests/Conformance/DOIT3 b/Tests/Conformance/DOIT3 index f4d1f22..aab0864 100644 --- a/Tests/Conformance/DOIT3 +++ b/Tests/Conformance/DOIT3 @@ -23,6 +23,7 @@ {1} c99fpcmp.c {1} c99tgmath.c {1} c99pragma.c +{1} c99inline.c {1} c11generic.c {1} c11align.c {1} c11noret.c diff --git a/Tests/Conformance/c99inline.c b/Tests/Conformance/c99inline.c new file mode 100644 index 0000000..762bcf6 --- /dev/null +++ b/Tests/Conformance/c99inline.c @@ -0,0 +1,33 @@ +/* + * Test inline function specifier (C99). + * + * This only tests "static inline" and "extern inline", + * which are the only forms currently supported by ORCA/C. + */ + +#include + +static inline int f(void) { + return 1; +} + +inline int extern g(void) { + return 2; +} + +int main(void) { + int (*p)(void) = f; + int (*q)(void) = g; + + if (f() + g() != 3) + goto Fail; + + if (p() + q() != 3) + goto Fail; + + printf ("Passed Conformance Test c99inline\n"); + return 0; + +Fail: + printf ("Failed Conformance Test c99inline\n"); +} diff --git a/cc.notes b/cc.notes index fc94e64..f998f6e 100644 --- a/cc.notes +++ b/cc.notes @@ -451,7 +451,7 @@ The flexible array member does not contribute to the size of the struct as repor (Kelvin Sherlock) -6. (C99) Functions may be declared as "static inline". These have the same semantics as other static functions. The "inline" specifier suggests (but does not require) that calls to the function should be inlined or otherwise optimized. ORCA/C currently does not inline these functions or apply any other special optimizations, but future versions might introduce such features. Note that non-static inline functions are not currently supported. +6. (C99) Functions may be declared as "static inline" or "extern inline". These have the same semantics as if "inline" was omitted. The "inline" function specifier suggests (but does not require) that calls to the function should be inlined or otherwise optimized. ORCA/C currently does not inline these functions or apply any other special optimizations, but future versions might introduce such features. Note that inline functions without a "static" or "extern" storage-class specifier are not currently supported. 7. (Draft C23) Integer constants may be written in binary, with a "0b" or "0B" prefix followed by binary digits. The type of these constants is determined by the same rules as for octal and hexadecimal constants.