[llvm-branch-commits] [llvm] 1915709 - Improve error messages for attributes in the wrong context.

2021-04-28 Thread Nick Lewycky via llvm-branch-commits

Author: Nick Lewycky
Date: 2021-04-28T13:17:43-07:00
New Revision: 191570989ba291c639034906eeb6a0bae9ed47e9

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

LOG: Improve error messages for attributes in the wrong context.

verifyFunctionAttrs has a comment that the value V is printed in error 
messages. The recently added errors for attributes didn't print V. Make them 
print V.

Change the stringification of AttributeList. Firstly they started with 'PAL[' 
which stood for ParamAttrsList. Change that to 'AttributeList[' matching its 
current name AttributeList. Print out semantic meaning of the index instead of 
the raw index value (i.e. 'return', 'function' or 'arg(n)').

Added: 


Modified: 
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/unittests/IR/AttributesTest.cpp

Removed: 




diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 30730a4374a5f..324e6f1833341 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1693,11 +1693,23 @@ unsigned AttributeList::getNumAttrSets() const {
 }
 
 void AttributeList::print(raw_ostream &O) const {
-  O << "PAL[\n";
+  O << "AttributeList[\n";
 
   for (unsigned i = index_begin(), e = index_end(); i != e; ++i) {
-if (getAttributes(i).hasAttributes())
-  O << "  { " << i << " => " << getAsString(i) << " }\n";
+if (getAttributes(i).hasAttributes()) {
+  O << "  { ";
+  switch (i) {
+  case AttrIndex::ReturnIndex:
+O << "return";
+break;
+  case AttrIndex::FunctionIndex:
+O << "function";
+break;
+  default:
+  O << "arg(" << i - AttrIndex::FirstArgIndex << ")";
+  }
+  O << " => " << getAsString(i) << " }\n";
+}
   }
 
   O << "]\n";

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e83599f7d08f9..856d1896489ff 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1895,13 +1895,13 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, 
AttributeList Attrs,
 
   if (AttributeListsVisited.insert(Attrs.getRawPointer()).second) {
 Assert(Attrs.hasParentContext(Context),
-   "Attribute list does not match Module context!", &Attrs);
+   "Attribute list does not match Module context!", &Attrs, V);
 for (const auto &AttrSet : Attrs) {
   Assert(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
- "Attribute set does not match Module context!", &AttrSet);
+ "Attribute set does not match Module context!", &AttrSet, V);
   for (const auto &A : AttrSet) {
 Assert(A.hasParentContext(Context),
-   "Attribute does not match Module context!", &A);
+   "Attribute does not match Module context!", &A, V);
   }
 }
   }

diff  --git a/llvm/unittests/IR/AttributesTest.cpp 
b/llvm/unittests/IR/AttributesTest.cpp
index 03b4cef404f5e..f260f0f9bf864 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -217,4 +217,39 @@ TEST(Attributes, HasParentContext) {
   }
 }
 
+TEST(Attributes, AttributeListPrinting) {
+  LLVMContext C;
+
+  {
+std::string S;
+raw_string_ostream OS(S);
+AttributeList AL;
+AL.addAttribute(C, AttributeList::FunctionIndex, Attribute::AlwaysInline)
+.print(OS);
+EXPECT_EQ(S, "AttributeList[\n"
+ "  { function => alwaysinline }\n"
+ "]\n");
+  }
+
+  {
+std::string S;
+raw_string_ostream OS(S);
+AttributeList AL;
+AL.addAttribute(C, AttributeList::ReturnIndex, Attribute::SExt).print(OS);
+EXPECT_EQ(S, "AttributeList[\n"
+ "  { return => signext }\n"
+ "]\n");
+  }
+
+  {
+std::string S;
+raw_string_ostream OS(S);
+AttributeList AL;
+AL.addParamAttribute(C, 5, Attribute::ZExt).print(OS);
+EXPECT_EQ(S, "AttributeList[\n"
+ "  { arg(5) => zeroext }\n"
+ "]\n");
+  }
+}
+
 } // end anonymous namespace



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 0e3f038 - [ASan] Rename `-fsanitize-address-destructor-kind=` to drop the `-kind` suffix.

2021-04-28 Thread Dan Liew via llvm-branch-commits

Author: Dan Liew
Date: 2021-04-28T18:58:55-07:00
New Revision: 0e3f038261be4799d0d09e70e165f526e182b0cf

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

LOG: [ASan] Rename `-fsanitize-address-destructor-kind=` to drop the `-kind` 
suffix.

Renaming the option is based on discussions in https://reviews.llvm.org/D101122.

It is normally not a good idea to rename driver flags but this flag is
new enough and obscure enough that it is very unlikely to have adopters.

While we're here also drop the `` metavar. It's not necessary and
is actually inconsistent with the documentation in
`clang/docs/ClangCommandLineReference.rst`.

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

Added: 
clang/test/Driver/fsanitize-address-destructor.c

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGen/asan-destructor-kind.cpp
clang/test/Driver/darwin-asan-mkernel-kext.c

Removed: 
clang/test/Driver/fsanitize-address-destructor-kind.c



diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 24e0040a4f50d..6b67dc07982bd 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -870,7 +870,7 @@ Enable use-after-scope detection in AddressSanitizer
 
 Enable ODR indicator globals to avoid false ODR violation reports in partially 
sanitized programs at the cost of an increase in binary size
 
-.. option:: -fsanitize-address-destructor-kind=
+.. option:: -fsanitize-address-destructor=
 
 Set the kind of module destructors emitted by AddressSanitizer instrumentation.
 These destructors are emitted to unregister instrumented global variables when

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index eaebed5978368..f30e08a2930f5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1540,8 +1540,7 @@ defm sanitize_address_use_odr_indicator : BoolOption<"f", 
"sanitize-address-use-
   NegFlag>,
   Group;
 def sanitize_address_destructor_kind_EQ
-: Joined<["-"], "fsanitize-address-destructor-kind=">,
-  MetaVarName<"">,
+: Joined<["-"], "fsanitize-address-destructor=">,
   Flags<[CC1Option]>,
   HelpText<"Set destructor type used in ASan instrumentation">,
   Group,

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 0f9f5d87696c4..de6f5796d6ec8 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1098,7 +1098,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const 
llvm::opt::ArgList &Args,
   // Only pass the option to the frontend if the user requested,
   // otherwise the frontend will just use the codegen default.
   if (AsanDtorKind != llvm::AsanDtorKind::Invalid) {
-CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-destructor-kind=" 
+
+CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-destructor=" +
  AsanDtorKindToString(AsanDtorKind)));
   }
 

diff  --git a/clang/test/CodeGen/asan-destructor-kind.cpp 
b/clang/test/CodeGen/asan-destructor-kind.cpp
index 567482b726435..8d70b663f67a2 100644
--- a/clang/test/CodeGen/asan-destructor-kind.cpp
+++ b/clang/test/CodeGen/asan-destructor-kind.cpp
@@ -1,9 +1,9 @@
 // Frontend rejects invalid option
 // RUN: not %clang_cc1 -fsanitize=address \
-// RUN:   -fsanitize-address-destructor-kind=bad_arg -emit-llvm -o - \
+// RUN:   -fsanitize-address-destructor=bad_arg -emit-llvm -o - \
 // RUN:   -triple x86_64-apple-macosx10.15 %s 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CHECK-BAD-ARG
-// CHECK-BAD-ARG: invalid value 'bad_arg' in 
'-fsanitize-address-destructor-kind=bad_arg'
+// CHECK-BAD-ARG: invalid value 'bad_arg' in 
'-fsanitize-address-destructor=bad_arg'
 
 // Default is global dtor
 // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-apple-macosx10.15 \
@@ -16,12 +16,12 @@
 
 // Explictly ask for global dtor
 // RUN: %clang_cc1 -fsanitize=address \
-// RUN:   -fsanitize-address-destructor-kind=global -emit-llvm -o - \
+// RUN:   -fsanitize-address-destructor=global -emit-llvm -o - \
 // RUN:   -triple x86_64-apple-macosx10.15 -fno-legacy-pass-manager %s | \
 // RUN:   FileCheck %s --check-prefixes=CHECK-GLOBAL-DTOR
 //
 // RUN: %clang_cc1 -fsanitize=address \
-// RUN:   -fsanitize-address-destructor-kind=global -emit-llvm -o - \
+// RUN:   -fsanitize-address-destructor=global -emit-llvm -o - \
 // RUN:   -triple x86_64-apple-macosx10.15 -flegacy-pass-manager %s | \
 // RUN:   FileCheck %s --check-prefixes=CHECK-GLOBAL-DTOR
 
@@ -30,12 +30,12 @@
 
 // Explictly ask for no