public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102030] New: Optimization turns null ptr true
@ 2021-08-23 23:34 joeedh at gmail dot com
  2021-08-23 23:38 ` [Bug c/102030] " joeedh at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: joeedh at gmail dot com @ 2021-08-23 23:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102030
           Summary: Optimization turns null ptr true
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joeedh at gmail dot com
  Target Milestone: ---

Created attachment 51349
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51349&action=edit
save-temps output

System type: Linux Ubuntu.
GCC version: 10.3.0 and 9.3.1

I'm getting a weird error where a null pointer
is evaluating to true if optimizations are on.

For example

    printf("%p %s\n", ptr, ptr ? "true" : "false");

will print "(nil), true"

I had a fair number of users report the crash caused by
this bug.

Output of code when run:
  == without optimization ==
  1 ob: (nil), true
  2 ob: (nil), false
  3 ob: (nil), false
  4 ob: (nil), false
  ob! (nil)
  == with without optimization ==
  1 ob: (nil), false
  2 ob: (nil), false
  3 ob: (nil), false
  4 ob: (nil), false

Compiler command:

/usr/bin/gcc -save-temps -DNDEBUG -DWITH_ASSERT_ABORT -DWITH_FREESTYLE
-DWITH_GMP -DWITH_INTERNATIONAL -DWITH_OPENGL -D_FILE_OFFSET_BITS=64
-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D__LITTLE_ENDIAN__ -D__MMX__
-D__SSE2__ -D__SSE__ -I/home/joeedh/blender/blender/source/blender/bmesh
-I/home/joeedh/blender/blender/source/blender/blenkernel
-I/home/joeedh/blender/blender/source/blender/blenlib
-I/home/joeedh/blender/blender/source/blender/blentranslation
-I/home/joeedh/blender/blender/source/blender/depsgraph
-I/home/joeedh/blender/blender/source/blender/makesdna
-I/home/joeedh/blender/blender/intern/atomic
-I/home/joeedh/blender/blender/source/blender/blenloader
-I/home/joeedh/blender/blender/build/source/blender/makesdna/intern
-I/home/joeedh/blender/blender/intern/eigen
-I/home/joeedh/blender/blender/intern/clog
-I/home/joeedh/blender/blender/intern/guardedalloc
-I/home/joeedh/blender/blender/extern/rangetree -isystem
/home/joeedh/blender/lib/linux_centos7_x86_64/gmp/include -Wall -Wcast-align
-Werror=implicit-function-declaration -Werror=return-type -Werror=vla
-Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts
-Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings
-Wlogical-op -Wundef -Winit-self -Wmissing-include-dirs -Wno-div-by-zero
-Wtype-limits -Wformat-signedness -Wrestrict -Wnonnull -Wabsolute-value
-Wuninitialized -Wredundant-decls -Wshadow -Wno-error=unused-but-set-variable
-Wimplicit-fallthrough=5 -Wno-error=conversion -Wno-error=sign-conversion 
-fuse-ld=gold -std=gnu11 -msse -fPIC -funsigned-char -fno-strict-aliasing
-ffp-contract=off -msse2 -D_GLIBCXX_USE_CXX11_ABI=0
-fmacro-prefix-map="/home/joeedh/blender/blender/"=""
-fmacro-prefix-map="/home/joeedh/blender/blender/build/"=""
-Wno-maybe-uninitialized -O2 -g -DNDEBUG -fopenmp -save-temps -o
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c

Compiler Output:

In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:
In function ‘mempool_chunk_add’:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:260:17:
warning: unused variable ‘prev’ [-Wunused-variable]
  260 |   BLI_freenode *prev = NODE_STEP_PREV(curnode);
      |                 ^~~~
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:
In function ‘BLI_mempool_as_tableN’:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:648:61:
warning: unused parameter ‘allocstr’ [-Wunused-parameter]
  648 | oid **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr)
      |                                                ~~~~~~~~~~~~^~~~~~~~

/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:
In function ‘BLI_mempool_as_arrayN’:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:675:60:
warning: unused parameter ‘allocstr’ [-Wunused-parameter]
  675 | void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
      |                                                ~~~~~~~~~~~~^~~~~~~~
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:
In function ‘BLI_mempool_iterstep’:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:788:12:
warning: unused variable ‘freeword’ [-Wunused-variable]
  788 |   intptr_t freeword = 0;
      |            ^~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘CustomData_has_layer’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:109:51:
warning: unused parameter ‘cd’ [-Wunused-parameter]
  109 | bool CustomData_has_layer(const struct CustomData *cd, int type) {
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:109:59:
warning: unused parameter ‘type’ [-Wunused-parameter]
  109 | bool CustomData_has_layer(const struct CustomData *cd, int type) {
      |                                                       ~~~~^~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘CustomData_unmark_temporary_nocopy’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:113:53:
warning: unused parameter ‘cd’ [-Wunused-parameter]
  113 | void CustomData_unmark_temporary_nocopy(CustomData *cd) {
      |                                         ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘CustomData_mark_temporary_nocopy’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:116:51:
warning: unused parameter ‘cd’ [-Wunused-parameter]
  116 | void CustomData_mark_temporary_nocopy(CustomData *cd) {
      |                                       ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_mesh_create’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:122:57:
warning: passing argument 4 of ‘BLI_mempool_create’ makes integer from pointer
without a cast [-Wint-conversion]
  122 |  bm->vpool = BLI_mempool_create(sizeof(BMVert), 0, 512, "bm->vpool");
      |                                                         ^~~~~~~~~~~
      |                                                         |
      |                                                         const char *
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected ‘unsigned int’ but argument is of type ‘const char *’
  400 | BLI_mempool_create(uint esize, uint totelem, uint pchunk, uint flag)
      |                                                           ~~~~~^~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:123:57:
warning: passing argument 4 of ‘BLI_mempool_create’ makes integer from pointer
without a cast [-Wint-conversion]
  123 |  bm->epool = BLI_mempool_create(sizeof(BMEdge), 0, 512, "bm->epool");
      |                                                         ^~~~~~~~~~~
      |                                                         |
      |                                                         const char *
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected ‘unsigned int’ but argument is of type ‘const char *’
  400 | BLI_mempool_create(uint esize, uint totelem, uint pchunk, uint flag)
      |                                                           ~~~~~^~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:124:57:
warning: passing argument 4 of ‘BLI_mempool_create’ makes integer from pointer
without a cast [-Wint-conversion]
  124 |  bm->lpool = BLI_mempool_create(sizeof(BMLoop), 0, 512, "bm->lpool");
      |                                                         ^~~~~~~~~~~
      |                                                         |
      |                                                         const char *
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected ‘unsigned int’ but argument is of type ‘const char *’
  400 | BLI_mempool_create(uint esize, uint totelem, uint pchunk, uint flag)
      |                                                           ~~~~~^~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:125:57:
warning: passing argument 4 of ‘BLI_mempool_create’ makes integer from pointer
without a cast [-Wint-conversion]
  125 |  bm->fpool = BLI_mempool_create(sizeof(BMFace), 0, 512, "bm->fpool");
      |                                                         ^~~~~~~~~~~
      |                                                         |
      |                                                         const char *
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected ‘unsigned int’ but argument is of type ‘const char *’
  400 | BLI_mempool_create(uint esize, uint totelem, uint pchunk, uint flag)
      |                                                           ~~~~~^~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:119:53:
warning: unused parameter ‘template’ [-Wunused-parameter]
  119 | BMesh *BM_mesh_create(const struct BMAllocTemplate *template, const
struct BMeshCreateParams *params) {
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:119:95:
warning: unused parameter ‘params’ [-Wunused-parameter]
  119 | BMAllocTemplate *template, const struct BMeshCreateParams *params) {
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_data_layer_add’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:137:31:
warning: unused parameter ‘bm’ [-Wunused-parameter]
  137 | void BM_data_layer_add(BMesh *bm, CustomData *cd, int type) {
      |                        ~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:137:47:
warning: unused parameter ‘cd’ [-Wunused-parameter]
  137 | void BM_data_layer_add(BMesh *bm, CustomData *cd, int type) {
      |                                   ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:137:55:
warning: unused parameter ‘type’ [-Wunused-parameter]
  137 | void BM_data_layer_add(BMesh *bm, CustomData *cd, int type) {
      |                                                   ~~~~^~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_data_layer_free’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:140:32:
warning: unused parameter ‘bm’ [-Wunused-parameter]
  140 | void BM_data_layer_free(BMesh *bm, CustomData *cd, int type) {
      |                         ~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:140:48:
warning: unused parameter ‘cd’ [-Wunused-parameter]
  140 | void BM_data_layer_free(BMesh *bm, CustomData *cd, int type) {
      |                                    ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:140:56:
warning: unused parameter ‘type’ [-Wunused-parameter]
  140 | void BM_data_layer_free(BMesh *bm, CustomData *cd, int type) {
      |                                                    ~~~~^~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: At top
level:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:143:6:
warning: no previous prototype for ‘bm_init_idmap_layers’
[-Wmissing-prototypes]
  143 | void bm_init_idmap_layers(BMesh *bm) {
      |      ^~~~~~~~~~~~~~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘bm_init_idmap_layers’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:143:34:
warning: unused parameter ‘bm’ [-Wunused-parameter]
  143 | void bm_init_idmap_layers(BMesh *bm) {
      |                           ~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘get_multires_modifier’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:281:59:
warning: unused parameter ‘scene’ [-Wunused-parameter]
  281 | ultiresModifierData *get_multires_modifier(struct Scene *scene, Object
*ob, bool state) {
      |                                            ~~~~~~~~~~~~~~^~~~~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:281:74:
warning: unused parameter ‘ob’ [-Wunused-parameter]
  281 | Data *get_multires_modifier(struct Scene *scene, Object *ob, bool
state) {
      |                                                  ~~~~~~~~^~

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:281:82:
warning: unused parameter ‘state’ [-Wunused-parameter]
  281 | get_multires_modifier(struct Scene *scene, Object *ob, bool state) {

/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_mesh_bm_from_me’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:312:17:
warning: unused variable ‘i’ [-Wunused-variable]
  312 |   int totloops, i;
      |                 ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:312:7:
warning: unused variable ‘totloops’ [-Wunused-variable]
  312 |   int totloops, i;
      |       ^~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:311:10:
warning: unused variable ‘keyco’ [-Wunused-variable]
  311 |   float(*keyco)[3] = NULL;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:310:16:
warning: unused variable ‘ftable’ [-Wunused-variable]
  310 |   BMFace *f, **ftable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:310:11:
warning: unused variable ‘f’ [-Wunused-variable]
  310 |   BMFace *f, **ftable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:309:16:
warning: unused variable ‘etable’ [-Wunused-variable]
  309 |   BMEdge *e, **etable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:309:11:
warning: unused variable ‘e’ [-Wunused-variable]
  309 |   BMEdge *e, **etable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:308:16:
warning: unused variable ‘vtable’ [-Wunused-variable]
  308 |   BMVert *v, **vtable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:308:11:
warning: unused variable ‘v’ [-Wunused-variable]
  308 |   BMVert *v, **vtable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:307:22:
warning: unused variable ‘block’ [-Wunused-variable]
  307 |   KeyBlock *actkey, *block;
      |                      ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:307:13:
warning: unused variable ‘actkey’ [-Wunused-variable]
  307 |   KeyBlock *actkey, *block;
      |             ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:306:10:
warning: unused variable ‘mp’ [-Wunused-variable]
  306 |   MPoly *mp;
      |          ^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:305:10:
warning: unused variable ‘mloop’ [-Wunused-variable]
  305 |   MLoop *mloop;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:304:10:
warning: unused variable ‘medge’ [-Wunused-variable]
  304 |   MEdge *medge;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:303:10:
warning: unused variable ‘mvert’ [-Wunused-variable]
  303 |   MVert *mvert;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:301:13:
warning: unused variable ‘is_new’ [-Wunused-variable]
  301 |   const bool is_new = !(bm->totvert || (bm->vdata.totlayer ||
bm->edata.totlayer ||
      |             ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:298:37:
warning: unused parameter ‘me’ [-Wunused-parameter]
  298 |                         const Mesh *me,
      |                         ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: At top
level:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:374:38:
warning: no previous prototype for ‘BM_mesh_bm_from_me_no_opt’
[-Wmissing-prototypes]
  374 | ATTR_NO_OPT void BM_mesh_bm_from_me_no_opt(Object *ob,
      |                                      ^~~~~~~~~~~~~~~~~        
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_mesh_bm_from_me_no_opt’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:390:17:
warning: unused variable ‘i’ [-Wunused-variable]
  390 |   int totloops, i;
      |                 ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:390:7:
warning: unused variable ‘totloops’ [-Wunused-variable]
  390 |   int totloops, i;
      |       ^~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:389:10:
warning: unused variable ‘keyco’ [-Wunused-variable]
  389 |   float(*keyco)[3] = NULL;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:388:16:
warning: unused variable ‘ftable’ [-Wunused-variable]
  388 |   BMFace *f, **ftable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:388:11:
warning: unused variable ‘f’ [-Wunused-variable]
  388 |   BMFace *f, **ftable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:387:16:
warning: unused variable ‘etable’ [-Wunused-variable]
  387 |   BMEdge *e, **etable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:387:11:
warning: unused variable ‘e’ [-Wunused-variable]
  387 |   BMEdge *e, **etable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:386:16:
warning: unused variable ‘vtable’ [-Wunused-variable]
  386 |   BMVert *v, **vtable = NULL;
      |                ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:386:11:
warning: unused variable ‘v’ [-Wunused-variable]
  386 |   BMVert *v, **vtable = NULL;
      |           ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:385:22:
warning: unused variable ‘block’ [-Wunused-variable]
  385 |   KeyBlock *actkey, *block;
      |                      ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:385:13:
warning: unused variable ‘actkey’ [-Wunused-variable]
  385 |   KeyBlock *actkey, *block;
      |             ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:384:10:
warning: unused variable ‘mp’ [-Wunused-variable]
  384 |   MPoly *mp;
      |          ^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:383:10:
warning: unused variable ‘mloop’ [-Wunused-variable]
  383 |   MLoop *mloop;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:382:10:
warning: unused variable ‘medge’ [-Wunused-variable]
  382 |   MEdge *medge;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:381:10:
warning: unused variable ‘mvert’ [-Wunused-variable]
  381 |   MVert *mvert;
      |          ^~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:379:13:
warning: unused variable ‘is_new’ [-Wunused-variable]
  379 |   const bool is_new = !(bm->totvert || (bm->vdata.totlayer ||
bm->edata.totlayer ||
      |             ^~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:376:37:
warning: unused parameter ‘me’ [-Wunused-parameter]
  376 |                         const Mesh *me,
      |                         ~~~~~~~~~~~~^~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘main’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:462:2:
warning: null argument where non-null required (argument 1) [-Wnonnull]
  462 |  BM_mesh_bm_from_me(NULL, bm, me, &params);
      |  ^~~~~~~~~~~~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:440:14:
warning: unused parameter ‘argc’ [-Wunused-parameter]
  440 | int main(int argc, char **argv) {
      |          ~~~~^~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:440:27:
warning: unused parameter ‘argv’ [-Wunused-parameter]
  440 | int main(int argc, char **argv) {
      |                    ~~~~~~~^~~~
At top level:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:230:16:
warning: ‘bm_face_create_from_mpoly’ defined but not used [-Wunused-function]
  230 | static BMFace *bm_face_create_from_mpoly(
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:155:13:
warning: ‘bm_mark_temp_cdlayers’ defined but not used [-Wunused-function]
  155 | static void bm_mark_temp_cdlayers(BMesh *bm)
      |             ^~~~~~~~~~~~~~~~~~~~~
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
‘BM_mesh_bm_from_me’:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:357:6:
warning: ‘nonnull’ argument ‘ob’ compared to NULL [-Wnonnull-compare]
  357 |   if (ob) {
      |      ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:335:6:
warning: ‘nonnull’ argument ‘ob’ compared to NULL [-Wnonnull-compare]
  335 |   if (ob) {
      |      ^
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:320:3:
warning: ‘nonnull’ argument ‘ob’ compared to NULL [-Wnonnull-compare]
  320 |   printf("1 ob: %p, %s\n", ob, ob ? "true" : "false");
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/102030] Optimization turns null ptr true
  2021-08-23 23:34 [Bug c/102030] New: Optimization turns null ptr true joeedh at gmail dot com
@ 2021-08-23 23:38 ` joeedh at gmail dot com
  2021-08-24  1:41 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: joeedh at gmail dot com @ 2021-08-23 23:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Joe Eagar <joeedh at gmail dot com> ---
I forgot to add, the offending function is BM_mesh_bm_from_me:


void BM_mesh_bm_from_me(Object *ob,
                        BMesh *bm,
                        const Mesh *me,
                        const struct BMeshFromMeshParams *params)
{
  const bool is_new = !(bm->totvert || (bm->vdata.totlayer ||
bm->edata.totlayer ||
                                        bm->pdata.totlayer ||
bm->ldata.totlayer));
  MVert *mvert;
  MEdge *medge;
  MLoop *mloop;
  MPoly *mp;
  KeyBlock *actkey, *block;
  BMVert *v, **vtable = NULL;
  BMEdge *e, **etable = NULL;
  BMFace *f, **ftable = NULL;
  float(*keyco)[3] = NULL;
  int totloops, i;
  CustomData_MeshMasks mask = CD_MASK_BMESH;
  CustomData_MeshMasks_update(&mask, &params->cd_mask_extra);

  if (params->copy_temp_cdlayers) {
    bm_unmark_temp_cdlayers(bm);
  }

  printf("1 ob: %p, %s\n", ob, ob ? "true" : "false");
  fflush(stdout);

  printf("2 ob: %p, %s\n", ob, NULL ? "true" : "false");
  fflush(stdout);

  printf("3 ob: %p, %s\n", ob, ((Object*)NULL) ? "true" : "false");
  fflush(stdout);

  printf("4 ob: %p, %s\n", ob, ((Object*)0) ? "true" : "false");  
  fflush(stdout);

  MultiresModifierData *mmd;
  if (ob) {
        mmd = get_multires_modifier(NULL, ob, true);
  } else {
        mmd = NULL;
  }

  if (params->copy_temp_cdlayers) {
    mask.vmask |= CD_MASK_MESH_ID;
    mask.emask |= CD_MASK_MESH_ID;
    mask.lmask |= CD_MASK_MESH_ID;
    mask.pmask |= CD_MASK_MESH_ID;
  }

  if (mmd) {
    bm->multires = *mmd;
    bm->haveMultiResSettings = true;
    bm->multiresSpace = MULTIRES_SPACE_TANGENT;
  }
  else {
    bm->haveMultiResSettings = false;
  }

  if (ob) {
        printf("ob! %p\n", ob);
  }
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/102030] Optimization turns null ptr true
  2021-08-23 23:34 [Bug c/102030] New: Optimization turns null ptr true joeedh at gmail dot com
  2021-08-23 23:38 ` [Bug c/102030] " joeedh at gmail dot com
@ 2021-08-24  1:41 ` pinskia at gcc dot gnu.org
  2021-08-24  1:45 ` pinskia at gcc dot gnu.org
  2021-08-27  3:21 ` joeedh at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-24  1:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With -W -Wall I get the following warnings:
In file included from
/home/joeedh/blender/blender/intern/atomic/atomic_ops.h:138,
                 from
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:35,
                 from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h: In function
'atomic_cas_ptr':
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:180:52:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:180:71:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h: In function
'atomic_cas_float':
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:192:52:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:192:71:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:193:11:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h: In function
'atomic_add_and_fetch_fl':
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:204:49:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:204:73:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/intern/atomic/intern/atomic_ops_ext.h:205:44:
warning: dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
'BM_mesh_create':
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:122:57:
warning: passing argument 4 of 'BLI_mempool_create' makes integer from pointer
without a cast [-Wint-conversion]
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected 'unsigned int' but argument is of type 'char *'
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:123:57:
warning: passing argument 4 of 'BLI_mempool_create' makes integer from pointer
without a cast [-Wint-conversion]
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected 'unsigned int' but argument is of type 'char *'
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:124:57:
warning: passing argument 4 of 'BLI_mempool_create' makes integer from pointer
without a cast [-Wint-conversion]
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected 'unsigned int' but argument is of type 'char *'
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:125:57:
warning: passing argument 4 of 'BLI_mempool_create' makes integer from pointer
without a cast [-Wint-conversion]
In file included from
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:106:
/home/joeedh/blender/blender/build/../source/blender/blenlib/intern/BLI_mempool.c:400:77:
note: expected 'unsigned int' but argument is of type 'char *'
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
'main':
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:462:2:
warning: null argument where non-null required (argument 1) [-Wnonnull]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
'BM_mesh_bm_from_me':
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:357:6:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:335:6:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:320:3:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/102030] Optimization turns null ptr true
  2021-08-23 23:34 [Bug c/102030] New: Optimization turns null ptr true joeedh at gmail dot com
  2021-08-23 23:38 ` [Bug c/102030] " joeedh at gmail dot com
  2021-08-24  1:41 ` pinskia at gcc dot gnu.org
@ 2021-08-24  1:45 ` pinskia at gcc dot gnu.org
  2021-08-27  3:21 ` joeedh at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-24  1:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
BM_mesh_bm_from_me has the nonnull attribute on it for ob saying if ob is a
null argument passed to it undefined behavior will happen.  So obviously it
will remove the comparisons.

These warnings here:
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c: In function
'BM_mesh_bm_from_me':
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:357:6:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:335:6:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]
/home/joeedh/blender/blender/build/bmesh_mesh_convert_bugreport.c:320:3:
warning: 'nonnull' argument 'ob' compared to NULL [-Wnonnull-compare]

Are the important ones to pay attention to.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/102030] Optimization turns null ptr true
  2021-08-23 23:34 [Bug c/102030] New: Optimization turns null ptr true joeedh at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-24  1:45 ` pinskia at gcc dot gnu.org
@ 2021-08-27  3:21 ` joeedh at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: joeedh at gmail dot com @ 2021-08-27  3:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Joe Eagar <joeedh at gmail dot com> ---
I hadn't realized the nonnull attribute is 1-based.  That makes sense.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-27  3:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 23:34 [Bug c/102030] New: Optimization turns null ptr true joeedh at gmail dot com
2021-08-23 23:38 ` [Bug c/102030] " joeedh at gmail dot com
2021-08-24  1:41 ` pinskia at gcc dot gnu.org
2021-08-24  1:45 ` pinskia at gcc dot gnu.org
2021-08-27  3:21 ` joeedh at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).