User account creation filtered due to spam.

Bug 81812 - [7/8 Regression] Empty virtual function fails to compile
Summary: [7/8 Regression] Empty virtual function fails to compile
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 7.1.1
: P3 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2017-08-10 22:40 UTC by Ben Woodard
Modified: 2017-08-28 19:47 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work: 6.4.0
Known to fail: 7.1.1, 8.0
Last reconfirmed: 2017-08-11 00:00:00


Attachments
Prototype patch (340 bytes, patch)
2017-08-11 04:50 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Woodard 2017-08-10 22:40:05 UTC
-95 ~]$ cat testg++.C
#include <stdio.h>
class Error {
public:
  virtual void error( int, int, const char *, ... ) const;
};

void Error::error(int a, int b, const char * c, ...) const {

}

class ChildNode : public virtual Error {
public:
  void error( int, int, const char *, ... ) const;
};

void ChildNode::error( int, int, const char *, ... ) const
{
  // Uncomment leads to succesful compelation. 
  //printf("hello world");
}

int main () {}
[ben@li392-95 ~]$ g++ testg++.C -O2 -o testg++
testg++.C:22:14: error: generic thunk code fails for method ‘virtual void ChildNode::_ZTv0_n24_NK9ChildNode5errorEiiPKcz(int, int, const char*, ...) const’ which uses ‘...’
 int main () {}
              ^
While if you compile with -O0 it compiles fine.
Comment 1 Andrew Pinski 2017-08-10 22:42:24 UTC
Which target is this on?
Comment 2 Ben Woodard 2017-08-10 22:45:35 UTC
Uncommenting the printf allows it to compile.
This showed up on F26 x86_64 compiling MRNet
Comment 3 Jonathan Wakely 2017-08-11 00:01:26 UTC
Confirmed. Reduced (define FIX to fix the failure):

struct Error {
  virtual void error(... ) const;
};

struct ChildNode : virtual Error {
  void error(... ) const;
};

void ext(const char*, ...);

void ChildNode::error(...) const
{
#ifdef FIX
  ext("");
#endif
}

b.cc:16:1: error: generic thunk code fails for method ‘virtual void ChildNode::_ZTv0_n24_NK9ChildNode5errorEz(...) const’ which uses ‘...’
 }
 ^
Comment 4 Jason Merrill 2017-08-11 04:50:33 UTC
Created attachment 41969 [details]
Prototype patch

The issue here is that because the function is empty, GCC decides that we want to inline it into all callers, which then fails because we can't generate a gimple thunk.  This patch avoids trying to inline virtual varargs functions into all callers, but I expect it isn't quite the right fix.