On Fri, Aug 20, 2021 at 01:51:26PM +0200, grischka wrote:
> That's good, but as you may guess, none of the tests that so far
> exist was made specifically to test your new feature. See for
> example:
>
> #pragma pack(push+1)
> #pragma pack(pop)
> #pragma pack(push)
> struct foo { char c; int d; };
> #pragma pack(pop)
> main() { printf("size: %d\n", sizeof (struct foo)); }
>
> should notify the user about the typo, and when you replace
> the '+' by a ',' it should print 'size: 8' (not '5').
Yes.This is my mistake.I made a new patch and it fixes this problem.
>
> You can add one or two tests in 60_errors_and_warnings.c,
> if you want.
I did so.Now error message for above example is similar to the other pragma
options.And a test was added.
Please ONLY apply the patch I sent in this mail.
Suote127
diff --git a/tccgen.c b/tccgen.c
index e0b5fd6..562ab09 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -4589,7 +4589,7 @@ static void struct_layout(CType *type, AttributeDef *ad)
/* pragma pack overrides align if lesser and packs bitfields always */
if (pragma_pack) {
-packed = 1;
+packed = pragma_pack;
if (pragma_pack < align)
align = pragma_pack;
/* in pcc mode pragma pack also overrides individual align */
diff --git a/tccpp.c b/tccpp.c
index 897ef15..3b343a6 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1744,7 +1744,13 @@ static void pragma_parse(TCCState *s1)
if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE - 1)
goto stk_error;
s1->pack_stack_ptr++;
-skip(',');
+if (tok == ')') {
+*s1->pack_stack_ptr = *(s1->pack_stack_ptr - 1);
+return;
+}
+if (tok !=',')
+ goto pragma_err;
+ next();
}
if (tok != TOK_CINT)
goto pragma_err;
diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c
index 8a91512..b86f8c7 100644
--- a/tests/tests2/60_errors_and_warnings.c
+++ b/tests/tests2/60_errors_and_warnings.c
@@ -416,4 +416,6 @@ void func()
fink();
}
__attribute__((stuff)) int fink() {return 0;}
+#elif defined test_pragma_pack_with_wrong_format
+#pragma pack(push+1)
#endif
diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect
index a9dfa2d..6e5053b 100644
--- a/tests/tests2/60_errors_and_warnings.expect
+++ b/tests/tests2/60_errors_and_warnings.expect
@@ -203,3 +203,6 @@ bar : 3 ; 3
[test_switch_W4]
60_errors_and_warnings.c:416: warning: implicit declaration of function 'fink'
60_errors_and_warnings.c:418: error: 'stuff' attribute ignored
+
+[test_pragma_pack_with_wrong_format]
+60_errors_and_warnings.c:420: error: malformed #pragma directive
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel