This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] detect incompatible aliases (PR c/81854)


On 08/18/2017 10:48 AM, Jonathan Wakely wrote:
On 18/08/17 08:54 -0600, Martin Sebor wrote:
On 08/18/2017 07:10 AM, Jonathan Wakely wrote:
On 17/08/17 21:21 -0600, Martin Sebor wrote:
Joseph, while looking into implementing enhancement your request
pr81824 I noticed that GCC silently accepts incompatible alias
declarations (pr81854) so as sort of a proof-concept for the
former I enhanced the checking already done for other kinds of
incompatibilities to also detect those mentioned in the latter
bug.  Attached is this patch, tested on x85_64-linux.

Jonathan, the patch requires suppressing the warning in libstdc++
compatibility symbol definitions in compatibility.cc.  I couldn't
find a way to do it without the suppression but I'd be happy to
try again if you have an idea for how.

Doing it that way is fine, but ...

diff --git a/libstdc++-v3/src/c++98/compatibility.cc
b/libstdc++-v3/src/c++98/compatibility.cc
index 381f4c4..5f56b9e 100644
--- a/libstdc++-v3/src/c++98/compatibility.cc
+++ b/libstdc++-v3/src/c++98/compatibility.cc
@@ -213,6 +213,11 @@
_ZNSt19istreambuf_iteratorIcSt11char_traitsIcEEppEv
_ZNSt19istreambuf_iteratorIwSt11char_traitsIwEEppEv
*/

+// Disable warning about declaring aliases between functions with
+// incompatible types.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wattributes"
+

Could this be moved closer to the point where it's needed?

It's not needed until after line 361, right?

Sure.  The other possibility that I forgot to mention is to
declare the alias without a prototype, which in C++ looks
like this:

 void foo (...);

The patch would then look like this.  Do you have a preference
between these two approaches?

If this doesn't change the generated code, but avoids the warnings
then I think I prefer this. i.e. fix the code, not just suppress the
warnings.

It's the same as calling a function without a prototype in C.
I rebuilt libstdc++ with this change and reran the test suite
with no unexpected failures so I'll go ahead and commit this
change instead.

To be clear, though, this is just a suppression mechanism not
unlike a cast.  The ideal solution would be to declare the
aliases to have the right type, e.g., using __typeof__ or
decltype.  I just couldn't find a way to make it work with
the macros.

Martin



Martin

diff --git a/libstdc++-v3/src/c++98/compatibility.cc
b/libstdc++-v3/src/c++98/compatibility.cc
index 381f4c4..b49a5ca 100644
--- a/libstdc++-v3/src/c++98/compatibility.cc
+++ b/libstdc++-v3/src/c++98/compatibility.cc
@@ -367,13 +367,13 @@ _GLIBCXX_END_NAMESPACE_VERSION

#define _GLIBCXX_3_4_SYMVER(XXname, name) \
   extern "C" void \
-   _X##name() \
+   _X##name(...) \
   __attribute__ ((alias(#XXname))); \
   asm (".symver " "_X" #name "," #name "@GLIBCXX_3.4");

#define _GLIBCXX_3_4_5_SYMVER(XXname, name) \
   extern "C" void \
-   _Y##name() \
+   _Y##name(...) \
   __attribute__ ((alias(#XXname))); \
   asm (".symver " "_Y" #name  "," #name "@@GLIBCXX_3.4.5");




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]