Skip to content

Commit c54128e

Browse files
committed
C++: Fix obtaining the base type of a VLA
1 parent f79fcaa commit c54128e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,8 +4185,18 @@ class TranslatedSizeofExpr extends TranslatedNonConstantExpr {
41854185

41864186
override string getInstructionConstantValue(InstructionTag tag) {
41874187
tag = SizeofVlaDimensionTag(-1) and
4188-
result =
4189-
getBaseType(vlaDeclStmt.getVariable().getUnderlyingType(), vlaDimensions).getSize().toString()
4188+
result = this.getVlaBaseType(vlaDeclStmt).getSize().toString()
4189+
}
4190+
4191+
private Type getVlaBaseType(VlaDeclStmt v) {
4192+
not exists(getParentVlaDecl(v)) and
4193+
(
4194+
result = getBaseType(v.getVariable().getUnderlyingType(), v.getNumberOfVlaDimensionStmts())
4195+
or
4196+
result = getBaseType(v.getType().getUnderlyingType(), v.getNumberOfVlaDimensionStmts())
4197+
)
4198+
or
4199+
result = this.getVlaBaseType(getParentVlaDecl(v))
41904200
}
41914201

41924202
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20589,7 +20589,7 @@ ir.cpp:
2058920589
# 2807| m2807_2(long[][][]) = Uninitialized[tmp] : &:r2807_1
2059020590
# 2807| v2807_3(void) = NoOp :
2059120591
# 2808| r2808_1(glval<unsigned long>) = VariableAddress[#return] :
20592-
# 2808| r2808_2(unsigned long) = Constant :
20592+
# 2808| r2808_2(unsigned long) = Constant[8] :
2059320593
# 2808| r2808_3(unsigned long) = Mul : r2808_2, r2802_2
2059420594
# 2808| r2808_4(unsigned long) = Mul : r2808_3, r2802_4
2059520595
# 2808| m2808_5(unsigned long) = Store[#return] : &:r2808_1, r2808_4

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18732,7 +18732,7 @@ ir.cpp:
1873218732
# 2807| mu2807_2(long[][][]) = Uninitialized[tmp] : &:r2807_1
1873318733
# 2807| v2807_3(void) = NoOp :
1873418734
# 2808| r2808_1(glval<unsigned long>) = VariableAddress[#return] :
18735-
# 2808| r2808_2(unsigned long) = Constant :
18735+
# 2808| r2808_2(unsigned long) = Constant[8] :
1873618736
# 2808| r2808_3(unsigned long) = Mul : r2808_2, r2802_2
1873718737
# 2808| r2808_4(unsigned long) = Mul : r2808_3, r2802_4
1873818738
# 2808| mu2808_5(unsigned long) = Store[#return] : &:r2808_1, r2808_4

0 commit comments

Comments
 (0)