[Bug c/100124] New: Why is "flexible array member '...' in an otherwise empty '...'" an issue?

2021-04-16 Thread gcc at behdad dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100124

Bug ID: 100124
   Summary: Why is "flexible array member '...' in an otherwise
empty '...'" an issue?
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gcc at behdad dot org
  Target Milestone: ---

Hi,

In HarfBuzz we extensively use the Struct Hack [0]. Up until now we've used
"array[1]" for that. This upsets ubsan [1]. So I'm looking to replace it with
flexible arrays on compilers that support it.

However, trying to do that I get error if the flexible-array is the only
member. Clang has no issues with it, but gcc gives me: "flexible array member
'...' in an otherwise empty '...'".


```
struct UnsignedArray {
  int array[];
};
```

I've seen:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69550
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71742

which suggests that disallowing flexible arrays in structs that have no other
named member is intentional. But I cannot find the reason. Can someone please
help me understand, and suggest a solution here?

Note that if I use `int array[0]` instead, then gcc warns everytime in code we
access that array with a constexpr value, like `array[0]` when we know it's
safe to do. That is, gcc seems to treat `int array[0]` literally, not as a
flexible array.

Thank you.


[0] http://c-faq.com/struct/structhack.html
[1] https://github.com/harfbuzz/harfbuzz/issues/2953

[Bug preprocessor/100125] New: -Wunused-macros generated while should be ignored; if undef is seen?

2021-04-16 Thread gcc at behdad dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100125

Bug ID: 100125
   Summary: -Wunused-macros generated while should be ignored; if
undef is seen?
   Product: gcc
   Version: 10.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: preprocessor
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gcc at behdad dot org
  Target Milestone: ---

We're facing this in HarfBuzz. I narrowed down the bug to this:

Works:

```c++
#pragma GCC diagnostic ignored "-Wunused-macros"

#define A B
```

$ g++ a.cc -c -Wunused-macros

(fine; no warning)

But if I add an `undef` to that file:

```c++
#pragma GCC diagnostic ignored "-Wunused-macros"

#define A B

#undef A
```

$ g++ a.cc -c -Wunused-macros
a.cc:3: warning: macros "A" is not used [-Wunused-macros]
3 | #define A B

Am I missing something?

[Bug c++/100124] Why is "flexible array member '...' in an otherwise empty '...'" an issue?

2021-04-20 Thread gcc at behdad dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100124

--- Comment #6 from Behdad Esfahbod  ---
Thank you all. I understand it's unlikely to happen at this point.


In reply to Andrew Pinski from comment #1)
> I will let someone comment on the flexible array extension.
> 
> But I will note GCC treats (all) arrays at the end of a POD struct as a
> flexible one so the question I have is more about the ubsan issue you are
> running into, is that with GCC or with clang/LLVM?

The ubsan issue reported to us is with gcc:
https://github.com/harfbuzz/harfbuzz/issues/2953#issuecomment-823460893

[Bug c++/100124] Why is "flexible array member '...' in an otherwise empty '...'" an issue?

2021-04-20 Thread gcc at behdad dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100124

--- Comment #8 from Behdad Esfahbod  ---
(In reply to Andrew Pinski from comment #7)
> 
> Can you report that as a bug as GCC's rule is treat all arrays that end a
> POD as a flexiable array?  Please include the full preprocessed source that
> produces the problem at runtime and the specific version of GCC that is
> used.  This is a GCC bug in mind due to this unless there is another field
> missing that is in the source that you are not showing.

Thanks. Will do after reproducing.