[Bug inline-asm/97667] New: a bug in asm_operand_ok() recog.c:1801

2020-11-01 Thread huntazhang at tencent dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97667

Bug ID: 97667
   Summary: a bug in asm_operand_ok() recog.c:1801
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: inline-asm
  Assignee: unassigned at gcc dot gnu.org
  Reporter: huntazhang at tencent dot com
  Target Milestone: ---

when i used gcc-11.0 compile linux kernel in
arch/x86/include/asm/checksum_64.h:171 trigger a bug 

here is compile source code argurment 
gcc -Wp,-MMD,net/core/.utils.o.d  -nostdinc -isystem
/usr/lib/gcc/x86_64-linux-gnu/11.0.0/include -I../arch/x86/include
-I./arch/x86/include/generated -I../include -I./include
-I../arch/x86/include/uapi -I./arch/x86/include/generated/uapi
-I../include/uapi -I./include/generated/uapi -include
../include/linux/kconfig.h -include ../include/linux/compiler_types.h
-D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs
-fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE
-Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type
-Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
-m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387
-mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone
-mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables
-mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables
-fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation
-Wno-format-overflow -Wno-address-of-packed-member -O2
-fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong
-Wno-unused-but-set-variable -Wimplicit-fallthrough -Wno-unused-const-variable
-fomit-frame-pointer -Wdeclaration-after-statement -Wvla -Wno-pointer-sign
-Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds
-Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized
-fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time
-Werror=incompatible-pointer-types -Werror=designated-init
-fmacro-prefix-map=../= -fcf-protection=none -Wno-packed-not-aligned -I
../net/core -I ./net/core-DKBUILD_MODFILE='"net/core/utils"'
-DKBUILD_BASENAME='"utils"' -DKBUILD_MODNAME='"utils"' -c -o net/core/utils.o
../net/core/utils.c

here is gcc configure:

# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --enable-languages=c,c++ --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --build=x86_64-linux-gnu --enable-multilib
--enable-pugin --prefix=/usr
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20201027 (experimental) (GCC) 

here is trigger  bug source code :
static inline unsigned add32_with_carry(unsigned a, unsigned b)
{
asm("addl %2,%0\n\t"
"adcl $0,%0"
: "=r" (a)
: "0" (a), "rm" (b));
return a;
}

gcc-11.0 combine inline-asm 

(insn 43 84 44 5 (parallel [
(set (reg:SI 126 [ a ])
(asm_operands:SI ("addl %2,%0
adcl $0,%0") ("=r") 0 [
(reg:SI 126 [ a ])
(not:SI (mem/j:SI (plus:DI (reg/v/f:DI 108 [ skb ])
(const_int 136 [0x88])) [169
skb_7(D)->D.41008.csum+0 S4 A64]))
]
 [
(asm_input:SI ("0")
../arch/x86/include/asm/checksum_64.h:171)
(asm_input:SI ("rm")
../arch/x86/include/asm/checksum_64.h:171)
]
 [] ../arch/x86/include/asm/checksum_64.h:171))
(clobber (reg:CC 17 flags))
]) "../arch/x86/include/asm/checksum_64.h":171:2 -1
 (expr_list:REG_UNUSED (reg:CC 17 flags)
(nil)))

gcc-10 combine inline-asm 

(insn 43 84 44 5 (parallel [
(set (reg:SI 126 [ a ])
(asm_operands:SI ("addl %2,%0
adcl $0,%0") ("=r") 0 [
(reg:SI 126 [ a ])
(reg:SI 127)
]
 [
(asm_input:SI ("0")
../arch/x86/include/asm/checksum_64.h:171)
(asm_input:SI ("rm")
../arch/x86/include/asm/checksum_64.h:171)
]
 [] ../arch/x86/include/asm/checksum_64.h:171))
(clobber (reg:CC 17 flags))
]) "../arch/x86/include/asm/checksum_64.h":171:2 -1
 (expr_list:REG_DEAD (reg:SI 127)
(expr_list:REG_UNUSED (reg:CC 17 flags)
(nil


the difference between gcc10 and gcc 11 in asm_operand_ok() recog.c 

gcc-11 is 
case CT_MEMORY:
case CT_SPECIAL_MEMORY:
  /* Every memory operand can be reloaded to fit.  */
  result = result || memory_operand (extract_mem_from_operand (op),
 

[Bug inline-asm/97667] [11 Regression] a bug in asm_operand_ok() recog.c:1801

2020-11-02 Thread huntazhang at tencent dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97667

--- Comment #5 from huntazhang  ---
YES DUP.

[Bug middle-end/102037] New: False positive in -Warray-bounds

2021-08-24 Thread huntazhang at tencent dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102037

Bug ID: 102037
   Summary: False positive in -Warray-bounds
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: middle-end
  Assignee: unassigned at gcc dot gnu.org
  Reporter: huntazhang at tencent dot com
  Target Milestone: ---

Created attachment 51351
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51351&action=edit
test code

[root@VM-209-165-centos ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --enable-language=c,c++ --prefix=/usr
--program-suffix=-12 --program-prefix=x86_64-linux-gnu --enable-plugin
--disable-multilib --build=x86_64-linux-gnu --target=x86_64-linux-gnu
--enable-vtable-verify --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210823 (experimental) (GCC) 
[root@VM-209-165-centos ~]# gcc -O2 -Wall array-bound-index.c 
In function 'rdfs8',
inlined from 'main' at array-bound-index.c:13:2:
array-bound-index.c:7:9: warning: array subscript 0 is outside array bounds of
'u8[0]' {aka 'unsigned char[]'} [-Warray-bounds]
7 | asm volatile("movb %%fs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));

here is my debug log 
Breakpoint 1, compute_objsize_r (ptr=0x774593a8, ostype=0,
pref=0x7fffd730, snlim=..., qry=0x7fffd5f0) at
../../gcc/pointer-query.cc:1587
1587  STRIP_NOPS (ptr);
(gdb) p debug(ptr)
1160B
$2 = void
(gdb) n
1589  const bool addr = TREE_CODE (ptr) == ADDR_EXPR;
(gdb) 
1590  if (addr)
(gdb) n
1596  if (DECL_P (ptr))
(gdb) n
1621  const tree_code code = TREE_CODE (ptr);
(gdb) n
1622  range_query *const rvals = qry ? qry->rvals : NULL;
(gdb) n
1624  if (code == BIT_FIELD_REF)
(gdb) 
1635  if (code == COMPONENT_REF)
(gdb) n
1702  if (code == ARRAY_REF)
(gdb) 
1705  if (code == MEM_REF)
(gdb) 
1708  if (code == TARGET_MEM_REF)
(gdb) 
1720  if (code == INTEGER_CST)
(gdb) 
1726  if (integer_zerop (ptr))
(gdb) n
1729pref->sizrng[0] = pref->sizrng[1] = 0;
(gdb) p gimple_debug_cfg(TDF_DETAILS)

;; Function main (main, funcdef_no=1, decl_uid=1948, cgraph_uid=2,
symbol_order=1) (executed once)

;; 
3 basic blocks, 2 edges, last basic block 3.

;; basic block 2, loop depth 0, count 1073741824 (estimated locally), maybe hot
;;  prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)
;;  pred:   ENTRY [always]  count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)
;;  succ:   EXIT [always]  count:1073741824 (estimated locally)
(EXECUTABLE)

int main ()
{
  u8 v;

;;   basic block 2, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;;prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)
;;pred:   ENTRY [always]  count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)
  __asm__ __volatile__("movb %%fs:%1,%0" : "=q" v_2 : "m" MEM[(u8 *)1160B]);
  return 0;
;;succ:   EXIT [always]  count:1073741824 (estimated locally)
(EXECUTABLE)

}


$3 = void
(gdb) p debug(ptr)
1160B
$4 = void
(gdb) frame 1
#1  0x0126212c in handle_mem_ref (mref=0x77475168, ostype=0,
pref=0x7fffd730, snlim=..., qry=0x7fffd5f0) at
../../gcc/pointer-query.cc:1551
1551  if (!compute_objsize_r (mrefop, ostype, pref, snlim, qry))
(gdb) p debug(mref)
MEM[(u8 *)1160B]
$5 = void
(gdb)