https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83954

            Bug ID: 83954
           Summary: LTO: Bogus -Wlto-type-mismatch warning for pointer to
                    incomplete type
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic, lto
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dobonachea at lbl dot gov
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu
             Build: x86_64-pc-linux-gnu

Created attachment 43198
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43198&action=edit
Source code and preprocessed output

I'm seeing bogus -Wlto-type-mismatch warnings in C for an array of pointers to
incomplete type with gcc 7.2.0 -flto.

Source files (also attached):

==> lto.h <==
struct foo;
extern struct foo *FOO_PTR;
extern struct foo *FOO_PTR_ARR[1];
extern int        *INT_PTR_ARR[1];

==> lto1.c <==
#include "lto.h"

int main() { 
  // just to prevent symbol removal
  FOO_PTR = 0;
  FOO_PTR_ARR[1] = 0;
  return 0;
}

==> lto2.c <==
#include "lto.h"

struct foo {
 int x;
};
struct foo *FOO_PTR = 0;
struct foo *FOO_PTR_ARR[1] = { 0 };
int        *INT_PTR_ARR[1] = { 0 };

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/pkg/gcc/7.2.0/libexec/gcc/x86_64-pc-linux-gnu/7.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/pkg/gcc/7.2.0
Thread model: posix
gcc version 7.2.0 (GCC) 

$ uname -a
Linux <redacted> 3.10.0-693.1.1.el7.x86_64 #1 SMP Tue Aug 15 08:36:44 CDT 2017
x86_64 x86_64 x86_64 GNU/Linux

$  gcc -pedantic -flto -fuse-linker-plugin lto1.c lto2.c
lto.h:3:20: warning: type of 'FOO_PTR_ARR' does not match original declaration
[-Wlto-type-mismatch]
 extern struct foo *FOO_PTR_ARR[1];
                    ^
lto2.c:7:13: note: 'FOO_PTR_ARR' was previously declared here
 struct foo *FOO_PTR_ARR[1] = { 0 };
             ^
lto2.c:7:13: note: code may be misoptimized unless -fno-strict-aliasing is used

Note the warning only occurs for the array-of-pointer-to-incomplete-type, and
not for the analogous pointer-to-incomplete-type or array-of-pointer-to-int.

Reply via email to