[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-09-13 Thread aldyh at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #12 from Aldy Hernandez  ---
Author: aldyh
Date: Wed Sep 13 16:20:27 2017
New Revision: 252253

URL: https://gcc.gnu.org/viewcvs?rev=252253=gcc=rev
Log:
PR c/81448
PR c/81306
* c-warn.c (warn_for_multistatement_macros): Prevent bogus
warnings.  Avoid walking MACRO_MAP_LOCATIONS.   

* c-c++-common/Wmultistatement-macros-13.c: New test.

Added:
branches/range-gen2/gcc/testsuite/c-c++-common/Wmultistatement-macros-13.c
Modified:
branches/range-gen2/gcc/c-family/c-warn.c
branches/range-gen2/gcc/c/ChangeLog
branches/range-gen2/gcc/testsuite/ChangeLog

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-08-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #11 from Marek Polacek  ---
Cool, thanks for confirming.

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-08-02 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #10 from Bernd Edlinger  ---
Confirmed.
Thanks!

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-08-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Marek Polacek  ---
Hopefully fixed.

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-08-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #8 from Marek Polacek  ---
Author: mpolacek
Date: Wed Aug  2 11:56:54 2017
New Revision: 250822

URL: https://gcc.gnu.org/viewcvs?rev=250822=gcc=rev
Log:
PR c/81448
PR c/81306
* c-warn.c (warn_for_multistatement_macros): Prevent bogus
warnings.  Avoid walking MACRO_MAP_LOCATIONS.   

* c-c++-common/Wmultistatement-macros-13.c: New test.

Added:
trunk/gcc/testsuite/c-c++-common/Wmultistatement-macros-13.c
Modified:
trunk/gcc/c-family/c-warn.c
trunk/gcc/c/ChangeLog
trunk/gcc/testsuite/ChangeLog

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-07-26
 Ever confirmed|0   |1

--- Comment #7 from Marek Polacek  ---
I think this is a real bug now:

void baz (void);

#define FOO for (int i = 0; i < 10; i++)

#define BAR \
void bar (void) \
{   \
  FOO   \
baz (); \
  return;   \
}

BAR

the warning is fooled because the "body" (baz();) and "next" are coming from
the same expansion, and "guard" isn't.

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-25 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #6 from Bernd Edlinger  ---
(In reply to Marek Polacek from comment #5)
> PR81364 is fixed, do you still see any false positives?

Well adding braces would fix the warning,
but consider this slightly reduced test case:

void b_ecb_encrypt();

#define BLOCK_CIPHER_ecb_loop() \
int i, bl; \
bl = 100; \
if (inl < bl) return 1; \
inl -= bl; \
for (i=0; i <= inl; i+=bl)

#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
int cname##_ecb_cipher(char *out, char *in, int inl) \
{ \
  BLOCK_CIPHER_ecb_loop() \
cprefix##_ecb_encrypt(in + i, out + i); \
  return 1; \
}

BLOCK_CIPHER_func_ecb(a,b,c,d)

int test(unsigned char *out, const unsigned char *in, int inl)
{
  BLOCK_CIPHER_ecb_loop()
b_ecb_encrypt(in + i, out + i);
  return 1;
}


Why is the warning only in the macro expansion
and not in explicit instantiation ?

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-25 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #5 from Marek Polacek  ---
PR81364 is fixed, do you still see any false positives?

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-14 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #4 from Bernd Edlinger  ---
(In reply to Marek Polacek from comment #3)
> Guess we'll need the PR81364 fix for that.

Yes, although it would be good to require
a "{" only if cprefix##_ecb_encrypt(...) actually expands
to multiple stmts, if it expands to single stmt as here
BLOCK_CIPHER_ecb_loop() would be usable like for(;;)

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #3 from Marek Polacek  ---
Guess we'll need the PR81364 fix for that.

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-14 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

--- Comment #2 from Bernd Edlinger  ---
Not really:

diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h
index 2bb709a..cb44ed8 100644
--- a/crypto/evp/evp_locl.h
+++ b/crypto/evp/evp_locl.h
@@ -71,8 +71,9 @@
 #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
 static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const
unsigned char *in, size_t inl) \
 {\
-BLOCK_CIPHER_ecb_loop() \
+BLOCK_CIPHER_ecb_loop() { \
 cprefix##_ecb_encrypt(in + i, out + i, &((kstruct
*)ctx->cipher_data)->ksched, ctx->encrypt);\
+} \
 return 1;\
 }

In file included from e_bf.c:63:0:
e_bf.c: In function 'bf_ecb_cipher':
evp_locl.h:74:33: error: macro expands to multiple statements
[-Werror=multistatement-macros]
 BLOCK_CIPHER_ecb_loop() { \
 ^
evp_locl.h:132:9: note: in expansion of macro 'BLOCK_CIPHER_func_ecb'
 BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
 ^
evp_locl.h:251:9: note: in expansion of macro 'BLOCK_CIPHER_all_funcs'
 BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
 ^~
e_bf.c:76:1: note: in expansion of macro 'IMPLEMENT_BLOCK_CIPHER'
 IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
 ^~
evp_locl.h:69:9: note: some parts of macro expansion are not guarded by this
'for' clause
 for(i=0; i <= inl; i+=bl)
 ^~~
evp_locl.h:74:9: note: in expansion of macro 'BLOCK_CIPHER_ecb_loop'
 BLOCK_CIPHER_ecb_loop() { \
 ^
evp_locl.h:132:9: note: in expansion of macro 'BLOCK_CIPHER_func_ecb'
 BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
 ^
evp_locl.h:251:9: note: in expansion of macro 'BLOCK_CIPHER_all_funcs'
 BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
 ^~
e_bf.c:76:1: note: in expansion of macro 'IMPLEMENT_BLOCK_CIPHER'
 IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
 ^~

[Bug c/81448] False positive -Werror=multistatement-macros in openssl

2017-07-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81448

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek  ---
To me it seems the warning is doing what it should here, simply wrapping the
body of the for loop into {} should fix it.