diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-11-10 18:59:31 +0100 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2023-11-10 19:01:45 +0100 |
commit | 0f02e744ca1ea3256f912dbeb965ead3b5c9f66f (patch) | |
tree | 9f335a55fb91dc8ca5fe890840a3a554883746db /gcc/testsuite/gnat.dg | |
parent | df66fa08578a28b3acc8bdb6257b68c245a6a0fa (diff) | |
download | gcc-0f02e744ca1ea3256f912dbeb965ead3b5c9f66f.zip gcc-0f02e744ca1ea3256f912dbeb965ead3b5c9f66f.tar.gz gcc-0f02e744ca1ea3256f912dbeb965ead3b5c9f66f.tar.bz2 |
Handle constant CONSTRUCTORs in operand_compare
This teaches operand_compare to compare constant CONSTRUCTORs, which is
quite helpful for so-called fat pointers in Ada, i.e. objects that are
semantically pointers but are represented by structures made up of two
pointers. This is modeled on the implementation present in the ICF pass.
gcc/
* fold-const.cc (operand_compare::operand_equal_p) <CONSTRUCTOR>:
Deal with nonempty constant CONSTRUCTORs.
(operand_compare::hash_operand) <CONSTRUCTOR>: Hash DECL_FIELD_OFFSET
and DECL_FIELD_BIT_OFFSET for FIELD_DECLs.
gcc/testsuite/
* gnat.dg/opt103.ads, gnat.dg/opt103.adb: New test.
Diffstat (limited to 'gcc/testsuite/gnat.dg')
-rw-r--r-- | gcc/testsuite/gnat.dg/opt103.adb | 39 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/opt103.ads | 12 |
2 files changed, 51 insertions, 0 deletions
diff --git a/gcc/testsuite/gnat.dg/opt103.adb b/gcc/testsuite/gnat.dg/opt103.adb new file mode 100644 index 0000000..8509fa3 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt103.adb @@ -0,0 +1,39 @@ +-- { dg-do compile } +-- { dg-options "-O -gnatn -fdump-tree-optimized" } + +package body Opt103 is + + function Read return Mode is + S : String := Get; + M : Mode; + + begin + -- There should be a single call to Value_Enumeration_Pos after inlining + + if Mode'Valid_Value (S) then + M := Mode'Value (S); + else + raise Program_Error; + end if; + + return M; + end; + + function Translate (S : String) return Mode is + M : Mode; + + begin + -- There should be a single call to Value_Enumeration_Pos after inlining + + if Mode'Valid_Value (S) then + M := Mode'Value (S); + else + raise Program_Error; + end if; + + return M; + end; + +end Opt103; + +-- { dg-final { scan-tree-dump-times ".value_enumeration_pos" 2 "optimized" } } diff --git a/gcc/testsuite/gnat.dg/opt103.ads b/gcc/testsuite/gnat.dg/opt103.ads new file mode 100644 index 0000000..97608bb --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt103.ads @@ -0,0 +1,12 @@ +package Opt103 is + + type Mode is (Stop, Forward, Backward, Up, Down); + + function Get return String; + pragma Import (Ada, Get); + + function Read return Mode; + + function Translate (S : String) return Mode; + +end Opt103; |