Menu

#4 Subtype compatibility check of an implicitly converted universal integer not performed during dynamic elaboration

1.0
closed
None
2013-12-28
2013-12-23
No

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity tb_test0 is end;

architecture arch_tb of tb_test0 is
signal i_s : integer := -1;
--
signal v_s : unsigned(7 downto 0);

begin
-- Here it won't have any error during simulation, but it should
v_s <= to_unsigned(i_s, 8);
--
end architecture arch_tb;

david_koontz@Macbook: ghdl -a tb_test0.vhdl
david_koontz@Macbook: ghdl -e tb_test0
david_koontz@Macbook: ghdl -r tb_test0
david_koontz@Macbook: ghdl --version
GHDL 0.31dev (20132311) [Dunoon edition]
Compiled with GNAT Version: GPL 2013 (20130314)
GCC back-end code generator
Written by Tristan Gingold.

This is a noncompliant VHDL design description (yet it ran without error):

From numeric_std:

-- Id: D.3
function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED;
-- Result subtype: UNSIGNED(SIZE-1 downto 0)
-- Result: Converts a non-negative INTEGER to an UNSIGNED vector with
-- the specified SIZE.

Section 3
Types

...
A type is characterized by a set of values and a set of operations. The set of operations of a type includes the explicitly declared subprograms that have a parameter or result of the type. The remaining operations of a type are the basic operations and the predefined operators (see 7.2 ). These operations are each implicitly declared for a given type declaration immediately after the type declaration and before the next explicit declaration, if any.

A basic operation is an operation that is inherent in one of the following:

-- An assignment (in assignment statements and initializations)

-- An allocator

-- A selected name, an indexed name, or a slice name

-- A qualification (in a qualified expression), an explicit type conversion, a formal or actual part in the form of a type conversion, or an implicit type conversion of a value of type universal_integer or universal_real to the corresponding value of another numeric type


The implicit type conversion of universal integer to natural should fail.


7.3.5 Type conversions

...

If the type mark denotes a subtype, conversion consists of conversion to the target type followed by a check that the result of the conversion belongs to the subtype.

...

In certain cases, an implicit type conversion will be performed. An implicit conversion of an operand of type universal_integer to another integer type, or of an operand of type universal_real to another floating point type, can only be applied if the operand is either a numeric literal or an attribute, or if the operand is an expression consisting of the division of a value of a physical type by a value of the same type; such an operand is called a convertible universal operand. An implicit conversion of a convertible universal operand is applied if and only if the innermost complete context determines a unique (numeric) target type for the implicit conversion, and there is no legal interpretation of this context without this conversion.


So the check that the result of the conversion belongs to the subtype isn't performed. (And this is a run time check).

(And there is no TO_UNSIGNED (ARG: INTEGER; SIZE: INTEGER/NATURAL) defined in package numeric_std, leaving no legal interpretation without implicit conversion. The inner most context is defined by the interface declaration used for the association list for the arguments to TO_UNSIGNED.)

Further, during simulation of the equivalent process statement for the offending concurrent signal assignment statement, the TO_UNSIGNED subprogram call involves the elaboration of the parameter interface list of corresponding subprogram declaration (See 12.5 Dynamic elaboration).

Discussion

  • Brian Drummond

    Brian Drummond - 2013-12-23

    How does this differ from ticket 2 other than the reduced testcase?

     
  • Tristan Gingold

    Tristan Gingold - 2013-12-27

    Also I agree this test should fail, there is no issue with the implicit conversion.

    The implicit conversion converts universal integer -1 to integer, which is correct.

    I haven't yet found the reference for the check during call.

     
  • Tristan Gingold

    Tristan Gingold - 2013-12-27

    Ok, that's 2.1.1.1:

    it is an error if, after applying any conversion function or type conversion present in the actual part of the applicable association element (see 4.3.2.2), the value of the actual parameter does not belong to the subtype denoted by the subtype indication of the formal. After completion of the subprogram body, if the mode is inout or out, the value of the formal parameter is copied back into the associated actual parameter; it is similarly an error if, after applying any conversion function or type conversion present in the formal part of the applicable association element, the value of the formal parameter does not belong to the subtype denoted by the subtype indication of the actual.

     
  • Tristan Gingold

    Tristan Gingold - 2013-12-28

    As ticket #2 is closed, I close this ticket. This is indeed a reduced test case of #2.

     
  • Tristan Gingold

    Tristan Gingold - 2013-12-28
    • status: open --> closed
    • assigned_to: Tristan Gingold
     

Log in to post a comment.