From fd6bc0cc95992f8a92b6bdb828d40eb7c77376c3 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 8 Jul 2021 02:08:45 -0700 Subject: [PATCH] [llvm-diff] Check for recursive initialiers We need to check for recursive initializers in the "ConstantStruct" case. Differential Revision: https://reviews.llvm.org/D105616 --- test/tools/llvm-diff/initializers.ll | 9 +++++++++ tools/llvm-diff/DifferenceEngine.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/test/tools/llvm-diff/initializers.ll b/test/tools/llvm-diff/initializers.ll index 93cabfba54f..d4b0d8f8a23 100644 --- a/test/tools/llvm-diff/initializers.ll +++ b/test/tools/llvm-diff/initializers.ll @@ -36,3 +36,12 @@ define internal i32 @qux() { call void undef(%struct.mutex* @vmx_l1d_flush_mutex) ret i32 undef } + +; An initializer could use itself as part of the initialization. + +@kvm_debugfs_entries = internal global %struct.list_head { %struct.list_head* @kvm_debugfs_entries, %struct.list_head* @kvm_debugfs_entries }, align 8 + +define i64 @mux() { + %1 = load i8*, i8** bitcast (%struct.list_head* @kvm_debugfs_entries to i8**), align 8 + ret i64 undef +} diff --git a/tools/llvm-diff/DifferenceEngine.cpp b/tools/llvm-diff/DifferenceEngine.cpp index b3a6ba83c1e..eb746cd2a86 100644 --- a/tools/llvm-diff/DifferenceEngine.cpp +++ b/tools/llvm-diff/DifferenceEngine.cpp @@ -490,6 +490,16 @@ public: const Value *LAgg = CSL->getAggregateElement(I); const Value *RAgg = CSR->getAggregateElement(I); + if (LAgg == SavedLHS || RAgg == SavedRHS) { + if (LAgg != SavedLHS || RAgg != SavedRHS) + // If the left and right operands aren't both re-analyzing the + // variable, then the initialiers don't match, so report "false". + // Otherwise, we skip these operands.. + return false; + + continue; + } + if (!equivalentAsOperands(LAgg, RAgg)) { return false; }