[llvm-debuginfo-analyzer] (05/09) - Select elements
authorCarlos Alberto Enciso <carlos.alberto.enciso@gmail.com>
Fri, 21 Oct 2022 12:12:19 +0000 (13:12 +0100)
committerCarlos Alberto Enciso <carlos.alberto.enciso@gmail.com>
Fri, 21 Oct 2022 18:16:49 +0000 (19:16 +0100)
The test case 'checkFlexiblePatterns' caused a failure in:

  https://lab.llvm.org/buildbot/#/builders/85/builds/11590
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
    runtime error: applying zero offset to null pointer
    llvm/lib/Support/regengine.inc:151:18

The logical view is traversed and for each logical element a
series of match criterias are applied. One of those criterias
is to match its name or type name to a given pattern.

If the logical element does not have a type (for instance a
'namespace') do not try to use its type name, which is a
empty string as the 'matcher' function receives a null pointer.

Reviewed By: probinson

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

llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h
llvm/lib/DebugInfo/LogicalView/Core/LVOptions.cpp

index ba8e773..8c495c8 100644 (file)
@@ -511,8 +511,8 @@ class LVPatterns final {
   void resolveGenericPatternMatch(T *Element, const U &Requests) {
     assert(Element && "Element must not be nullptr");
     auto CheckPattern = [=]() -> bool {
-      return Element->isNamed() &&
-             (matchGenericPattern(Element->getName()) ||
+      return (Element->isNamed() && matchGenericPattern(Element->getName())) ||
+             (Element->isTyped() &&
               matchGenericPattern(Element->getTypeName()));
     };
     auto CheckOffset = [=]() -> bool {
index 2bcc8a6..265237e 100644 (file)
@@ -505,6 +505,9 @@ void LVPatterns::updateReportOptions() {
 // Match a general pattern.
 bool LVPatterns::matchPattern(StringRef Input, const LVMatchInfo &MatchInfo) {
   bool Matched = false;
+  // Do not match an empty 'Input'.
+  if (Input.empty())
+    return Matched;
   // Traverse all match specifications.
   for (const LVMatch &Match : MatchInfo) {
     switch (Match.Mode) {