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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Haoxin Tu from comment #3)
> I see. Are there any cases that can trigger the UB of nonnull-attribute? I
> doubt the usage of “-fsanitize=nonnull-attribute” in GCC...

Yes, just use the attribute correctly.

Using:

__attribute__((nonnull)) void has_nonnull_argument(int *p) { 
     ; 
}

will cause UBsan to diagnose it:

nn.cc:7:25: runtime error: null pointer passed as argument 1, which is declared
to never be null

Reply via email to