From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id F2BAC385840D for ; Fri, 17 Sep 2021 19:26:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F2BAC385840D Received: by mail-ot1-x32d.google.com with SMTP id y63-20020a9d22c5000000b005453f95356cso7351084ota.11 for ; Fri, 17 Sep 2021 12:26:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oyLbbel5TTDotAczC/YddAP6v13E7/pkjUc7tzqWxok=; b=UJzIKV2ZuYe7v0GTv0iiHJmnN136gwgWPAkytafC+wdYkJ1yjqW38HGxtRB7XmJjWT AaadV9b94vXJ4elBxuQBMGdpyqA+WD3z0GEy4i1VW602v1ndm6m0NETrXzHU/QCqBJ93 Kww6/J3AxdjXWy4lQpOJwyvmIx01Rl59rxQarNqnyD/omK22Zeo/7thhb1oFyaf2St8O yV604dvzZEPODE8EylQf+04V0YSzjTp2e8ByjxGQbleQORZ0rjDt6T91xXBh5Rx24E/G Gwm9TUOqjgn3aHWPTbLJYdQrdelgHkFpJptcFp2Fr1RxSAKRbcPxJD7iJA3TudIEyoL2 mBCQ== X-Gm-Message-State: AOAM5323q1UPxKQBsa+UEgLNUfiXOM4eqvHFdlIk9TCTgxKMrfGlPaYp ye5Qikd2kHY5VyYFLRFpcPDLDMBB7n0= X-Google-Smtp-Source: ABdhPJwOVlJH8yLmvETmy8ZdOK7fXuoKDXwGXGQlVVeH4f2panVa8g2H472idsXlO6u0D/liHzRk4w== X-Received: by 2002:a05:6830:4084:: with SMTP id x4mr10668144ott.280.1631906779174; Fri, 17 Sep 2021 12:26:19 -0700 (PDT) Received: from [192.168.0.41] (97-118-96-133.hlrn.qwest.net. [97.118.96.133]) by smtp.gmail.com with ESMTPSA id y26sm1760421oih.2.2021.09.17.12.26.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Sep 2021 12:26:18 -0700 (PDT) Subject: Re: nvtpx: error: array subscript -1 is below array bounds of 'short int [2][16]' To: Jan-Benedict Glaw , gcc@gcc.gnu.org Cc: Tom de Vries References: <20210904191017.2dqr6cxwedrt5bsg@lug-owl.de> From: Martin Sebor Message-ID: <1953bae3-6fd7-b960-c61d-fc55a465c9d1@gmail.com> Date: Fri, 17 Sep 2021 13:26:18 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20210904191017.2dqr6cxwedrt5bsg@lug-owl.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Sep 2021 19:26:21 -0000 On 9/4/21 1:10 PM, Jan-Benedict Glaw wrote: > Hi! > > Running automated tests again, I found that when building current > (2fcfc03459a907c0237ea6e2c6e4ce4871034bed) GCC with a recent GCC, a > build (make all-gcc) when ./configure'ed for -target=nvptx-none > --enable-werror-always --enable-languages=all --disable-gcov > --disable-shared --disable-threads --without-headers fails with: I was able to reproduce the warning. The IL that triggers it is below: [local count: 64737]: _1504 = MEM[(const struct rtx_def *)dreg_1461].u.reg.regno; dregno_1505 = (int) _1504; _1506 = (long unsigned int) dregno_1505; _1507 = _1506 * 2; _1508 = reg_renumber.845_1499 + _1507; _1509 = default_target_ira.x_ira_class_hard_regs[dclass.380_1481][0]; dclass.380_1481 is an SSA_NAME in the range int [-INF, -1], so the warning is working as designed. dclass' type is enum reg_class which is defined like so: emum enum reg_class { NO_REGS, ALL_REGS, LIM_REG_CLASSES }; GCC treats it as signed despite it having no negative enumerators, and somehow infers its range as negative. Since (if) none of its values can be negative as I suspect, defining it as unsigned should help: emum enum reg_class: unsigned { NO_REGS, ALL_REGS, LIM_REG_CLASSES }; And, in fact, it does avoid the warning. I haven't done any other testing with this change but I'd expect it to also improve codegen by letting GCC eliminate what's probably unreachable code (which the warning might then be issued for). You didn't say what you're looking for but I would suggest to start by opening a bug in Bugzilla, attaching the preprocessed translation unit for lra-constraints.c, and referencing this discussion. To get it fixed quickly I'd try testing (and, if successful, submitting) the enum change above. Another, more targeted solution, the change above isn't safe, is to add asserting above the uses of the dclass and sclass variables as indices that they're not negative, e.g., like so: if (dclass < 0) gcc_unreachable (); Martin > [all 2021-09-04 16:33:59] /usr/lib/gcc-snapshot/bin/g++ -fno-PIE -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include -I../../gcc/gcc/../libcody -I../../gcc/gcc/../libdecnumber -I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/gcc/../libbacktrace -o lra-constraints.o -MT lra-constraints.o -MMD -MP -MF ./.deps/lra-constraints.TPo ../../gcc/gcc/lra-constraints.c > [all 2021-09-04 16:34:07] In function 'bool check_and_process_move(bool*, bool*)', > [all 2021-09-04 16:34:07] inlined from 'bool curr_insn_transform(bool)' at ../../gcc/gcc/lra-constraints.c:4092:33: > [all 2021-09-04 16:34:07] ../../gcc/gcc/lra-constraints.c:1317:56: error: array subscript -1 is below array bounds of 'short int [2][16]' [-Werror=array-bounds] > [all 2021-09-04 16:34:07] 1317 | reg_renumber[dregno] = ira_class_hard_regs[dclass][0]; > [all 2021-09-04 16:34:07] In file included from ../../gcc/gcc/lra-constraints.c:123: > [all 2021-09-04 16:34:07] ../../gcc/gcc/ira.h: In function 'bool curr_insn_transform(bool)': > [all 2021-09-04 16:34:07] ../../gcc/gcc/ira.h:85:9: note: while referencing 'target_ira::x_ira_class_hard_regs' > [all 2021-09-04 16:34:07] 85 | short x_ira_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER]; > [all 2021-09-04 16:34:07] | ^~~~~~~~~~~~~~~~~~~~~ > [all 2021-09-04 16:34:07] In function 'bool check_and_process_move(bool*, bool*)', > [all 2021-09-04 16:34:07] inlined from 'bool curr_insn_transform(bool)' at ../../gcc/gcc/lra-constraints.c:4092:33: > [all 2021-09-04 16:34:07] ../../gcc/gcc/lra-constraints.c:1324:56: error: array subscript -1 is below array bounds of 'short int [2][16]' [-Werror=array-bounds] > [all 2021-09-04 16:34:07] 1324 | reg_renumber[sregno] = ira_class_hard_regs[sclass][0]; > [all 2021-09-04 16:34:07] In file included from ../../gcc/gcc/lra-constraints.c:123: > [all 2021-09-04 16:34:07] ../../gcc/gcc/ira.h: In function 'bool curr_insn_transform(bool)': > [all 2021-09-04 16:34:07] ../../gcc/gcc/ira.h:85:9: note: while referencing 'target_ira::x_ira_class_hard_regs' > [all 2021-09-04 16:34:07] 85 | short x_ira_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER]; > [all 2021-09-04 16:34:07] | ^~~~~~~~~~~~~~~~~~~~~ > [all 2021-09-04 16:34:13] cc1plus: all warnings being treated as errors > [all 2021-09-04 16:34:13] make[1]: *** [Makefile:1142: lra-constraints.o] Error 1 > [all 2021-09-04 16:34:13] make[1]: Leaving directory '/var/lib/laminar/run/gcc-nvptx-none/5/toolchain-build/gcc' > [all 2021-09-04 16:34:13] make: *** [Makefile:4407: all-gcc] Error 2 > > Thanks, > Jan-Benedict >