Fix incorrect public object access specifiers.

Bug: 78184573

Test: tests/test.py

Merged-In: I9cf5df612322eb66e9a46450d7f43c99586dbab6
Change-Id: I9cf5df612322eb66e9a46450d7f43c99586dbab6
(cherry picked from commit 9c569ce793)
This commit is contained in:
Jayant Chowdhary
2018-04-16 14:54:40 -07:00
parent 6fb5c38bdd
commit 81d6b6cc35
7 changed files with 38 additions and 9 deletions

View File

@@ -894,6 +894,7 @@ bool GlobalVarDeclWrapper::SetupGlobalVar(
global_varp->SetSourceFile(source_file);
global_varp->SetName(global_var_decl_->getQualifiedNameAsString());
global_varp->SetLinkerSetKey(mangled_name);
global_varp->SetAccess(AccessClangToIR(global_var_decl_->getAccess()));
global_varp->SetReferencedType(
ast_caches_->GetTypeId(GetKeyForTypeId(global_var_decl_->getType())));
return true;

View File

@@ -95,6 +95,10 @@ static bool ShouldSkipFunctionDecl(const clang::FunctionDecl *decl) {
if (!decl->getDefinition()) {
return true;
}
if (decl->getLinkageAndVisibility().getLinkage() !=
clang::Linkage::ExternalLinkage) {
return true;
}
if (const clang::CXXMethodDecl *method_decl =
llvm::dyn_cast<clang::CXXMethodDecl>(decl)) {
if (method_decl->getParent()->getTypeForDecl()->isDependentType()) {

View File

@@ -259,8 +259,8 @@ class CXXBaseSpecifierIR : public ReferencesOtherType {
}
protected:
bool is_virtual_;
AccessSpecifierIR access_;
bool is_virtual_ = false;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
};
class TemplateElementIR : public ReferencesOtherType {
@@ -334,7 +334,7 @@ class RecordFieldIR : public ReferencesOtherType {
protected:
std::string name_;
uint64_t offset_ = 0;
AccessSpecifierIR access_;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
};
class RecordTypeIR: public TypeIR, public TemplatedArtifactIR,
@@ -420,8 +420,8 @@ class RecordTypeIR: public TypeIR, public TemplatedArtifactIR,
std::vector<RecordFieldIR> fields_;
VTableLayoutIR vtable_layout_;
std::vector<CXXBaseSpecifierIR> bases_;
AccessSpecifierIR access_;
bool is_anonymous_;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
bool is_anonymous_ = false;
RecordKind record_kind_;
};
@@ -482,7 +482,7 @@ class EnumTypeIR : public TypeIR, public TagTypeIR {
protected:
std::vector<EnumFieldIR> fields_;
std::string underlying_type_;
AccessSpecifierIR access_;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
};
class ArrayTypeIR : public TypeIR {
@@ -593,6 +593,10 @@ class GlobalVarIR: public LinkableMessageIR , public ReferencesOtherType {
return name_;
}
void SetAccess(AccessSpecifierIR access) {
access_ = access;
}
AccessSpecifierIR GetAccess() const {
return access_;
}
@@ -603,7 +607,7 @@ class GlobalVarIR: public LinkableMessageIR , public ReferencesOtherType {
protected:
std::string name_;
AccessSpecifierIR access_;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
};
class ParamIR : public ReferencesOtherType {
@@ -684,7 +688,7 @@ class FunctionIR : public LinkableMessageIR, public TemplatedArtifactIR,
protected:
std::string linkage_name_;
std::string name_;
AccessSpecifierIR access_;
AccessSpecifierIR access_ = AccessSpecifierIR::PublicAccess;
};
class ElfSymbolIR {

View File

@@ -210,6 +210,7 @@ void ProtobufTextFormatToIRReader::ReadGlobalVariables(
for (auto &&global_variable_protobuf : tu.global_vars()) {
GlobalVarIR global_variable_ir;
global_variable_ir.SetName(global_variable_protobuf.name());
global_variable_ir.SetAccess(AccessProtobufToIR(global_variable_protobuf.access()));
global_variable_ir.SetSourceFile(global_variable_protobuf.source_file());
global_variable_ir.SetReferencedType(
global_variable_protobuf.referenced_type());

View File

@@ -21,6 +21,9 @@ class HighVolumeSpeaker : public SuperSpeaker {
int AddedFunction();
#endif
#if GOLDEN_ADD_GLOBVAR
#if GOLDEN_ADD_GLOBVAR_PRIVATE
private:
#endif
static int global_unprotected_id;
#endif
};

View File

@@ -207,6 +207,18 @@ TEST_MODULES = [
arch = '',
api = 'current',
),
Module(
name = 'libgolden_cpp_add_global_variable_private',
srcs = ['integration/cpp/gold/golden_1.cpp',
'integration/cpp/gold/high_volume_speaker.cpp',
'integration/cpp/gold/low_volume_speaker.cpp',
],
version_script = 'integration/cpp/gold/map_added_globvar.txt',
export_include_dirs = ['integration/cpp/gold/include'],
cflags = ['-DGOLDEN_ADD_GLOBVAR=1', '-DGOLDEN_ADD_GLOBVAR_PRIVATE'],
arch = '',
api = 'current',
),
Module(
name = 'libgolden_cpp_return_type_diff',
srcs = ['integration/cpp/gold/golden_1.cpp',

View File

@@ -167,11 +167,15 @@ class MyTest(unittest.TestCase):
self.prepare_and_run_abi_diff_all_archs(
"libgolden_cpp", "libgolden_cpp_add_global_variable", 4)
def test_libgolden_cpp_change_global_var_access(self):
self.prepare_and_run_abi_diff_all_archs(
"libgolden_cpp_add_global_variable",
"libgolden_cpp_add_global_variable_private", 8)
def test_libgolden_cpp_parameter_type_diff(self):
self.prepare_and_run_abi_diff_all_archs(
"libgolden_cpp", "libgolden_cpp_parameter_type_diff", 8)
def test_libgolden_cpp_with_vtable_diff(self):
self.prepare_and_run_abi_diff_all_archs("libgolden_cpp",
"libgolden_cpp_vtable_diff", 8)