r335853 - [ODRHash] Do not rely on Type* when computing the hash.
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 28 06:28:44 PDT 2018
Author: vvassilev
Date: Thu Jun 28 06:28:44 2018
New Revision: 335853
URL: http://llvm.org/viewvc/llvm-project?rev=335853&view=rev
Log:
[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
Added:
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/first.h
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/second.h
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h
cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h
cfe/trunk/test/Modules/odr_hash-elaborated-types.cpp
Modified:
cfe/trunk/include/clang/AST/ODRHash.h
cfe/trunk/lib/AST/ODRHash.cpp
Modified: cfe/trunk/include/clang/AST/ODRHash.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ODRHash.h?rev=335853&r1=335852&r2=335853&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ODRHash.h (original)
+++ cfe/trunk/include/clang/AST/ODRHash.h Thu Jun 28 06:28:44 2018
@@ -40,7 +40,6 @@ class ODRHash {
// Use DenseMaps to convert from DeclarationName and Type pointers
// to an index value.
llvm::DenseMap<DeclarationName, unsigned> DeclNameMap;
- llvm::DenseMap<const Type*, unsigned> TypeMap;
// Save space by processing bools at the end.
llvm::SmallVector<bool, 128> Bools;
Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=335853&r1=335852&r2=335853&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Thu Jun 28 06:28:44 2018
@@ -180,7 +180,6 @@ void ODRHash::AddTemplateParameterList(c
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);
}
Added: cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/first.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/first.h?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/first.h (added)
+++ cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/first.h Thu Jun 28 06:28:44 2018
@@ -0,0 +1,6 @@
+#ifndef FIRST
+#define FIRST
+
+#include "textual_time.h"
+
+#endif
Added: cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/module.modulemap Thu Jun 28 06:28:44 2018
@@ -0,0 +1,5 @@
+module M {
+ module first { header "first.h" export *}
+ module second { header "second.h" export *}
+ export *
+}
Added: cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/second.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/second.h?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/second.h (added)
+++ cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/second.h Thu Jun 28 06:28:44 2018
@@ -0,0 +1,6 @@
+#ifndef SECOND
+#define SECOND
+
+#include "textual_stat.h"
+
+#endif
Added: cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h (added)
+++ cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_stat.h Thu Jun 28 06:28:44 2018
@@ -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
Added: cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h (added)
+++ cfe/trunk/test/Modules/Inputs/odr_hash-elaborated-types/textual_time.h Thu Jun 28 06:28:44 2018
@@ -0,0 +1,6 @@
+#ifndef _TIME_H
+#define _TIME_H
+
+struct timespec { };
+
+#endif
Added: cfe/trunk/test/Modules/odr_hash-elaborated-types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash-elaborated-types.cpp?rev=335853&view=auto
==============================================================================
--- cfe/trunk/test/Modules/odr_hash-elaborated-types.cpp (added)
+++ cfe/trunk/test/Modules/odr_hash-elaborated-types.cpp Thu Jun 28 06:28:44 2018
@@ -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
More information about the cfe-commits
mailing list