Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] g++ 14 -Wnonnull triggered when compiling with -O2 #1134

Closed
DyXel opened this issue Jun 22, 2024 · 3 comments
Closed

[BUG] g++ 14 -Wnonnull triggered when compiling with -O2 #1134

DyXel opened this issue Jun 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@DyXel
Copy link
Contributor

DyXel commented Jun 22, 2024

Describe the bug
Title. This is a pretty weird one, I am not sure why it only happens when compiling with optimizations.

To Reproduce
Steps to reproduce the behavior:

  1. Compile with: /usr/bin/g++ -std=c++20 -Wall -Wextra -pedantic -Werror -O2 -I./include/ -o cppfront.exe source/cppfront.cpp
  2. Output:
In file included from source/to_cpp1.h:21,
                 from source/cppfront.cpp:18:
source/sema.h: In member function ‘bool cpp2::sema::check(const cpp2::parameter_declaration_node&)’:
source/sema.h:1485:68: error: ‘this’ pointer is null [-Werror=nonnull]
 1485 |             type_name = n.declaration->get_object_type()->to_string();
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from reflect.h2:18,
                 from source/sema.h:21:
source/parse.h:1299:10: note: in a call to non-static member function ‘std::string cpp2::type_id_node::to_string() const’
 1299 |     auto to_string() const
      |          ^~~~~~~~~
cc1plus: all warnings being treated as errors

Additional context
It could be a false-positive, but I haven't analyzed the code yet.

@DyXel DyXel added the bug Something isn't working label Jun 22, 2024
@hsutter
Copy link
Owner

hsutter commented Jun 22, 2024

Thanks! Fixed, or at least "silenced." As I mentioned in the commit: The warning is silenced by adding an assert(not-null). That assertion doesn't get triggered by any of the regression tests, but GCC could be reporting a real latent issue, and if so now with the assert we'll get a nice trackable ICE if we ever do encounter a source file that triggers a problem.

@DyXel
Copy link
Contributor Author

DyXel commented Jun 22, 2024

Perfect! By the way, feel free to ignore these newer issues if there are older more important ones, I am reporting what I encounter as I write regular-ish code, there's still a few more I need to open, but they aren't super high priority.

@hsutter
Copy link
Owner

hsutter commented Jun 22, 2024

feel free to ignore these newer issues

Thanks, understood, but in practice when I can't keep up (which has been a lot of the past year) I tend to at least try to stay abreast of the more current ones. And if I can knock out small ones like this one I can reduce the remaining pile by some amount, and most ICEs are easy to resolve (which I can usually just repro in the debugger to find a stray bad dereference or one of the simpler assertion failure) and helps stability. So I do try to do that kind of report a little more responsively. Again, thanks.

MarekKnapek pushed a commit to MarekKnapek/cppfront that referenced this issue Jul 4, 2024
Adding `assert(object_type);` silences a null-dereference warning when compiling cppfront on GCC 14 using -Werror=nonnull -O2 (both switches together)

Running all regression tests doesn't fire the assertion, but it's good hygiene to have it there anyway. GCC could be diagnosing a real error that I don't see, and that happens not to be exercised by the regression tests. At least now with the assertion we'll get a clear ICE to track down, if we ever do encounter a source file where it does fire.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants