From: Vassil Vassilev Date: Thu, 28 Jun 2018 13:28:44 +0000 (+0000) Subject: [ODRHash] Do not rely on Type* when computing the hash. X-Git-Tag: llvmorg-7.0.0-rc1~2646 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61914d38dd5a0f1866d911a408d5070089379213;p=platform%2Fupstream%2Fllvm.git [ODRHash] Do not rely on Type* when computing the hash. ODRHash aims to provide Cross-TU stable hashing. Making clang::Type pointer part of the hash connects (remotely) the ODRHash with the TU-specific ::Profile hasher. r332281 exposed the issue by changing the way the ASTContext different elaborated types if there is an owning tag. In that case, ODRHash stores two different types in its TypeMap which yields false ODR violation in modules. The current state of implementation shouldn't need the TypeMap concept anymore. Rip it out. Differential Revision: https://reviews.llvm.org/D48524 llvm-svn: 335853 --- diff --git a/clang/include/clang/AST/ODRHash.h b/clang/include/clang/AST/ODRHash.h index c9e8027..d4cddb8 100644 --- a/clang/include/clang/AST/ODRHash.h +++ b/clang/include/clang/AST/ODRHash.h @@ -40,7 +40,6 @@ class ODRHash { // Use DenseMaps to convert from DeclarationName and Type pointers // to an index value. llvm::DenseMap DeclNameMap; - llvm::DenseMap TypeMap; // Save space by processing bools at the end. llvm::SmallVector Bools; diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 126b6de..ef1235e 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -180,7 +180,6 @@ void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) { void ODRHash::clear() { DeclNameMap.clear(); - TypeMap.clear(); Bools.clear(); ID.clear(); } @@ -770,14 +769,6 @@ public: void ODRHash::AddType(const Type *T) { assert(T && "Expecting non-null pointer."); - auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size())); - ID.AddInteger(Result.first->second); - // On first encounter of a Type pointer, process it. Every time afterwards, - // only the index value is needed. - if (!Result.second) { - return; - } - ODRTypeVisitor(ID, *this).Visit(T); } diff --git a/clang/test/Modules/Inputs/odr_hash-elaborated-types/first.h b/clang/test/Modules/Inputs/odr_hash-elaborated-types/first.h new file mode 100644 index 0000000..d2c4a03 --- /dev/null +++ b/clang/test/Modules/Inputs/odr_hash-elaborated-types/first.h @@ -0,0 +1,6 @@ +#ifndef FIRST +#define FIRST + +#include "textual_time.h" + +#endif diff --git a/clang/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap b/clang/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap new file mode 100644 index 0000000..94cb4c1 --- /dev/null +++ b/clang/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap @@ -0,0 +1,5 @@ +module M { + module first { header "first.h" export *} + module second { header "second.h" export *} + export * +} diff --git a/clang/test/Modules/Inputs/odr_hash-elaborated-types/second.h b/clang/test/Modules/Inputs/odr_hash-elaborated-types/second.h new file mode 100644 index 0000000..577cf11 --- /dev/null +++ b/clang/test/Modules/Inputs/odr_hash-elaborated-types/second.h @@ -0,0 +1,6 @@ +#ifndef SECOND +#define SECOND + +#include "textual_stat.h" + +#endif diff --git a/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h b/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h new file mode 100644 index 0000000..5dad510 --- /dev/null +++ b/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h @@ -0,0 +1,11 @@ +#ifndef _SYS_STAT_H +#define _SYS_STAT_H + +#include "textual_time.h" + +struct stat { + struct timespec st_atim; + struct timespec st_mtim; +}; + +#endif diff --git a/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h b/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h new file mode 100644 index 0000000..2a2a89c --- /dev/null +++ b/clang/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h @@ -0,0 +1,6 @@ +#ifndef _TIME_H +#define _TIME_H + +struct timespec { }; + +#endif diff --git a/clang/test/Modules/odr_hash-elaborated-types.cpp b/clang/test/Modules/odr_hash-elaborated-types.cpp new file mode 100644 index 0000000..7dd11ac --- /dev/null +++ b/clang/test/Modules/odr_hash-elaborated-types.cpp @@ -0,0 +1,12 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -std=c++1z -I%S/Inputs/odr_hash-elaborated-types -verify %s +// RUN: %clang_cc1 -std=c++1z -fmodules -fmodules-local-submodule-visibility -fmodule-map-file=%S/Inputs/odr_hash-elaborated-types/module.modulemap -fmodules-cache-path=%t -x c++ -I%S/Inputs/odr_hash-elaborated-types -verify %s + +#include "textual_stat.h" + +#include "first.h" +#include "second.h" + +void use() { struct stat value; } + +// expected-no-diagnostics