[Ada] Spurious condition warning on type conversion in return

Message ID 20200619082834.GA31364@adacore.com
State New
Headers show
  • [Ada] Spurious condition warning on type conversion in return
Related show

Commit Message

Pierre-Marie de Rodat June 19, 2020, 8:28 a.m.
This patch fixes the compiler whereby a conversion to Interfaces.C.Bool
within a return statement may cause a spurious "condition always X"

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-19  Justin Squirek  <squirek@adacore.com>


	* sem_warn.adb (Warn_On_Known_Condition): Add general sanity
	check that asserts the original source node being checked
	contains an entity. If not, it could be the result of special
	case expansion for type conversions.


--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -3520,6 +3520,7 @@  package body Sem_Warn is
       if Constant_Condition_Warnings
         and then Is_Known_Branch
         and then Comes_From_Source (Orig)
+        and then Nkind (Orig) in N_Has_Entity
         and then not In_Instance
          --  Don't warn if comparison of result of attribute against a constant