Bug 81812 - [7/8 Regression] Empty virtual function fails to compile
Summary: [7/8 Regression] Empty virtual function fails to compile
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 7.1.1
: P2 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: 2018-03-05 08:40 UTC (History)
8 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.
Comment 5 Jan Hubicka 2017-11-19 16:23:31 UTC
I think we should just mark such thunks as not inlinable in compute_fn_summary. PPatch is OK with that change.

Thanks!
Honza
Comment 6 Paolo Carlini 2018-01-18 20:43:13 UTC
Looks like this is fixed for 8 and I'd like to updated the bug to reflect that and possibly add the testcase. Any idea which change fixed it and whether could be backported to 7?
Comment 7 Richard Biener 2018-01-25 08:21:30 UTC
GCC 7.3 is being released, adjusting target milestone.
Comment 8 Jan Hubicka 2018-02-01 14:33:39 UTC
Martin,
I seem to recall that this was related to icf trying to merge variadic function. Would it be possible to work out the patch that fixed this?
Comment 9 Paolo Carlini 2018-03-02 17:57:52 UTC
This works in 7.3.0 too. I'm going to add the testcase and close the bug.
Comment 10 paolo@gcc.gnu.org 2018-03-02 18:07:15 UTC
Author: paolo
Date: Fri Mar  2 18:06:44 2018
New Revision: 258150

URL: https://gcc.gnu.org/viewcvs?rev=258150&root=gcc&view=rev
Log:
2018-03-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81812
	* g++.dg/torture/pr81812.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr81812.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 11 Paolo Carlini 2018-03-02 18:19:06 UTC
Done.