Add a field for arrays of unknown bound
The ABI tools do not diff the array length. They cannot distinguish between arrays of unknown bound (e.g., int foo[]) and arrays of zero length (e.g., int bar[0]). To implement array diff, this commit adds "is_of_unknown_bound" field to the ABI dumps. It defaults to false so that it can be omitted for common cases. Test: ./test.py ; update prebuilts/clang-tools and build Bug: 255702405 Change-Id: I5db163eb62e95fa01377ef7202e70cc2a0e89524
This commit is contained in:
@@ -385,6 +385,7 @@ TypeAndCreationStatus ABIWrapper::SetTypeKind(
|
||||
}
|
||||
if (type_ptr->isArrayType()) {
|
||||
auto array_type_ir = std::make_unique<repr::ArrayTypeIR>();
|
||||
array_type_ir->SetUnknownBound(type_ptr->isIncompleteArrayType());
|
||||
array_type_ir->SetSourceFile(source_file);
|
||||
return TypeAndCreationStatus(std::move(array_type_ir));
|
||||
}
|
||||
|
||||
@@ -508,9 +508,18 @@ class EnumTypeIR : public TypeIR {
|
||||
|
||||
class ArrayTypeIR : public TypeIR {
|
||||
public:
|
||||
void SetUnknownBound(bool is_of_unknown_bound) {
|
||||
is_of_unknown_bound_ = is_of_unknown_bound;
|
||||
}
|
||||
|
||||
bool IsOfUnknownBound() const { return is_of_unknown_bound_; }
|
||||
|
||||
LinkableMessageKind GetKind() const override {
|
||||
return LinkableMessageKind::ArrayTypeKind;
|
||||
}
|
||||
|
||||
private:
|
||||
bool is_of_unknown_bound_ = false;
|
||||
};
|
||||
|
||||
class PointerTypeIR : public TypeIR {
|
||||
|
||||
@@ -29,11 +29,6 @@ inline std::string GetReferencedTypeMapKey(T &element) {
|
||||
return element.GetReferencedType();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string GetReferencedTypeMapKey<ArrayTypeIR>(ArrayTypeIR &element) {
|
||||
return element.GetReferencedType() + ":" + std::to_string(element.GetSize());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string GetReferencedTypeMapKey<BuiltinTypeIR>(
|
||||
BuiltinTypeIR &element) {
|
||||
@@ -44,6 +39,12 @@ inline static std::string BoolToString(bool val) {
|
||||
return val ? "true" : "false";
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string GetReferencedTypeMapKey<ArrayTypeIR>(ArrayTypeIR &element) {
|
||||
return element.GetReferencedType() + ":" + std::to_string(element.GetSize()) +
|
||||
":" + BoolToString(element.IsOfUnknownBound());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string GetReferencedTypeMapKey<QualifiedTypeIR>(
|
||||
QualifiedTypeIR &element) {
|
||||
|
||||
@@ -265,6 +265,7 @@ IRToJsonConverter::ConvertBuiltinTypeIR(const BuiltinTypeIR *builtin_typep) {
|
||||
JsonObject
|
||||
IRToJsonConverter::ConvertArrayTypeIR(const ArrayTypeIR *array_typep) {
|
||||
JsonObject array_type;
|
||||
array_type.Set("is_of_unknown_bound", array_typep->IsOfUnknownBound());
|
||||
AddTypeInfo(array_type, array_typep);
|
||||
return array_type;
|
||||
}
|
||||
|
||||
@@ -355,6 +355,7 @@ void JsonIRReader::ReadArrayTypes(const JsonObjectRef &tu) {
|
||||
for (auto &&array_type : tu.GetObjects("array_types")) {
|
||||
ArrayTypeIR array_type_ir;
|
||||
ReadTypeInfo(array_type, &array_type_ir);
|
||||
array_type_ir.SetUnknownBound(array_type.GetBool("is_of_unknown_bound"));
|
||||
module_->AddArrayType(std::move(array_type_ir));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ abi_dump::BuiltinType IRToProtobufConverter::ConvertBuiltinTypeIR(
|
||||
abi_dump::ArrayType IRToProtobufConverter::ConvertArrayTypeIR(
|
||||
const ArrayTypeIR *array_typep) {
|
||||
abi_dump::ArrayType added_array_type;
|
||||
added_array_type.set_is_of_unknown_bound(array_typep->IsOfUnknownBound());
|
||||
if (!AddTypeInfo(added_array_type.mutable_type_info(), array_typep)) {
|
||||
llvm::errs() << "ArrayTypeIR could not be converted\n";
|
||||
::exit(1);
|
||||
|
||||
@@ -245,6 +245,7 @@ void ProtobufIRReader::ReadArrayTypes(const abi_dump::TranslationUnit &tu) {
|
||||
for (auto &&array_type_protobuf : tu.array_types()) {
|
||||
ArrayTypeIR array_type_ir;
|
||||
ReadTypeInfo(array_type_protobuf.type_info(), &array_type_ir);
|
||||
array_type_ir.SetUnknownBound(array_type_protobuf.is_of_unknown_bound());
|
||||
module_->AddArrayType(std::move(array_type_ir));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ message BasicNamedAndTypedDecl {
|
||||
|
||||
message ArrayType {
|
||||
optional BasicNamedAndTypedDecl type_info = 1;
|
||||
optional bool is_of_unknown_bound = 2;
|
||||
}
|
||||
|
||||
message PointerType {
|
||||
|
||||
@@ -798,6 +798,7 @@ array_types {
|
||||
linker_set_key: "_ZTIA2_b"
|
||||
self_type: "_ZTIA2_b"
|
||||
}
|
||||
is_of_unknown_bound: false
|
||||
}
|
||||
functions {
|
||||
return_type: "_ZTI4ListIfE"
|
||||
|
||||
@@ -878,6 +878,7 @@ array_types {
|
||||
linker_set_key: "_ZTIA2_b"
|
||||
self_type: "_ZTIA2_b"
|
||||
}
|
||||
is_of_unknown_bound: false
|
||||
}
|
||||
functions {
|
||||
return_type: "_ZTIi"
|
||||
|
||||
@@ -355,6 +355,7 @@ array_types {
|
||||
linker_set_key: "_ZTIA2_b"
|
||||
self_type: "_ZTIA2_b"
|
||||
}
|
||||
is_of_unknown_bound: false
|
||||
}
|
||||
functions {
|
||||
return_type: "_ZTIi"
|
||||
|
||||
Reference in New Issue
Block a user