[llvm-branch-commits] [llvm] dd60b80 - [DebugInfo][LoopStrengthReduction] SCEV-based salvaging for LSR

2021-08-05 Thread Chris Jackson via llvm-branch-commits

Author: Chris Jackson
Date: 2021-08-05T10:34:33+01:00
New Revision: dd60b80561ce637f8b97d709f38bc53c8d0c0510

URL: 
https://github.com/llvm/llvm-project/commit/dd60b80561ce637f8b97d709f38bc53c8d0c0510
DIFF: 
https://github.com/llvm/llvm-project/commit/dd60b80561ce637f8b97d709f38bc53c8d0c0510.diff

LOG: [DebugInfo][LoopStrengthReduction] SCEV-based salvaging for LSR

Reapply commit d675b594f4f1e1f6a195fb9a4fd02cf3de92292d that was
reverted due to buildbot failures. A simple fix has been applied to
remove an assertion.

Differential Revision: https://reviews.llvm.org/D105207

(cherry picked from commit 0ba8595287ea2203ef2250e2b0b41f284a055518)

Added: 
llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-0.ll
llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-1.ll
llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-2.ll
llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-3.ll
llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-4.ll

Modified: 
llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/test/Transforms/LoopStrengthReduce/dbg-preserve-0.ll
llvm/test/Transforms/LoopStrengthReduce/dbg-preserve-2.ll

Removed: 




diff  --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h 
b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index 8662dbf385dc9..59bf3a342caa3 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -83,6 +83,9 @@ class SCEVExpander : public SCEVVisitor {
   /// InsertedValues/InsertedPostIncValues.
   SmallPtrSet ReusedValues;
 
+  // The induction variables generated.
+  SmallVector InsertedIVs;
+
   /// A memoization of the "relevant" loop for a given SCEV.
   DenseMap RelevantLoops;
 
@@ -199,9 +202,11 @@ class SCEVExpander : public SCEVVisitor {
 InsertedPostIncValues.clear();
 ReusedValues.clear();
 ChainedPhis.clear();
+InsertedIVs.clear();
   }
 
   ScalarEvolution *getSE() { return &SE; }
+  const SmallVectorImpl &getInsertedIVs() const { return InsertedIVs; }
 
   /// Return a vector containing all instructions inserted during expansion.
   SmallVector getAllInsertedInstructions() const {

diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp 
b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index b585818af5952..a56a4d736f68a 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1981,6 +1981,9 @@ class LSRInstance {
   /// IV users that belong to profitable IVChains.
   SmallPtrSet IVIncSet;
 
+  /// Induction variables that were generated and inserted by the SCEV 
Expander.
+  SmallVector ScalarEvolutionIVs;
+
   void OptimizeShadowIV();
   bool FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse);
   ICmpInst *OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse);
@@ -2085,6 +2088,9 @@ class LSRInstance {
   TargetLibraryInfo &TLI, MemorySSAUpdater *MSSAU);
 
   bool getChanged() const { return Changed; }
+  const SmallVectorImpl &getScalarEvolutionIVs() const {
+return ScalarEvolutionIVs;
+  }
 
   void print_factors_and_types(raw_ostream &OS) const;
   void print_fixups(raw_ostream &OS) const;
@@ -5589,6 +5595,11 @@ void LSRInstance::ImplementSolution(
 GenerateIVChain(Chain, Rewriter, DeadInsts);
 Changed = true;
   }
+
+  for (const WeakVH &IV : Rewriter.getInsertedIVs())
+if (IV && dyn_cast(&*IV)->getParent())
+  ScalarEvolutionIVs.push_back(IV);
+
   // Clean up after ourselves. This must be done before deleting any
   // instructions.
   Rewriter.clear();
@@ -5859,87 +5870,391 @@ void 
LoopStrengthReduce::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addPreserved();
 }
 
-using EqualValues = SmallVector, 4>;
-using EqualValuesMap =
-DenseMap>>;
-using LocationMap =
-DenseMap>;
+struct SCEVDbgValueBuilder {
+  SCEVDbgValueBuilder() = default;
+  SCEVDbgValueBuilder(const SCEVDbgValueBuilder &Base) {
+Values = Base.Values;
+Expr = Base.Expr;
+  }
+
+  /// The DIExpression as we translate the SCEV.
+  SmallVector Expr;
+  /// The location ops of the DIExpression.
+  SmallVector Values;
+
+  void pushOperator(uint64_t Op) { Expr.push_back(Op); }
+  void pushUInt(uint64_t Operand) { Expr.push_back(Operand); }
+
+  /// Add a DW_OP_LLVM_arg to the expression, followed by the index of the 
value
+  /// in the set of values referenced by the expression.
+  void pushValue(llvm::Value *V) {
+Expr.push_back(llvm::dwarf::DW_OP_LLVM_arg);
+auto *It =
+std::find(Values.begin(), Values.end(), llvm::ValueAsMetadata::get(V));
+unsigned ArgIndex = 0;
+if (It != Values.end()) {
+  ArgIndex = std::distance(Value

[llvm-branch-commits] [llvm] 692f875 - Follow-up to D105207, only salvage affine SCEVs to avoid a crash

2021-08-05 Thread Chris Jackson via llvm-branch-commits

Author: Jeremy Morse
Date: 2021-08-05T10:35:08+01:00
New Revision: 692f875535db1d79e5cb9c3862a6cad0228d04e7

URL: 
https://github.com/llvm/llvm-project/commit/692f875535db1d79e5cb9c3862a6cad0228d04e7
DIFF: 
https://github.com/llvm/llvm-project/commit/692f875535db1d79e5cb9c3862a6cad0228d04e7.diff

LOG: Follow-up to D105207, only salvage affine SCEVs to avoid a crash

SCEVToIterCountExpr only expects to be fed affine expressions, but
DbgRewriteSalvageableDVIs is feeding it non-affine induction variables.
Following this up with an obvious fix, will add test coverage too if
this avoids D105207 being reverted.

(cherry picked from commit 2537120c870c04893636f171f553024f378c2de8)

Added: 


Modified: 
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp 
b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index a56a4d736f68..1ea4e116bd2f 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -6162,6 +6162,9 @@ DbgRewriteSalvageableDVIs(llvm::Loop *L, ScalarEvolution 
&SE,
   bool Changed = false;
   if (const SCEVAddRecExpr *IVAddRec =
   dyn_cast(SCEVInductionVar)) {
+if (!IVAddRec->isAffine())
+  return false;
+
 SCEVDbgValueBuilder IterCountExpr;
 IterCountExpr.pushValue(LSRInductionVar);
 if (!IterCountExpr.SCEVToIterCountExpr(*IVAddRec, SE))



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 8988ce3 - [DebugInfo][LSR] Avoid crashes on large integer inputs

2021-08-05 Thread Chris Jackson via llvm-branch-commits

Author: Chris Jackson
Date: 2021-08-05T10:38:19+01:00
New Revision: 8988ce302864ef3216e252af7d491482e71f79c7

URL: 
https://github.com/llvm/llvm-project/commit/8988ce302864ef3216e252af7d491482e71f79c7
DIFF: 
https://github.com/llvm/llvm-project/commit/8988ce302864ef3216e252af7d491482e71f79c7.diff

LOG: [DebugInfo][LSR] Avoid crashes on large integer inputs

SCEV-based salvaging in LSR translates SCEVs to DIExpressions. SCEVs may
contain very large integers but the translation does not support
integers greater than 64 bits. This patch adds checks to ensure
conversions of these large integers is not attempted. A regression test
is added to ensure no such translation is attempted.

Reviewed by: StephenTozer

PR: https://bugs.llvm.org/show_bug.cgi?id=51329

Differential Revision: https://reviews.llvm.org/D107438

(cherry picked from commit 21ee38e24f9801a567306b2a88defacf6e589a8b)

Added: 
llvm/test/Transforms/LoopStrengthReduce/pr51329.ll

Modified: 
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp 
b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 1ea4e116bd2fc..404852f1dd4dd 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5906,9 +5906,12 @@ struct SCEVDbgValueBuilder {
 pushValue(V);
   }
 
-  void pushConst(const SCEVConstant *C) {
+  bool pushConst(const SCEVConstant *C) {
+if (C->getAPInt().getMinSignedBits() > 64)
+  return false;
 Expr.push_back(llvm::dwarf::DW_OP_consts);
 Expr.push_back(C->getAPInt().getSExtValue());
+return true;
   }
 
   /// Several SCEV types are sequences of the same arithmetic operator applied
@@ -5947,7 +5950,7 @@ struct SCEVDbgValueBuilder {
   bool pushSCEV(const llvm::SCEV *S) {
 bool Success = true;
 if (const SCEVConstant *StartInt = dyn_cast(S)) {
-  pushConst(StartInt);
+  Success &= pushConst(StartInt);
 
 } else if (const SCEVUnknown *U = dyn_cast(S)) {
   if (!U->getValue())
@@ -6033,6 +6036,8 @@ struct SCEVDbgValueBuilder {
   /// SCEV constant value is an identity function.
   bool isIdentityFunction(uint64_t Op, const SCEV *S) {
 if (const SCEVConstant *C = dyn_cast(S)) {
+  if (C->getAPInt().getMinSignedBits() > 64)
+return false;
   int64_t I = C->getAPInt().getSExtValue();
   switch (Op) {
   case llvm::dwarf::DW_OP_plus:

diff  --git a/llvm/test/Transforms/LoopStrengthReduce/pr51329.ll 
b/llvm/test/Transforms/LoopStrengthReduce/pr51329.ll
new file mode 100644
index 0..f8f1c48eeaa86
--- /dev/null
+++ b/llvm/test/Transforms/LoopStrengthReduce/pr51329.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S -loop-reduce %s | FileCheck %s
+;
+; Test that LSR SCEV-based salvaging does not crash when translating SCEVs
+; that contain integers with binary representations greater than 64-bits. 
+;
+; CHECK: call void @llvm.dbg.value(metadata i64 %var2, metadata !{{[0-9]+}}, 
metadata !DIExpression(DW_OP_plus_uconst, 228, DW_OP_stack_value))
+
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+; Function Attrs: nounwind
+define hidden void @reproducer() local_unnamed_addr !dbg !5 {
+init:
+  %0 = lshr i128 undef, 64
+  %var1 = trunc i128 %0 to i64
+  %1 = add nuw i64 undef, %var1
+  %var2 = lshr i64 %1, 12
+  br label %Label_d0
+
+Label_d0: ; preds = %Label_d0, %init
+  %var3 = phi i64 [ %var2, %init ], [ %var4, %Label_d0 ]
+  call void @llvm.dbg.value(metadata i64 %var2, metadata !11, metadata 
!DIExpression(DW_OP_plus_uconst, 228, DW_OP_stack_value)), !dbg !12
+  %var4 = add i64 %var3, -1
+  %var5 = icmp eq i64 %var4, 0
+  br i1 %var5, label %Label_1bc, label %Label_d0
+
+Label_1bc:; preds = %Label_d0
+  ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, 
producer: "frontend", isOptimized: true, runtimeVersion: 0, emissionKind: 
FullDebug, enums: !2)
+!1 = !DIFile(filename: "source", directory: "")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = distinct !DISubprogram(name: "reproducer", scope: !1, file: !1, line: 
904320, type: !6, scopeLine: 904320, spFlags: DISPFlagDefinition, unit: !0, 
retainedNodes: !10)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null, !8, !9, !9, !9, !9, !9, !9}
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
+!9 = !DIBasicType(name: "my_type", size: 64, encoding: DW_ATE_unsigned)
+!10 = !{!11}
+!11 = !DILocalVariable(name: "my_var", arg: 1, scope: !5, file: !1,

[llvm-branch-commits] [compiler-rt] 6f58e54 - Work around non-existence of ElfW(type) macro on FreeBSD

2021-08-05 Thread Tom Stellard via llvm-branch-commits

Author: Dimitry Andric
Date: 2021-08-05T10:06:16-07:00
New Revision: 6f58e54d655d0167f3b7d55e35c9806854307204

URL: 
https://github.com/llvm/llvm-project/commit/6f58e54d655d0167f3b7d55e35c9806854307204
DIFF: 
https://github.com/llvm/llvm-project/commit/6f58e54d655d0167f3b7d55e35c9806854307204.diff

LOG: Work around non-existence of ElfW(type) macro on FreeBSD

Fixes PR51331. On FreeBSD, the elf headers don't (yet) provide the
ElfW(type) macro. However, there is a similar set of macros in the
 header, of which `__ElfN(type)` exactly matches the
indended purpose.

Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D107388

(cherry picked from commit 440d9712ebf6d5faa898daa68045ff0c10859db3)

Added: 


Modified: 
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c

Removed: 




diff  --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c 
b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
index 508624a80cd66..d1922e27ae1d0 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -17,6 +17,15 @@
 #include "InstrProfiling.h"
 #include "InstrProfilingInternal.h"
 
+#if defined(__FreeBSD__) && !defined(ElfW)
+/*
+ * FreeBSD's elf.h and link.h headers do not define the ElfW(type) macro yet.
+ * If this is added to all supported FreeBSD versions in the future, this
+ * compatibility macro can be removed.
+ */
+#define ElfW(type) __ElfN(type)
+#endif
+
 #define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_COMMON)
 #define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_COMMON)
 #define PROF_NAME_START INSTR_PROF_SECT_START(INSTR_PROF_NAME_COMMON)



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 6774711 - Apply -fmacro-prefix-map to __builtin_FILE()

2021-08-05 Thread Tom Stellard via llvm-branch-commits

Author: Pavel Asyutchenko
Date: 2021-08-05T10:07:47-07:00
New Revision: 67747112b5e63462989cd0a43b6921664e14e58c

URL: 
https://github.com/llvm/llvm-project/commit/67747112b5e63462989cd0a43b6921664e14e58c
DIFF: 
https://github.com/llvm/llvm-project/commit/67747112b5e63462989cd0a43b6921664e14e58c.diff

LOG: Apply -fmacro-prefix-map to __builtin_FILE()

This matches the behavior of GCC.
Patch does not change remapping logic itself, so adding one simple smoke test 
should be enough.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D107393

(cherry picked from commit 7df405e079c5045562c53f7a2504b85f423078be)

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/include/clang/Lex/PreprocessorOptions.h
clang/lib/AST/Expr.cpp
clang/lib/Basic/LangOptions.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 71cf0c65e6924..b60b94a1ba08c 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -354,6 +354,9 @@ class LangOptions : public LangOptionsBase {
   /// A list of all -fno-builtin-* function names (e.g., memset).
   std::vector NoBuiltinFuncs;
 
+  /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
+  std::map> MacroPrefixMap;
+
   /// Triples of the OpenMP targets that the host code codegen should
   /// take into account in order to generate accurate offloading descriptors.
   std::vector OMPTargetTriples;
@@ -460,6 +463,9 @@ class LangOptions : public LangOptionsBase {
   }
 
   bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
+
+  /// Remap path prefix according to -fmacro-prefix-path option.
+  void remapPathPrefix(SmallString<256> &Path) const;
 };
 
 /// Floating point control options

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ab1a5487d9c03..a0cbcae0bdc35 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2825,10 +2825,10 @@ def fcoverage_prefix_map_EQ
 HelpText<"remap file source paths in coverage mapping">;
 def ffile_prefix_map_EQ
   : Joined<["-"], "ffile-prefix-map=">, Group,
-HelpText<"remap file source paths in debug info and predefined 
preprocessor macros">;
+HelpText<"remap file source paths in debug info, predefined preprocessor 
macros and __builtin_FILE()">;
 def fmacro_prefix_map_EQ
-  : Joined<["-"], "fmacro-prefix-map=">, Group, 
Flags<[CC1Option]>,
-HelpText<"remap file source paths in predefined preprocessor macros">;
+  : Joined<["-"], "fmacro-prefix-map=">, Group, Flags<[CC1Option]>,
+HelpText<"remap file source paths in predefined preprocessor macros and 
__builtin_FILE()">;
 defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",
   CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,
   PosFlag, 
NegFlag>;

diff  --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index 99085b98fc7ad..a7aabc3e1df2a 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -199,9 +199,6 @@ class PreprocessorOptions {
   /// build it again.
   std::shared_ptr FailedModules;
 
-  /// A prefix map for __FILE__ and __BASE_FILE__.
-  std::map> MacroPrefixMap;
-
   /// Contains the currently active skipped range mappings for skipping 
excluded
   /// conditional directives.
   ///

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index e8b4aaa2b81e6..11f10d4695fcd 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2233,8 +2233,11 @@ APValue SourceLocExpr::EvaluateInContext(const 
ASTContext &Ctx,
   };
 
   switch (getIdentKind()) {
-  case SourceLocExpr::File:
-return MakeStringLiteral(PLoc.getFilename());
+  case SourceLocExpr::File: {
+SmallString<256> Path(PLoc.getFilename());
+Ctx.getLangOpts().remapPathPrefix(Path);
+return MakeStringLiteral(Path);
+  }
   case SourceLocExpr::Function: {
 const Decl *CurDecl = dyn_cast_or_null(Context);
 return MakeStringLiteral(

diff  --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index dc392d5352aae..bebf3178426f0 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -11,6 +11,8 @@
 
//===--===//
 
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang;
 
@@ -48,6 +50,12 @@ VersionTuple LangOptions::getOpenCLVersionTuple() const {
   return VersionTuple(Ver / 100, (Ver % 100) / 10);
 }
 

[llvm-branch-commits] [openmp] 2792379 - [OpenMP] libomp: taskwait depend implementation fixed.

2021-08-05 Thread Tom Stellard via llvm-branch-commits

Author: AndreyChurbanov
Date: 2021-08-05T10:13:27-07:00
New Revision: 279237937b330d8ca570ffa7b0cb7e1bbda57fca

URL: 
https://github.com/llvm/llvm-project/commit/279237937b330d8ca570ffa7b0cb7e1bbda57fca
DIFF: 
https://github.com/llvm/llvm-project/commit/279237937b330d8ca570ffa7b0cb7e1bbda57fca.diff

LOG: [OpenMP] libomp: taskwait depend implementation fixed.

Fix for https://bugs.llvm.org/show_bug.cgi?id=49723.
Eliminated references from task dependency hash to node allocated on stack,
thus eliminated accesses to stale memory. So the node now never freed.
Uncommented assertion which triggered when stale memory accessed.
Removed unneeded ref count increment for stack allocated node.

Differential Revision: https://reviews.llvm.org/D106705

(cherry picked from commit 8e29b4b323b87f3855dc71abf1e3f3d48952a4e4)

Added: 
openmp/runtime/test/tasking/kmp_taskwait_depend_in.c

Modified: 
openmp/runtime/src/kmp_taskdeps.cpp
openmp/runtime/src/kmp_taskdeps.h

Removed: 




diff  --git a/openmp/runtime/src/kmp_taskdeps.cpp 
b/openmp/runtime/src/kmp_taskdeps.cpp
index 162fb38e1eedd..dd3e7688d33f7 100644
--- a/openmp/runtime/src/kmp_taskdeps.cpp
+++ b/openmp/runtime/src/kmp_taskdeps.cpp
@@ -344,6 +344,13 @@ __kmp_process_deps(kmp_int32 gtid, kmp_depnode_t *node, 
kmp_dephash_t **hash,
 // link node as successor of all nodes in the prev_set if any
 npredecessors +=
 __kmp_depnode_link_successor(gtid, thread, task, node, prev_set);
+if (dep_barrier) {
+  // clean last_out and prev_set if any; don't touch last_set
+  __kmp_node_deref(thread, last_out);
+  info->last_out = NULL;
+  __kmp_depnode_list_free(thread, prev_set);
+  info->prev_set = NULL;
+}
   } else { // last_set is of 
diff erent dep kind, make it prev_set
 // link node as successor of all nodes in the last_set
 npredecessors +=
@@ -353,13 +360,21 @@ __kmp_process_deps(kmp_int32 gtid, kmp_depnode_t *node, 
kmp_dephash_t **hash,
 info->last_out = NULL;
 // clean prev_set if any
 __kmp_depnode_list_free(thread, prev_set);
-// move last_set to prev_set, new last_set will be allocated
-info->prev_set = last_set;
+if (!dep_barrier) {
+  // move last_set to prev_set, new last_set will be allocated
+  info->prev_set = last_set;
+} else {
+  info->prev_set = NULL;
+  info->last_flag = 0;
+}
 info->last_set = NULL;
   }
-  info->last_flag = dep->flag; // store dep kind of the last_set
-  info->last_set = __kmp_add_node(thread, info->last_set, node);
-
+  // for dep_barrier last_flag value should remain:
+  // 0 if last_set is empty, unchanged otherwise
+  if (!dep_barrier) {
+info->last_flag = dep->flag; // store dep kind of the last_set
+info->last_set = __kmp_add_node(thread, info->last_set, node);
+  }
   // check if we are processing MTX dependency
   if (dep->flag == KMP_DEP_MTX) {
 if (info->mtx_lock == NULL) {
@@ -756,8 +771,6 @@ void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, 
kmp_int32 ndeps,
 
   kmp_depnode_t node = {0};
   __kmp_init_node(&node);
-  // the stack owns the node
-  __kmp_node_ref(&node);
 
   if (!__kmp_check_deps(gtid, &node, NULL, ¤t_task->td_dephash,
 DEP_BARRIER, ndeps, dep_list, ndeps_noalias,

diff  --git a/openmp/runtime/src/kmp_taskdeps.h 
b/openmp/runtime/src/kmp_taskdeps.h
index d1576dd5b7910..73abf07018f31 100644
--- a/openmp/runtime/src/kmp_taskdeps.h
+++ b/openmp/runtime/src/kmp_taskdeps.h
@@ -23,8 +23,7 @@ static inline void __kmp_node_deref(kmp_info_t *thread, 
kmp_depnode_t *node) {
 return;
 
   kmp_int32 n = KMP_ATOMIC_DEC(&node->dn.nrefs) - 1;
-  // TODO: temporarily disable assertion until the bug with dependences is 
fixed
-  //  KMP_DEBUG_ASSERT(n >= 0);
+  KMP_DEBUG_ASSERT(n >= 0);
   if (n == 0) {
 KMP_ASSERT(node->dn.nrefs == 0);
 #if USE_FAST_MEMORY

diff  --git a/openmp/runtime/test/tasking/kmp_taskwait_depend_in.c 
b/openmp/runtime/test/tasking/kmp_taskwait_depend_in.c
new file mode 100644
index 0..fef29ea60b487
--- /dev/null
+++ b/openmp/runtime/test/tasking/kmp_taskwait_depend_in.c
@@ -0,0 +1,68 @@
+// RUN: %libomp-compile-and-run
+
+// test checks IN dep kind in depend clause on taskwait construct
+// uses codegen emulation
+#include 
+#include 
+// ---
+// internal data to emulate compiler codegen
+typedef struct DEP {
+  size_t addr;
+  size_t len;
+  unsigned char flags;
+} _dep;
+typedef struct ID {
+  int reserved_1;
+  int flags;
+  int reserved_2;
+  int reserved_3;
+  char *psource;
+} _id;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int __kmpc_global_thread_num(_id*);
+extern void __kmpc_omp_wait_deps(_id *, int,

[llvm-branch-commits] [clang-tools-extra] e097724 - [clang-tidy] Fix crash on "reference-to-array" parameters in 'bugprone-easily-swappable-parameters'

2021-08-05 Thread Tom Stellard via llvm-branch-commits

Author: Whisperity
Date: 2021-08-05T10:16:24-07:00
New Revision: e097724cb9efbc3a068767ecf264897e97b2e109

URL: 
https://github.com/llvm/llvm-project/commit/e097724cb9efbc3a068767ecf264897e97b2e109
DIFF: 
https://github.com/llvm/llvm-project/commit/e097724cb9efbc3a068767ecf264897e97b2e109.diff

LOG: [clang-tidy] Fix crash on "reference-to-array" parameters in 
'bugprone-easily-swappable-parameters'

An otherwise unexercised code path related to trying to model
"array-to-pointer decay" resulted in a null pointer dereference crash
when parameters of type "reference to array" were encountered.

Fixes crash report http://bugs.llvm.org/show_bug.cgi?id=50995.

Reviewed By: aaron.ballman

Differential Revision: http://reviews.llvm.org/D106946

(cherry picked from commit 21832121e112d97f1e197b35959867f3a99226ee)

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index afcdca226911d..e4500706b4b2e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -962,11 +962,8 @@ approximateStandardConversionSequence(const TheCheck 
&Check, QualType From,
   // LValue->RValue is irrelevant for the check, because it is a thing to be
   // done at a call site, and will be performed if need be performed.
 
-  // Array->Ptr decay.
-  if (const auto *ArrayT = dyn_cast(From)) {
-LLVM_DEBUG(llvm::dbgs() << "--- approximateStdConv. Array->Ptr 
decayed.\n");
-WorkType = ArrayT->getPointeeType();
-  }
+  // Array->Pointer decay is handled by the main method in desugaring
+  // the parameter's DecayedType as "useless sugar".
 
   // Function->Pointer conversions are also irrelevant, because a
   // "FunctionType" cannot be the type of a parameter variable, so this

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
index c1a72d687b135..ba7aa44a8731a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
@@ -26,6 +26,50 @@ void arrayAndPtr2(int *IP, int IA[8]) { arrayAndPtr2(IA, 
IP); }
 
 void arrayAndElement(int I, int IA[]) {} // NO-WARN.
 
+typedef int Point2D[2];
+typedef int Point3D[3];
+
+void arrays1(Point2D P2D, Point3D P3D) {} // In reality this is (int*, int*).
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 
'arrays1' of similar type ('int *') are
+// CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 
'P2D'
+// CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 
'P3D'
+
+void crefToArrayTypedef1(int I, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef2(int *IA, const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedef3(int P1[2], const Point2D &P) {}
+// NO-WARN.
+
+void crefToArrayTypedefBoth1(const Point2D &VecDescartes, const Point3D 
&VecThreeD) {}
+// NO-WARN: Distinct types.
+
+template 
+void templatedArrayRef(int (&Array1)[N], int (&Array2)[M]) {}
+// NO-WARN: Distinct template types in the primary template.
+
+void templatedArrayRefTest() {
+  int Foo[12], Bar[12];
+  templatedArrayRef(Foo, Bar);
+
+  int Baz[12], Quux[42];
+  templatedArrayRef(Baz, Quux);
+
+  // NO-WARN: Implicit instantiations are not checked.
+}
+
+template <>
+void templatedArrayRef(int (&Array1)[8], int (&Array2)[8]) { 
templatedArrayRef(Array2, Array1); }
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 2 adjacent parameters of 
'templatedArrayRef<8, 8>' of similar type ('int (&)[8]') are
+// CHECK-MESSAGES: :[[@LINE-2]]:30: note: the first parameter in the range is 
'Array1'
+// CHECK-MESSAGES: :[[@LINE-3]]:48: note: the last parameter in the range is 
'Array2'
+
+template <>
+void templatedArrayRef(int (&Array1)[16], int (&Array2)[24]) {}
+// NO-WARN: Not the same type.
+
 void numericConversion1(int I, double D) { numericConversion1(D, I); }
 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 
'numericConversion1' of convertible types are easily swapped by mistake 
[bugprone-easily-swappable-parameters]
 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 
'I'

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
 
b/clang-tools-extra/test/clan

[llvm-branch-commits] [lld] 6b6aef5 - [ELF] Support copy relocation on non-default version symbols

2021-08-05 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2021-08-05T10:33:31-07:00
New Revision: 6b6aef5dbacef31a3c7b3a54f7f1ba54cafc7077

URL: 
https://github.com/llvm/llvm-project/commit/6b6aef5dbacef31a3c7b3a54f7f1ba54cafc7077
DIFF: 
https://github.com/llvm/llvm-project/commit/6b6aef5dbacef31a3c7b3a54f7f1ba54cafc7077.diff

LOG: [ELF] Support copy relocation on non-default version symbols

Copy relocation on a non-default version symbol is unsupported and can crash at
runtime. Fortunately there is a one-line fix which works for most cases:
ensure `getSymbolsAt` unconditionally returns `ss`.

If two non-default version symbols are defined at the same place and both
are copy relocated, our implementation will copy relocated them into different
addresses. The pointer inequality is very unlikely an issue. In GNU ld, copy
relocating version aliases seems to create more pointer inequality problems than
us.

(
In glibc, sys_errlist@GLIBC_2.2.5 sys_errlist@GLIBC_2.3 sys_errlist@GLIBC_2.4
are defined at the same place, but it is unlikely they are all copy relocated in
one executable. Even if so, the variables are read-only and pointer inequality
should not be a problem.
)

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107535

(cherry picked from commit 72d070b4db2da7216f63f09407bd96f49dc90bd1)

Added: 


Modified: 
lld/ELF/Relocations.cpp
lld/test/ELF/Inputs/copy-rel-version.s
lld/test/ELF/copy-rel-version.s

Removed: 




diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e3cc210972b2f..537859f9e0b5b 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -527,6 +527,13 @@ static SmallSet 
getSymbolsAt(SharedSymbol &ss) {
 if (auto *alias = dyn_cast_or_null(sym))
   ret.insert(alias);
   }
+
+  // The loop does not check SHT_GNU_verneed, so ret does not contain
+  // non-default version symbols. If ss has a non-default version, ret won't
+  // contain ss. Just add ss unconditionally. If a non-default version alias is
+  // separately copy relocated, it and ss will have 
diff erent addresses.
+  // Fortunately this case is impractical and fails with GNU ld as well.
+  ret.insert(&ss);
   return ret;
 }
 

diff  --git a/lld/test/ELF/Inputs/copy-rel-version.s 
b/lld/test/ELF/Inputs/copy-rel-version.s
index 36bb1ba54c9f5..1477527d829e7 100644
--- a/lld/test/ELF/Inputs/copy-rel-version.s
+++ b/lld/test/ELF/Inputs/copy-rel-version.s
@@ -1,11 +1,22 @@
 .data
-.global foo@v1
-.type foo@v1, @object
-.size foo@v1, 4
-.global foo@@v2
-.type foo@@v2, @object
-.size foo@@v2, 8
-foo@v1:
-foo@@v2:
+.global foo_v1
+.symver foo_v1, foo@v1, remove
+.type foo_v1, @object
+.size foo_v1, 4
+
+.global foo_v2
+.symver foo_v2, foo@v2, remove
+.type foo_v2, @object
+.size foo_v2, 8
+
+.global foo
+.symver foo, foo@@@v3
+.type foo, @object
+.size foo, 12
+
+foo_v1:
+foo_v2:
+foo:
+.int 0
 .int 0
 .int 0

diff  --git a/lld/test/ELF/copy-rel-version.s b/lld/test/ELF/copy-rel-version.s
index afa5ebeb6e4da..feaa59f8eb8cb 100644
--- a/lld/test/ELF/copy-rel-version.s
+++ b/lld/test/ELF/copy-rel-version.s
@@ -1,15 +1,27 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux 
%p/Inputs/copy-rel-version.s -o %t1.o
-// RUN: echo "v1 {}; v2 {};" > %t.ver
-// RUN: ld.lld %t1.o -shared -soname t1.so --version-script=%t.ver -o %t1.so
-// RUN: ld.lld %t.o %t1.so -o %t
-// RUN: llvm-readobj --symbols %t | FileCheck %s
+# REQUIRES: x86
+## Copy relocate a versioned symbol which has a versioned alias.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/copy-rel-version.s -o 
%t.o
+# RUN: echo 'v1 {}; v2 {}; v3 {};' > %t.ver
+# RUN: ld.lld %t.o -shared -soname t.so --version-script=%t.ver -o %t.so
+
+## Copy relocate the default version symbol.
+# RUN: ld.lld %t1.o %t.so -o %t1
+# RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=CHECK1
+
+# CHECK1:   1: {{.+}}12 OBJECT  GLOBAL DEFAULT [[#]] foo@v3
+# CHECK1-EMPTY:
+
+## Copy relocate the non-default version symbol.
+# RUN: llvm-objcopy --redefine-sym foo=foo@v1 %t1.o %t2.o
+# RUN: ld.lld %t2.o %t.so -o %t2
+# RUN: llvm-readelf --dyn-syms %t2 | FileCheck %s --check-prefix=CHECK2
+
+# CHECK2:   1: [[ADDR:[0-9a-f]+]] 4 OBJECT  GLOBAL DEFAULT [[#]] foo@v1
+# CHECK2-NEXT:  2: [[ADDR]]  12 OBJECT  GLOBAL DEFAULT [[#]] foo@v3
+# CHECK2-EMPTY:
 
 .global _start
 _start:
   leaq foo, %rax
-
-// CHECK:  Name: foo (
-// CHECK-NEXT: Value:
-// CHECK-NEXT: Size: 8



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] 63081c9 - [ELF] Apply version script patterns to non-default version symbols

2021-08-05 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2021-08-05T10:42:02-07:00
New Revision: 63081c9bc138d393c3ded03df7ae50733283bdec

URL: 
https://github.com/llvm/llvm-project/commit/63081c9bc138d393c3ded03df7ae50733283bdec
DIFF: 
https://github.com/llvm/llvm-project/commit/63081c9bc138d393c3ded03df7ae50733283bdec.diff

LOG: [ELF] Apply version script patterns to non-default version symbols

Currently version script patterns are ignored for .symver produced
non-default version (single @) symbols. This makes such symbols
not localizable by `local:`, e.g.

```
.symver foo3_v1,foo3@v1
.globl foo_v1
foo3_v1:

ld.lld --version-script=a.ver -shared a.o
```

This patch adds the support:

* Move `config->versionDefinitions[VER_NDX_LOCAL].patterns` to 
`config->versionDefinitions[versionId].localPatterns`
* Rename `config->versionDefinitions[versionId].patterns` to 
`config->versionDefinitions[versionId].nonLocalPatterns`
* Allow `findAllByVersion` to find non-default version symbols when 
`includeNonDefault` is true. (Note: `symtab` keys do not have `@@`)
* Make each pattern check both the unversioned `pat.name` and the versioned 
`${pat.name}@${v.name}`
* `localPatterns` can localize `${pat.name}@${v.name}`. `nonLocalPatterns` can 
prevent localization by assigning `verdefIndex` (before `parseSymbolVersion`).

---

If a user notices new `undefined symbol` errors with a version script containing
`local: *;`, the issue is likely due to a missing `global:` pattern.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107234

(cherry picked from commit 00809c8889ed34a5fe014167aa473216dcb63a47)

Added: 
lld/test/ELF/version-script-symver-extern.s

Modified: 
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/SymbolTable.h
lld/ELF/Symbols.cpp
lld/test/ELF/verdef-defaultver.s
lld/test/ELF/version-script-noundef.s
lld/test/ELF/version-script-symver.s

Removed: 
lld/test/ELF/version-script-extern-exact.s
lld/test/ELF/version-script-extern-wildcards.s
lld/test/ELF/version-script-extern.s



diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index a996a815599a4..e1abb4dfab36a 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -86,7 +86,8 @@ struct SymbolVersion {
 struct VersionDefinition {
   llvm::StringRef name;
   uint16_t id;
-  std::vector patterns;
+  std::vector nonLocalPatterns;
+  std::vector localPatterns;
 };
 
 // This struct contains the global configuration for the linker.

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 713d1f7cc360f..594c20016827e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1351,18 +1351,19 @@ static void readConfigs(opt::InputArgList &args) {
   }
 
   assert(config->versionDefinitions.empty());
-  config->versionDefinitions.push_back({"local", (uint16_t)VER_NDX_LOCAL, {}});
   config->versionDefinitions.push_back(
-  {"global", (uint16_t)VER_NDX_GLOBAL, {}});
+  {"local", (uint16_t)VER_NDX_LOCAL, {}, {}});
+  config->versionDefinitions.push_back(
+  {"global", (uint16_t)VER_NDX_GLOBAL, {}, {}});
 
   // If --retain-symbol-file is used, we'll keep only the symbols listed in
   // the file and discard all others.
   if (auto *arg = args.getLastArg(OPT_retain_symbols_file)) {
-config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(
+config->versionDefinitions[VER_NDX_LOCAL].nonLocalPatterns.push_back(
 {"*", /*isExternCpp=*/false, /*hasWildcard=*/true});
 if (Optional buffer = readFile(arg->getValue()))
   for (StringRef s : args::getLines(*buffer))
-config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back(
+config->versionDefinitions[VER_NDX_GLOBAL].nonLocalPatterns.push_back(
 {s, /*isExternCpp=*/false, /*hasWildcard=*/false});
   }
 

diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 2c980eb810c77..1c743fd477471 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1496,9 +1496,9 @@ void ScriptParser::readAnonymousDeclaration() {
   std::vector globals;
   std::tie(locals, globals) = readSymbols();
   for (const SymbolVersion &pat : locals)
-config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat);
+config->versionDefinitions[VER_NDX_LOCAL].localPatterns.push_back(pat);
   for (const SymbolVersion &pat : globals)
-config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back(pat);
+config->versionDefinitions[VER_NDX_GLOBAL].nonLocalPatterns.push_back(pat);
 
   expect(";");
 }
@@ -1510,13 +1510,12 @@ void ScriptParser::readVersionDeclaration(StringRef 
verStr) {
   std::vector locals;
   std::vector globals;
   std::tie(locals, globals) = readSymbols();
-  for (const SymbolVersion &pat : locals)
-config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat);
 
   // Create a new version definition and add that to the global symbols.
   Ver

[llvm-branch-commits] [lld] 6b97268 - Revert "[ELF] Apply version script patterns to non-default version symbols"

2021-08-05 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2021-08-05T10:41:56-07:00
New Revision: 6b97268c56ae8baa684da5de23ae2ebc41d94a1d

URL: 
https://github.com/llvm/llvm-project/commit/6b97268c56ae8baa684da5de23ae2ebc41d94a1d
DIFF: 
https://github.com/llvm/llvm-project/commit/6b97268c56ae8baa684da5de23ae2ebc41d94a1d.diff

LOG: Revert "[ELF] Apply version script patterns to non-default version symbols"

This reverts commit 7ed22a6fa90cbdc70d6806c1121a0c50c1978dce.

buf is not cleared so the commit misses some cases.

(cherry picked from commit a533eb7423acad49f10426cd78dc8e7e66a6365f)

Added: 
lld/test/ELF/version-script-extern-exact.s
lld/test/ELF/version-script-extern-wildcards.s
lld/test/ELF/version-script-extern.s

Modified: 
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/SymbolTable.h
lld/ELF/Symbols.cpp
lld/test/ELF/version-script-noundef.s
lld/test/ELF/version-script-symver.s

Removed: 
lld/test/ELF/version-script-symver-extern.s



diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index e1abb4dfab36a..a996a815599a4 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -86,8 +86,7 @@ struct SymbolVersion {
 struct VersionDefinition {
   llvm::StringRef name;
   uint16_t id;
-  std::vector nonLocalPatterns;
-  std::vector localPatterns;
+  std::vector patterns;
 };
 
 // This struct contains the global configuration for the linker.

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 594c20016827e..713d1f7cc360f 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1351,19 +1351,18 @@ static void readConfigs(opt::InputArgList &args) {
   }
 
   assert(config->versionDefinitions.empty());
+  config->versionDefinitions.push_back({"local", (uint16_t)VER_NDX_LOCAL, {}});
   config->versionDefinitions.push_back(
-  {"local", (uint16_t)VER_NDX_LOCAL, {}, {}});
-  config->versionDefinitions.push_back(
-  {"global", (uint16_t)VER_NDX_GLOBAL, {}, {}});
+  {"global", (uint16_t)VER_NDX_GLOBAL, {}});
 
   // If --retain-symbol-file is used, we'll keep only the symbols listed in
   // the file and discard all others.
   if (auto *arg = args.getLastArg(OPT_retain_symbols_file)) {
-config->versionDefinitions[VER_NDX_LOCAL].nonLocalPatterns.push_back(
+config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(
 {"*", /*isExternCpp=*/false, /*hasWildcard=*/true});
 if (Optional buffer = readFile(arg->getValue()))
   for (StringRef s : args::getLines(*buffer))
-config->versionDefinitions[VER_NDX_GLOBAL].nonLocalPatterns.push_back(
+config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back(
 {s, /*isExternCpp=*/false, /*hasWildcard=*/false});
   }
 

diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 1c743fd477471..2c980eb810c77 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1496,9 +1496,9 @@ void ScriptParser::readAnonymousDeclaration() {
   std::vector globals;
   std::tie(locals, globals) = readSymbols();
   for (const SymbolVersion &pat : locals)
-config->versionDefinitions[VER_NDX_LOCAL].localPatterns.push_back(pat);
+config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat);
   for (const SymbolVersion &pat : globals)
-config->versionDefinitions[VER_NDX_GLOBAL].nonLocalPatterns.push_back(pat);
+config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back(pat);
 
   expect(";");
 }
@@ -1510,12 +1510,13 @@ void ScriptParser::readVersionDeclaration(StringRef 
verStr) {
   std::vector locals;
   std::vector globals;
   std::tie(locals, globals) = readSymbols();
+  for (const SymbolVersion &pat : locals)
+config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat);
 
   // Create a new version definition and add that to the global symbols.
   VersionDefinition ver;
   ver.name = verStr;
-  ver.nonLocalPatterns = std::move(globals);
-  ver.localPatterns = std::move(locals);
+  ver.patterns = globals;
   ver.id = config->versionDefinitions.size();
   config->versionDefinitions.push_back(ver);
 

diff  --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 96a9cf1d1617f..70aea288c53f6 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -150,24 +150,19 @@ std::vector 
SymbolTable::findByVersion(SymbolVersion ver) {
   return {};
 }
 
-std::vector SymbolTable::findAllByVersion(SymbolVersion ver,
-bool includeNonDefault) {
+std::vector SymbolTable::findAllByVersion(SymbolVersion ver) {
   std::vector res;
   SingleStringMatcher m(ver.name);
 
   if (ver.isExternCpp) {
 for (auto &p : getDemangledSyms())
   if (m.match(p.first()))
-for (Symbol *sym : p.second)
-  if (includeNonDefault || !sym->getName().contains('@'))
-res.push_back(sym);
+res.insert(res.end(), p.second.begin(), p.second.end(