From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Steve Baird <baird@adacore.com>
Subject: [Ada] Avoid unwanted warnings for statically-known-successful assertions
Date: Mon, 4 Jul 2022 07:50:12 +0000 [thread overview]
Message-ID: <20220704075012.GA99099@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 768 bytes --]
The -gnatwc switch enables warnings for test condition outcomes that are
known at compile time. Such warnings are unlikely to be useful in the
case of an assertion expression (or a subexpression thereof), so do not
generate them in that case.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_warn.adb (Warn_On_Constant_Valid_Condition): Do not
generate a warning if the expression in question is an assertion
expression, or a subexpression thereof. But do call
Test_Comparison so that it can generate warnings for the cases
that it generates warnings for.
* sem_prag.ads: Modify Assertion_Expression_Pragma constant so
that the predicate Sem_Util.In_Assertion_Expression_Pragma
returns True for the expression of a Compile_Time_Error pragma.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1281 bytes --]
diff --git a/gcc/ada/sem_prag.ads b/gcc/ada/sem_prag.ads
--- a/gcc/ada/sem_prag.ads
+++ b/gcc/ada/sem_prag.ads
@@ -135,6 +135,7 @@ package Sem_Prag is
Pragma_Assert_And_Cut => True,
Pragma_Assume => True,
Pragma_Check => True,
+ Pragma_Compile_Time_Error => True,
Pragma_Contract_Cases => True,
Pragma_Default_Initial_Condition => True,
Pragma_Initial_Condition => True,
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -3401,9 +3401,14 @@ package body Sem_Warn is
False_Result => False_Result);
-- Warn on a possible evaluation to False / True in the presence of
- -- invalid values.
+ -- invalid values. But issue no warning for an assertion expression
+ -- (or a subexpression thereof); in particular, we don't want a
+ -- warning about an assertion that will always succeed.
- if True_Result then
+ if In_Assertion_Expression_Pragma (Op) then
+ null;
+
+ elsif True_Result then
Error_Msg_N
("condition can only be False if invalid values present?c?", Op);
reply other threads:[~2022-07-04 7:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220704075012.GA99099@adacore.com \
--to=derodat@adacore.com \
--cc=baird@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).