C++: Give names in structured binding declarations correct IR types

This commit is contained in:
Jeroen Ketema
2022-02-24 11:47:58 +01:00
parent 73f0366dc6
commit 5814349fd8
3 changed files with 36 additions and 20 deletions

View File

@@ -11,6 +11,15 @@ private Type getDecayedType(Type type) {
result.(PointerType).getBaseType() = type.(ArrayType).getBaseType()
}
/**
* Holds if the sepcified variable is a structured binding with a non-reference
* type.
*/
predicate isNonReferenceStructuredBinding(Variable v) {
v.isStructuredBinding() and
not v.getUnderlyingType() instanceof ReferenceType
}
/**
* Get the actual type of the specified variable, as opposed to the declared type.
* This returns the type of the variable after any pointer decay is applied, and
@@ -30,7 +39,10 @@ Type getVariableType(Variable v) {
result = v.getInitializer().getExpr().getType()
or
not exists(v.getInitializer()) and result = v.getType()
else result = v.getType()
else
if isNonReferenceStructuredBinding(v)
then exists(ReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
else result = v.getType()
)
}