@@ -1906,8 +1906,10 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
1906
1906
final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
1907
1907
resultType = getTypeForPRValue ( expr .getAllocator ( ) .getParameter ( 0 ) .getType ( ) ) and
1908
1908
(
1909
+ this .extentNeedsConversion ( ) and
1909
1910
// Convert the extent to `size_t`, because the AST doesn't do this already.
1910
- tag = AllocationExtentConvertTag ( ) and opcode instanceof Opcode:: Convert
1911
+ tag = AllocationExtentConvertTag ( ) and
1912
+ opcode instanceof Opcode:: Convert
1911
1913
or
1912
1914
tag = AllocationElementSizeTag ( ) and opcode instanceof Opcode:: Constant
1913
1915
or
@@ -1918,6 +1920,7 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
1918
1920
final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
1919
1921
kind instanceof GotoEdge and
1920
1922
(
1923
+ this .extentNeedsConversion ( ) and
1921
1924
tag = AllocationExtentConvertTag ( ) and
1922
1925
result = this .getInstruction ( AllocationElementSizeTag ( ) )
1923
1926
or
@@ -1933,7 +1936,9 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
1933
1936
1934
1937
final override Instruction getChildSuccessor ( TranslatedElement child ) {
1935
1938
child = this .getExtent ( ) and
1936
- result = this .getInstruction ( AllocationExtentConvertTag ( ) )
1939
+ if this .extentNeedsConversion ( )
1940
+ then result = this .getInstruction ( AllocationExtentConvertTag ( ) )
1941
+ else result = this .getInstruction ( AllocationElementSizeTag ( ) )
1937
1942
}
1938
1943
1939
1944
final override string getInstructionConstantValue ( InstructionTag tag ) {
@@ -1945,18 +1950,32 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
1945
1950
tag = AllocationSizeTag ( ) and
1946
1951
(
1947
1952
operandTag instanceof LeftOperandTag and
1948
- result = this .getInstruction ( AllocationExtentConvertTag ( ) )
1953
+ (
1954
+ if this .extentNeedsConversion ( )
1955
+ then result = this .getInstruction ( AllocationExtentConvertTag ( ) )
1956
+ else result = this .getExtent ( ) .getResult ( )
1957
+ )
1949
1958
or
1950
1959
operandTag instanceof RightOperandTag and
1951
1960
result = this .getInstruction ( AllocationElementSizeTag ( ) )
1952
1961
)
1953
1962
or
1963
+ this .extentNeedsConversion ( ) and
1954
1964
tag = AllocationExtentConvertTag ( ) and
1955
1965
operandTag instanceof UnaryOperandTag and
1956
1966
result = this .getExtent ( ) .getResult ( )
1957
1967
}
1958
1968
1959
1969
TranslatedExpr getExtent ( ) { result = getTranslatedExpr ( expr .getExtent ( ) .getFullyConverted ( ) ) }
1970
+
1971
+ /**
1972
+ * Holds if the result of `expr.getExtent()` does not have the same type as
1973
+ * the allocator's size parameter.
1974
+ */
1975
+ private predicate extentNeedsConversion ( ) {
1976
+ expr .getExtent ( ) .getFullyConverted ( ) .getUnspecifiedType ( ) !=
1977
+ expr .getAllocator ( ) .getParameter ( 0 ) .getUnspecifiedType ( )
1978
+ }
1960
1979
}
1961
1980
1962
1981
/**
0 commit comments