Re: [Tinycc-devel] Preprocessor directive "pragma"

2021-08-20 Thread Suote127
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


Re: [Tinycc-devel] Preprocessor directive "pragma"

2021-08-20 Thread grischka

suote127 wrote:

I made a small patch to fix this problem.All tests are passed(with make 
test).


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').

You can add one or two tests in 60_errors_and_warnings.c,
if you want.

-- grischka



Suote127




___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel






___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] Preprocessor directive "pragma"

2021-08-19 Thread suote127
Hello,
At first,I am sorry for my poor English.
I am compiling a program which processes binary data package.To avoid 
excess padding,it uses "#pragma" to disable padding.But an error occurred while 
compiling with TCC.TCC does not accept pragma option "pack" with only an 
operator "push".For example,

#include

/*  This*/
#pragma pack(push)
#pragma pack(1)

struct foo {
char c;
int b;
};

/*  This*/
#pragma pack(pop)

int main(void)
{
printf("%zd\n",sizeof(struct foo));
return 0;
}

Code like the above example works fine for both gcc 7.5.0 and Clang 
6.0.0 on Ubuntu 18.04LTS.But tcc failed to compile it.
I made a small patch to fix this problem.All tests are passed(with make 
test).

Suote127
diff --git a/tccpp.c b/tccpp.c
index 897ef15..9cba15a 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1726,6 +1726,7 @@ static void pragma_parse(TCCState *s1)
#pragma pack(1) // set
#pragma pack() // reset to default
#pragma pack(push,1) // push & set
+   #pragma pack(push) // push only
#pragma pack(pop) // restore previous */
 next();
 skip('(');
@@ -1744,6 +1745,8 @@ 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++;
+if (tok == ')')
+return;
 skip(',');
 }
 if (tok != TOK_CINT)
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel