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

Compiling with gcc 11.2 triggers nonnull error #272

Open
jonasdn opened this issue Sep 20, 2021 · 0 comments · May be fixed by #273
Open

Compiling with gcc 11.2 triggers nonnull error #272

jonasdn opened this issue Sep 20, 2021 · 0 comments · May be fixed by #273

Comments

@jonasdn
Copy link

jonasdn commented Sep 20, 2021

Using Fedora 34 (gcc 11.2) to compile gives the following spat:

CXX src/vp.cpp
In file included from /home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/trace/component_trace.hpp:26,
                 from /home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/component.hpp:37,
                 from /home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/vp_data.hpp:26,
                 from /home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/vp.hpp:26,
                 from src/vp.cpp:27:
src/vp.cpp: In member function ‘js::config* vp::component::get_vp_config()’:
/home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/trace/trace.hpp:119:40: error: ‘this’ pointer is null [-Werror=nonnull]
  119 |       ((vp::trace *)(trace_ptr))->fatal(msg);      \
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
src/vp.cpp:241:5: note: in expansion of macro ‘vp_assert_always’
  241 |     vp_assert_always(this->vp_config != NULL, NULL, "No VP config found\n");
      |     ^~~~~~~~~~~~~~~~
In file included from /home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/vp.hpp:28,
                 from src/vp.cpp:27:
/home/jonasdn/sandbox/gap_sdk/install/workstation/include/vp/trace/implementation.hpp:112:15: note: in a call to non-static member function ‘void vp::trace::fatal(const char*, ...)’
  112 |   inline void vp::trace::fatal(const char *fmt, ...)
      |               ^~
cc1plus: all warnings being treated as errors
make[3]: *** [Makefile:63: /home/jonasdn/sandbox/gap_sdk/build/gvsoc/engine/vp.o] Error 1
make[3]: Leaving directory '/home/jonasdn/sandbox/gap_sdk/gvsoc/gvsoc/engine'
make[2]: *** [Makefile:25: build] Error 2
make[2]: Leaving directory '/home/jonasdn/sandbox/gap_sdk/gvsoc/gvsoc'
make[1]: *** [Makefile:303: gvsoc.build] Error 2
make[1]: Leaving directory '/home/jonasdn/sandbox/gap_sdk'
make: *** [Makefile:144: gvsoc] Error 2

It seems that the compiler is not convinced this macro is safe:

#define vp_assert_always(cond, trace_ptr, msg...)  \
  if (!(cond)) {                                   \
    if (trace_ptr != NULL)                                 \
      ((vp::trace *)(trace_ptr))->fatal(msg);      \
    else                                           \
    {                                              \
      fprintf(stdout, "ASSERT FAILED: %s", msg);   \
      abort();                                     \
    }                                              \
  }

When called for instance by:

js::config *vp::component::get_vp_config()
{
    if (this->vp_config == NULL)
    {
        if (this->parent != NULL)
        {
            this->vp_config = this->parent->get_vp_config();
        }
    }

    vp_assert_always(this->vp_config != NULL, NULL, "No VP config found\n");

    return this->vp_config;
}

I could not seem to find the magic steps to convince it to allow this.

jonasdn added a commit to jonasdn/gap_sdk that referenced this issue Sep 20, 2021
The gcc 11.2 version seemst to be more aggresive in nonnull checks.

Fixes: GreenWaves-Technologies#272
@jonasdn jonasdn linked a pull request Sep 20, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant