[PATCH] D104420: thread_local support for AIX

2021-07-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:265
 
+/// Create a stub function, suitable for being passed to atexit,
+/// which passes the given address to the given destructor function.

Since the function has some specifics about the stub function type and return 
value behaviour:
s/atexit/__pt_atexit_np/;




Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2959
+isEmittedWithConstantInitializer(VD, true) &&
+!VD->needsDestruction(getContext())) {
+  llvm::Function *Func = llvm::Function::Create(

An assertion that `Init` is null should be appropriate here: If it is non-null, 
then the pre-existing logic above would either be defining the function to be 
an alias or is declaring the function with the expectation that the definition 
of the variable is elsewhere.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2961
+  llvm::Function *Func = llvm::Function::Create(
+  InitFnTy, llvm::GlobalVariable::ExternalLinkage, InitFnName.str(),
+  ());

The linkage should be weak for a variable defined to be weak. For example, the 
code higher up uses `Var->getLinkage()` to produce the alias.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2988-2989
+} else if (CGM.getTriple().isOSAIX()) {
+  // On AIX, thread_local vars, other than non-class types or (possibly
+  // multi-dimensional) arrays or such types, will have init routines
+  // regardless of whether they are const-initialized or not.  Since the

This does not say that a `thread_local` variable of type `int` that is not 
`constinit` //does// have a guaranteed init routine.

Suggestion:
On AIX, except if constinit and also neither of class type or of (possibly 
multi-dimensional) array of class type, thread_local vars will have init 
routines regardless of whether they are const-initialized.



Comment at: clang/test/CodeGenCXX/cxx11-thread-local.cpp:241
   // LINUX: call i32 @__cxa_thread_atexit({{.*}}@_ZN1SD1Ev {{.*}} 
@_ZZ8tls_dtorvE1s{{.*}} @__dso_handle
+  // AIX: call i32 (i32, i32 (i32, ...)*, ...) @__pt_atexit_np(i32 0, 
{{.*}}@__dtor__ZZ8tls_dtorvE1s){{.*}}
   // DARWIN: call i32 @_tlv_atexit({{.*}}@_ZN1SD1Ev {{.*}} 
@_ZZ8tls_dtorvE1s{{.*}} @__dso_handle

Since the code to generate the stub is new, I believe inspecting the body of 
the stub in the test would be appropriate.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-14 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 358839.
RedDocMD added a comment.

Cleanup, still doesn't work


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105821/new/

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -19,6 +19,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace ento;
@@ -757,6 +758,7 @@
   for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
I != E; ++I)
 defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, 
*Call, *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -177,7 +177,9 @@
 
 bool SmartPtrModeling::evalCall(const CallEvent ,
 CheckerContext ) const {
+
   ProgramStateRef State = C.getState();
+  Call.dump();
   if (!smartptr::isStdSmartPtrCall(Call))
 return false;
 
@@ -261,6 +263,11 @@
 return true;
   }
 
+  if (const auto *DC = dyn_cast()) {
+llvm::errs() << "Wohoo\n";
+return true;
+  }
+
   if (handleAssignOp(Call, C))
 return true;
 


Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -19,6 +19,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace ento;
@@ -757,6 +758,7 @@
   for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
I != E; ++I)
 defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call, *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp

[PATCH] D105973: [ASTMatchers] NFC: Fix the annotation.

2021-07-14 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 358835.
Sockke added a comment.

update to display context.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105973/new/

https://reviews.llvm.org/D105973

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -913,7 +913,7 @@
 ///varDecl(hasInitializer(integerLiteral()))
 ///varDecl(hasInitializer(declRefExpr()))
 /// \endcode
-/// only match the declarations for b, c, and d.
+/// only match the declarations for a.
 AST_MATCHER_P(Expr, ignoringImpCasts,
   internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7701,7 +7701,7 @@
 While
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
-only match the declarations for b, c, and d.
+only match the declarations for a.
 
 
 


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -913,7 +913,7 @@
 ///varDecl(hasInitializer(integerLiteral()))
 ///varDecl(hasInitializer(declRefExpr()))
 /// \endcode
-/// only match the declarations for b, c, and d.
+/// only match the declarations for a.
 AST_MATCHER_P(Expr, ignoringImpCasts,
   internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7701,7 +7701,7 @@
 While
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
-only match the declarations for b, c, and d.
+only match the declarations for a.
 
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-07-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

In D106030#2878897 , @arsenm wrote:

> Adding something to the IR for the sole purpose of producing a diagnostic 
> feels really weird. I'm not sure I see why the frontend can't see this 
> attribute and directly warn

In C++, you can do trickery with template arguments to trigger compile errors, 
for example, the following:

  #include 
  template struct dependent_false : std::false_type {};
  template inline void f() {
if constexpr (x == 0) {
  /* do something */
} else if constexpr (x == 1) {
  /* do something else */
} else {
  static_assert(dependent_false() && "Invalid argument");
}
  }
  void g() { f<1>(); }

Now suppose you're an enterprising Linux kernel developer, and you decide you 
want this in C.  You don't really care about portability to compilers other 
than gcc, or compiling at any optimization level less than -O2, so instead of 
using a real language feature, you decide to depend on a combination of 
unintentional compiler semantics and linker diagnostics.  So you write 
something like the following:

  #define BUILD_BUG() undefined_symbol()
  extern void undefined_symbol();
  
  inline void f(int x) {
if (x == 0) {
  /* do something */
} else if (x == 1) {
  /* do something else */
} else {
  BUILD_BUG();
}
  }
  void g() { f(1); }

Then, after you're doing this for a while, you ask the gcc developers for a 
simple feature: an attribute you can apply to undefined_symbol that makes the 
compiler print the error message at compile-time instead of link-time.

---

Actually, in clang, you could probably use inline asm like the following to 
accomplish roughly the same thing, assuming you aren't building with 
-fno-integrated-as:

  #define BUILD_BUG() asm(".err \"BUILD_BUG\"")
  static inline void f(int x) {
if (x == 0) {
  /* do something */
} else if (x == 1) {
  /* do something else */
} else {
  BUILD_BUG();
}
  }
  void g() { f(2); }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106030/new/

https://reviews.llvm.org/D106030

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


[PATCH] D105973: [ASTMatchers] NFC: Fix the annotation.

2021-07-14 Thread liushuai wang via Phabricator via cfe-commits
MTC accepted this revision.
MTC added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for your cleanup.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105973/new/

https://reviews.llvm.org/D105973

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


[PATCH] D105957: [PowerPC] Implement intrinsics for mtfsf[i]

2021-07-14 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf accepted this revision.
qiucf added a comment.
This revision is now accepted and ready to land.

The PPC instructions tablegen part looks good to me.




Comment at: llvm/include/llvm/IR/IntrinsicsPowerPC.td:1589
[IntrNoMem, IntrHasSideEffects]>;
   def int_ppc_mtfsfi
   : GCCBuiltin<"__builtin_ppc_mtfsfi">,

If `mtfsf` was changed, `mtfsfi` `mtfsb0` `mtfsb1` should also be changed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105957/new/

https://reviews.llvm.org/D105957

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


[PATCH] D105973: [ASTMatchers] NFC: Fix the annotation.

2021-07-14 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 358820.
Sockke edited the summary of this revision.
Sockke added a comment.

Thanks for your review! I have run clang/docs/tools/dump_ast_matchers.py to 
regenerate the documentation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105973/new/

https://reviews.llvm.org/D105973

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -913,7 +913,7 @@
 ///varDecl(hasInitializer(integerLiteral()))
 ///varDecl(hasInitializer(declRefExpr()))
 /// \endcode
-/// only match the declarations for b, c, and d.
+/// only match the declarations for a.
 AST_MATCHER_P(Expr, ignoringImpCasts,
   internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7701,7 +7721,7 @@
 While
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
-only match the declarations for b, c, and d.
+only match the declarations for a.
 
 
 


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -913,7 +913,7 @@
 ///varDecl(hasInitializer(integerLiteral()))
 ///varDecl(hasInitializer(declRefExpr()))
 /// \endcode
-/// only match the declarations for b, c, and d.
+/// only match the declarations for a.
 AST_MATCHER_P(Expr, ignoringImpCasts,
   internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7701,7 +7721,7 @@
 While
varDecl(hasInitializer(integerLiteral()))
varDecl(hasInitializer(declRefExpr()))
-only match the declarations for b, c, and d.
+only match the declarations for a.
 
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham marked an inline comment as done.
bnbarham added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:2854
+bool recompileFinalized =
+Result == OutOfDate && Capabilities & ARR_OutOfDate &&
+getModuleManager().getModuleCache().isPCMFinal(F.FileName);

vsapsai wrote:
> I don't remember recommended LLVM style or if clang-tidy would complain about 
> it but `... & ... && ...` can be unclear regarding the priority of 
> operations. Personally, I would do `(... & ...) && ...` but I don't know what 
> is the rule, so not insisting.
I don't feel particularly strongly about it either way, so have just updated to 
add the parentheses :).

Also renamed `recompileFinalized` to `recompilingFinalized` as I thought that 
made more sense after coming back to it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105328/new/

https://reviews.llvm.org/D105328

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


[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham updated this revision to Diff 358826.
bnbarham marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105328/new/

https://reviews.llvm.org/D105328

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSerializationKinds.td
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/unittests/Serialization/CMakeLists.txt
  clang/unittests/Serialization/ModuleCacheTest.cpp

Index: clang/unittests/Serialization/ModuleCacheTest.cpp
===
--- /dev/null
+++ clang/unittests/Serialization/ModuleCacheTest.cpp
@@ -0,0 +1,179 @@
+//===- unittests/Serialization/ModuleCacheTest.cpp - CI tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/FileManager.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+class ModuleCacheTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modulecache-test", TestDir));
+
+ModuleCachePath = SmallString<256>(TestDir);
+sys::path::append(ModuleCachePath, "mcp");
+ASSERT_FALSE(sys::fs::create_directories(ModuleCachePath));
+  }
+
+  void TearDown() override { sys::fs::remove_directories(TestDir); }
+
+public:
+  SmallString<256> TestDir;
+  SmallString<256> ModuleCachePath;
+
+  void addFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+std::error_code EC;
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+OS << Contents;
+  }
+
+  void addDuplicateFrameworks() {
+addFile("test.m", R"cpp(
+@import Top;
+)cpp");
+
+addFile("frameworks/Top.framework/Headers/top.h", R"cpp(
+@import M;
+)cpp");
+addFile("frameworks/Top.framework/Modules/module.modulemap", R"cpp(
+framework module Top [system] {
+  header "top.h"
+  export *
+}
+)cpp");
+
+addFile("frameworks/M.framework/Headers/m.h", R"cpp(
+void foo();
+)cpp");
+addFile("frameworks/M.framework/Modules/module.modulemap", R"cpp(
+framework module M [system] {
+  header "m.h"
+  export *
+}
+)cpp");
+
+addFile("frameworks2/M.framework/Headers/m.h", R"cpp(
+void foo();
+)cpp");
+addFile("frameworks2/M.framework/Modules/module.modulemap", R"cpp(
+framework module M [system] {
+  header "m.h"
+  export *
+}
+)cpp");
+  }
+};
+
+TEST_F(ModuleCacheTest, CachedModuleNewPath) {
+  addDuplicateFrameworks();
+
+  SmallString<256> MCPArg("-fmodules-cache-path=");
+  MCPArg.append(ModuleCachePath);
+  IntrusiveRefCntPtr Diags =
+  CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+  // First run should pass with no errors
+  const char *Args[] = {"clang","-fmodules",  "-Fframeworks",
+MCPArg.c_str(), "-working-directory", TestDir.c_str(),
+"test.m"};
+  std::shared_ptr Invocation =
+  createInvocationFromCommandLine(Args, Diags);
+  ASSERT_TRUE(Invocation);
+  CompilerInstance Instance;
+  Instance.setDiagnostics(Diags.get());
+  Instance.setInvocation(Invocation);
+  SyntaxOnlyAction Action;
+  ASSERT_TRUE(Instance.ExecuteAction(Action));
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
+  // Now add `frameworks2` to the search path. `Top.pcm` will have a reference
+  // to the `M` from `frameworks`, but a search will find the `M` from
+  // `frameworks2` - causing a mismatch and it to be considered out of date.
+  //
+  // Normally this would be fine - `M` and the modules it depends on would be
+  // rebuilt. However, since we have a shared module cache and thus an already
+  // finalized `Top`, recompiling `Top` will cause the existing module to be
+  // removed from the cache, causing possible crashed if it is ever used.
+  //
+  // Make sure that an error occurs instead.
+  const char *Args2[] = {"clang", "-fmodules","-Fframeworks2",
+ "-Fframeworks",  MCPArg.c_str(), 

[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added a comment.
This revision is now accepted and ready to land.

Have 1 punctuation nit (that I'm not sure about), the rest looks good.




Comment at: clang/lib/Serialization/ASTReader.cpp:2854
+bool recompileFinalized =
+Result == OutOfDate && Capabilities & ARR_OutOfDate &&
+getModuleManager().getModuleCache().isPCMFinal(F.FileName);

I don't remember recommended LLVM style or if clang-tidy would complain about 
it but `... & ... && ...` can be unclear regarding the priority of operations. 
Personally, I would do `(... & ...) && ...` but I don't know what is the rule, 
so not insisting.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105328/new/

https://reviews.llvm.org/D105328

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


[PATCH] D105269: [X86] AVX512FP16 instructions enabling 6/6

2021-07-14 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: llvm/test/CodeGen/X86/avx512cfma-intrinsics.ll:3
+; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl -mattr=+avx512bw 
-mattr=+avx512fp16 -mattr=+avx512vl | FileCheck %s
+
+declare <4 x float> @llvm.x86.avx512fp16.mask.vfmaddc.ph.128(<4 x float>, <4 x 
float>, <4 x float>, i8)

Do we miss broadcast test case?



Comment at: llvm/test/CodeGen/X86/avx512cfmul-intrinsics.ll:3
+; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl -mattr=+avx512bw 
-mattr=+avx512fp16 -mattr=+avx512vl | FileCheck %s
+
+declare <4 x float> @llvm.x86.avx512fp16.mask.vfmulc.ph.128(<4 x float>, <4 x 
float>, <4 x float>, i8)

Do we miss broadcast test case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105269/new/

https://reviews.llvm.org/D105269

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


[PATCH] D105984: [PowerPC] Restore FastMathFlags of Builder for Vector FDiv Builtins

2021-07-14 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15140
+  Value *fdiv = Builder.CreateFDiv(X, Y, "recipdiv");
+  Builder.getFastMathFlags().operator&=(FMF);
+  return fdiv;




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105984/new/

https://reviews.llvm.org/D105984

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


[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-07-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Adding something to the IR for the sole purpose of producing a diagnostic feels 
really weird. I'm not sure I see why the frontend can't see this attribute and 
directly warn


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106030/new/

https://reviews.llvm.org/D106030

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


[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-07-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 358814.
nickdesaulniers added a comment.

- remove accidentally committed logging statement


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106030/new/

https://reviews.llvm.org/D106030

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-error.c
  clang/test/CodeGen/attr-warning.c
  clang/test/Frontend/backend-attribute-error-warning-optimize.c
  clang/test/Frontend/backend-attribute-error-warning.c
  clang/test/Frontend/backend-attribute-error-warning.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-error.c
  clang/test/Sema/attr-warning.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/test/CodeGen/Generic/attr-user-diagnostic.ll

Index: llvm/test/CodeGen/Generic/attr-user-diagnostic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Generic/attr-user-diagnostic.ll
@@ -0,0 +1,9 @@
+; RUN: not llc -stop-after=pre-isel-intrinsic-lowering %s 2>&1 | FileCheck %s
+
+declare void @foo() "user-diagnostic"="oh no"
+define void @bar() {
+  call void @foo()
+  ret void
+}
+
+; CHECK: error: call to foo: oh no
Index: llvm/lib/IR/DiagnosticInfo.cpp
===
--- llvm/lib/IR/DiagnosticInfo.cpp
+++ llvm/lib/IR/DiagnosticInfo.cpp
@@ -401,3 +401,7 @@
 
 void OptimizationRemarkAnalysisFPCommute::anchor() {}
 void OptimizationRemarkAnalysisAliasing::anchor() {}
+
+void DiagnosticInfoUser::print(DiagnosticPrinter ) const {
+  DP << "call to " << getFunctionName() << ": " << getMsgStr();
+}
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -14,6 +14,7 @@
 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
 #include "llvm/Analysis/ObjCARCInstKind.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instructions.h"
@@ -204,6 +205,25 @@
   Changed |= lowerObjCCall(F, "objc_sync_exit");
   break;
 }
+// TODO: is this the best pass for this?
+for (BasicBlock  : F) {
+  for (Instruction  : BB) {
+if (CallBase *CB = dyn_cast()) {
+  if (Function *Callee = CB->getCalledFunction()) {
+if (Callee->hasFnAttribute("user-diagnostic")) {
+  unsigned LocCookie = 0;
+  if (MDNode *MD = CB->getMetadata("srcloc"))
+LocCookie = mdconst::extract(MD->getOperand(0))
+->getZExtValue();
+  DiagnosticInfoUser DU(
+  Callee->getFnAttribute("user-diagnostic").getValueAsString(),
+  Callee->getName(), LocCookie);
+  F.getContext().diagnose(DU);
+}
+  }
+}
+  }
+}
   }
   return Changed;
 }
Index: llvm/include/llvm/IR/DiagnosticInfo.h
===
--- llvm/include/llvm/IR/DiagnosticInfo.h
+++ llvm/include/llvm/IR/DiagnosticInfo.h
@@ -79,6 +79,7 @@
   DK_PGOProfile,
   DK_Unsupported,
   DK_SrcMgr,
+  DK_UserDiagnostic,
   DK_FirstPluginKind // Must be last value to work with
  // getNextAvailablePluginDiagnosticKind
 };
@@ -1070,6 +1071,25 @@
   }
 };
 
+class DiagnosticInfoUser : public DiagnosticInfo {
+  StringRef MsgStr;
+  StringRef CalleeName;
+  unsigned LocCookie;
+
+public:
+  DiagnosticInfoUser(StringRef MsgStr, StringRef CalleeName, unsigned LocCookie,
+ DiagnosticSeverity Severity = DS_Error)
+  : DiagnosticInfo(DK_UserDiagnostic, Severity), MsgStr(MsgStr),
+CalleeName(CalleeName), LocCookie(LocCookie) {}
+  StringRef getMsgStr() const { return MsgStr; }
+  StringRef getFunctionName() const { return CalleeName; }
+  unsigned getLocCookie() const { return LocCookie; }
+  void print(DiagnosticPrinter ) const override;
+  static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_UserDiagnostic;
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_DIAGNOSTICINFO_H
Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -2037,6 +2037,12 @@
 show that no exceptions passes by it. This is normally the case for
 the ELF x86-64 abi, but it can be disabled for 

[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-07-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp:208
 }
+// TODO: is this the best pass for this?
+for (BasicBlock  : F) {

Why not just do in in codegen in IRTranslator/SelectionDAGBuilder?



Comment at: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp:212
+if (CallBase *CB = dyn_cast()) {
+  if (Function *Callee = CB->getCalledFunction()) {
+if (Callee->hasFnAttribute("user-diagnostic")) {

What's the expected behavior if the function is called indirectly?



Comment at: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp:219
+  DiagnosticInfoUser DU(
+  Callee->getFnAttribute("user-diagnostic").getValueAsString(),
+  Callee->getName(), LocCookie);

Just do one getFnAttribute instead of pre-checking it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106030/new/

https://reviews.llvm.org/D106030

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


[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-07-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: rsmith, aaron.ballman, craig.topper, efriedma, 
lebedev.ri, jdoerfert, arsenm.
Herald added subscribers: dexonsmith, hiraditya.
nickdesaulniers requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wdng.
Herald added projects: clang, LLVM.

Add support for the GNU C style __attribute__((error(""))) and
__attribute__((warning(""))). These attributes are meant to be put on
definitions of functions whom should not be called.

They are frequently used to provide compile time diagnostics similar to
_Static_assert, but which may rely on non-ICE conditions (ie. relying on
compiler optimizations). While users may instead simply call undefined
functions in such cases to get a linkage failure from the linker, these
provide a much more ergonomic and actionable diagnostic to users and do
so at compile time rather than at link time.

These are used throughout the Linux kernel in its implementation of
BUILD_BUG and BUILD_BUG_ON macros. These macros generally cannot be
converted to use _Static_assert because many of the parameters are not
ICEs. The Linux kernel still needs to be modified to make use of these
when building with Clang; I have a patch that does so I will send once
this feature is landed.

To do so, we create a new IR level Function attribute,
"user-diagnostic"="" which contains the string parameter from source
language function attributes (both error and warning boil down to one IR
Fn Attr). Then, similar to calls to inline asm, we attach a !srcloc
Metadata node to call sites of such attributed callees.

The backend diagnoses these before instruction selection, while we still
know that a call is a call (vs say a JMP that's a tail call) in an arch
agnostic manner.

The frontend then reconstructs the SourceLocation from that Metadata,
and determines whether to emit an error or warning based on the callee's
attribute.

Some things to iron out TODO:

- Is user-diagnostic the best identifier for the new fn attr? Maybe 
"diagnose-if-called"? I also use `UserDiagnostic` throughout much of this patch 
for C++ class names; surely there's something better?
- When is the best time for the backend to produce such diagnostics? If we wait 
until post-ISEL, then we need to diagnose instructions which may be JMPs, not 
just CALLs.

Link: https://bugs.llvm.org/show_bug.cgi?id=16428
Link: https://github.com/ClangBuiltLinux/linux/issues/1173


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106030

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-error.c
  clang/test/CodeGen/attr-warning.c
  clang/test/Frontend/backend-attribute-error-warning-optimize.c
  clang/test/Frontend/backend-attribute-error-warning.c
  clang/test/Frontend/backend-attribute-error-warning.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-error.c
  clang/test/Sema/attr-warning.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/test/CodeGen/Generic/attr-user-diagnostic.ll

Index: llvm/test/CodeGen/Generic/attr-user-diagnostic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Generic/attr-user-diagnostic.ll
@@ -0,0 +1,9 @@
+; RUN: not llc -stop-after=pre-isel-intrinsic-lowering %s 2>&1 | FileCheck %s
+
+declare void @foo() "user-diagnostic"="oh no"
+define void @bar() {
+  call void @foo()
+  ret void
+}
+
+; CHECK: error: call to foo: oh no
Index: llvm/lib/IR/DiagnosticInfo.cpp
===
--- llvm/lib/IR/DiagnosticInfo.cpp
+++ llvm/lib/IR/DiagnosticInfo.cpp
@@ -401,3 +401,7 @@
 
 void OptimizationRemarkAnalysisFPCommute::anchor() {}
 void OptimizationRemarkAnalysisAliasing::anchor() {}
+
+void DiagnosticInfoUser::print(DiagnosticPrinter ) const {
+  DP << "call to " << getFunctionName() << ": " << getMsgStr();
+}
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -14,6 +14,7 @@
 #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
 #include "llvm/Analysis/ObjCARCInstKind.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instructions.h"
@@ -204,6 +205,25 @@
   Changed |= lowerObjCCall(F, "objc_sync_exit");
   break;
 }
+// TODO: is this the best pass for this?
+

[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham marked 2 inline comments as done.
bnbarham added inline comments.



Comment at: clang/lib/Frontend/CompilerInstance.cpp:1063
+<< ModuleName;
+return ImportingInstance.getFrontendOpts().AllowPCMWithCompilerErrors;
+  }

vsapsai wrote:
> bnbarham wrote:
> > bnbarham wrote:
> > > vsapsai wrote:
> > > > Can we get in infinite loop with `AllowPCMWithCompilerErrors = true`? 
> > > > Specifically, I'm thinking about the scenario
> > > > 
> > > > 1. `compileModuleAndReadAST` obtains a file lock and calls 
> > > > `compileModule`
> > > > 2. `compileModule` calls `compileModuleImpl`
> > > > 3. Module is finalized but `AllowPCMWithCompilerErrors` is true, so 
> > > > `compileModuleImpl` returns true
> > > > 4. `compileModule` returns true
> > > > 5. `compileModuleAndReadAST` tries to read AST because compilation was 
> > > > successful
> > > > 6. AST is out of date, so `compileModuleAndReadAST` decides to try 
> > > > again, goto 1
> > > > 
> > > > Haven't tried to reproduce it locally but even if this scenario is 
> > > > impossible, a corresponding test case can be useful.
> > > Nice catch, that does seem likely - I'll see if I can add a test for this.
> > It doesn't end up causing an infinite recursion as `false` will end up 
> > being returned from `compileModuleAndReadAST`, but in that case there's no 
> > point returning `true` from `compileModuleImpl` in the first place so I've 
> > changed it anyway. Have also added that as a test case, just to make sure.
> Thanks for investigating it and adding a test case.
> 
> And appreciate that the error message mentions the module name. It is so hard 
> to work with errors like "cannot rebuild this module".
Note that this error is really just a fallback - it will be silenced by the 
previous fatal errors in ASTReader.



Comment at: clang/lib/Serialization/ASTReader.cpp:2859-2860
   << F.FileName << !F.ModuleName.empty() << F.ModuleName;
+if (recompileFinalized)
+  Diag(diag::note_module_file_conflict);
 

The failing test was because this note was being output when if `OutOfDate` 
wasn't in `Capabilities`. It should only get output when `OutOfDate` can be 
handled (ie. it'd be recompiled) *and* the module is already finalized.



Comment at: clang/lib/Serialization/ASTReader.cpp:5929
 
+bool ASTReader::diagnoseOutOfDate(StringRef ModuleFileName,
+  unsigned int ClientLoadCapabilities) {

vsapsai wrote:
> bnbarham wrote:
> > bnbarham wrote:
> > > vsapsai wrote:
> > > > Based on the rest of the code in clang, the expectation for 
> > > > `diagnose...` methods is to emit diagnostic in some cases. Personally, 
> > > > I'm often confused what true/false means for these methods, so I'm 
> > > > thinking about renaming the method to something like 
> > > > isRecoverableOutOfDateModule, canRecoverOutOfDateModule or some such. 
> > > > Feel free to pick a name you believe is appropriate, mine are just 
> > > > examples.
> > > Fair enough, `canRecoverOutOfDateModule` sounds reasonable to me. Or 
> > > maybe `canRecoverFromOutOfDate`?
> > I went with the latter.
> I think with the current naming we need to flip the conditions to opposite. 
> Currently,
> 
> ```lang=c++
>   return !(ClientLoadCapabilities & ARR_OutOfDate) ||
>  getModuleManager().getModuleCache().isPCMFinal(ModuleFileName);
> ```
> 
> corresponds to `cannotRecoverFromOutOfDate`. But to avoid double negations it 
> is better to have `canRecoverFromOutOfDate` (with `(ClientLoadCapabilities & 
> ARR_OutOfDate) && !isPCMFinal(ModuleFileName)`) and call it as 
> `!canRecoverFromOutOfDate` when necessary.
Argh, sorry - just did a find + replace without thinking. Have flipped that 
function and its calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105328/new/

https://reviews.llvm.org/D105328

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


[PATCH] D105328: [Frontend] Only compile modules if not already finalized

2021-07-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham updated this revision to Diff 358798.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105328/new/

https://reviews.llvm.org/D105328

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticSerializationKinds.td
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/unittests/Serialization/CMakeLists.txt
  clang/unittests/Serialization/ModuleCacheTest.cpp

Index: clang/unittests/Serialization/ModuleCacheTest.cpp
===
--- /dev/null
+++ clang/unittests/Serialization/ModuleCacheTest.cpp
@@ -0,0 +1,179 @@
+//===- unittests/Serialization/ModuleCacheTest.cpp - CI tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/FileManager.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+class ModuleCacheTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modulecache-test", TestDir));
+
+ModuleCachePath = SmallString<256>(TestDir);
+sys::path::append(ModuleCachePath, "mcp");
+ASSERT_FALSE(sys::fs::create_directories(ModuleCachePath));
+  }
+
+  void TearDown() override { sys::fs::remove_directories(TestDir); }
+
+public:
+  SmallString<256> TestDir;
+  SmallString<256> ModuleCachePath;
+
+  void addFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+std::error_code EC;
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+OS << Contents;
+  }
+
+  void addDuplicateFrameworks() {
+addFile("test.m", R"cpp(
+@import Top;
+)cpp");
+
+addFile("frameworks/Top.framework/Headers/top.h", R"cpp(
+@import M;
+)cpp");
+addFile("frameworks/Top.framework/Modules/module.modulemap", R"cpp(
+framework module Top [system] {
+  header "top.h"
+  export *
+}
+)cpp");
+
+addFile("frameworks/M.framework/Headers/m.h", R"cpp(
+void foo();
+)cpp");
+addFile("frameworks/M.framework/Modules/module.modulemap", R"cpp(
+framework module M [system] {
+  header "m.h"
+  export *
+}
+)cpp");
+
+addFile("frameworks2/M.framework/Headers/m.h", R"cpp(
+void foo();
+)cpp");
+addFile("frameworks2/M.framework/Modules/module.modulemap", R"cpp(
+framework module M [system] {
+  header "m.h"
+  export *
+}
+)cpp");
+  }
+};
+
+TEST_F(ModuleCacheTest, CachedModuleNewPath) {
+  addDuplicateFrameworks();
+
+  SmallString<256> MCPArg("-fmodules-cache-path=");
+  MCPArg.append(ModuleCachePath);
+  IntrusiveRefCntPtr Diags =
+  CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+  // First run should pass with no errors
+  const char *Args[] = {"clang","-fmodules",  "-Fframeworks",
+MCPArg.c_str(), "-working-directory", TestDir.c_str(),
+"test.m"};
+  std::shared_ptr Invocation =
+  createInvocationFromCommandLine(Args, Diags);
+  ASSERT_TRUE(Invocation);
+  CompilerInstance Instance;
+  Instance.setDiagnostics(Diags.get());
+  Instance.setInvocation(Invocation);
+  SyntaxOnlyAction Action;
+  ASSERT_TRUE(Instance.ExecuteAction(Action));
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
+  // Now add `frameworks2` to the search path. `Top.pcm` will have a reference
+  // to the `M` from `frameworks`, but a search will find the `M` from
+  // `frameworks2` - causing a mismatch and it to be considered out of date.
+  //
+  // Normally this would be fine - `M` and the modules it depends on would be
+  // rebuilt. However, since we have a shared module cache and thus an already
+  // finalized `Top`, recompiling `Top` will cause the existing module to be
+  // removed from the cache, causing possible crashed if it is ever used.
+  //
+  // Make sure that an error occurs instead.
+  const char *Args2[] = {"clang", "-fmodules","-Fframeworks2",
+ "-Fframeworks",  MCPArg.c_str(), "-working-directory",
+ 

[PATCH] D105526: opencl-c.h: CL3.0 generic address space

2021-07-14 Thread Dave Airlie via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde79ba9f9a2d: [OpenCL] opencl-c.h: CL3.0 generic address 
space (authored by airlied).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105526/new/

https://reviews.llvm.org/D105526

Files:
  clang/lib/Headers/opencl-c.h

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -7259,7 +7259,7 @@
  * Returns fmin(x - floor (x), 0x1.fep-1f ).
  * floor(x) is returned in iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld fract(float x, float *iptr);
 float2 __ovld fract(float2 x, float2 *iptr);
 float3 __ovld fract(float3 x, float3 *iptr);
@@ -7341,7 +7341,7 @@
 half8 __ovld fract(half8 x, __private half8 *iptr);
 half16 __ovld fract(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Extract mantissa and exponent from x. For each
@@ -7349,7 +7349,7 @@
  * magnitude in the interval [1/2, 1) or 0. Each
  * component of x equals mantissa returned * 2^exp.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld frexp(float x, int *exp);
 float2 __ovld frexp(float2 x, int2 *exp);
 float3 __ovld frexp(float3 x, int3 *exp);
@@ -7431,7 +7431,7 @@
 half8 __ovld frexp(half8 x, __private int8 *exp);
 half16 __ovld frexp(half16 x, __private int16 *exp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute the value of the square root of x^2 + y^2
@@ -7556,7 +7556,7 @@
 half16 __ovld __cnfn lgamma(half16 x);
 #endif //cl_khr_fp16
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld lgamma_r(float x, int *signp);
 float2 __ovld lgamma_r(float2 x, int2 *signp);
 float3 __ovld lgamma_r(float3 x, int3 *signp);
@@ -7638,7 +7638,7 @@
 half8 __ovld lgamma_r(half8 x, __private int8 *signp);
 half16 __ovld lgamma_r(half16 x, __private int16 *signp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute natural logarithm.
@@ -7862,7 +7862,7 @@
  * the argument. It stores the integral part in the object
  * pointed to by iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld modf(float x, float *iptr);
 float2 __ovld modf(float2 x, float2 *iptr);
 float3 __ovld modf(float3 x, float3 *iptr);
@@ -7944,7 +7944,7 @@
 half8 __ovld modf(half8 x, __private half8 *iptr);
 half16 __ovld modf(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Returns a quiet NaN. The nancode may be placed
@@ -8122,7 +8122,7 @@
  * sign as x/y. It stores this signed value in the object
  * pointed to by quo.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld remquo(float x, float y, int *quo);
 float2 __ovld remquo(float2 x, float2 y, int2 *quo);
 float3 __ovld remquo(float3 x, float3 y, int3 *quo);
@@ -8205,7 +8205,7 @@
 half8 __ovld remquo(half8 x, half8 y, __private int8 *quo);
 half16 __ovld remquo(half16 x, half16 y, __private int16 *quo);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 /**
  * Round to integral value (using round to nearest
  * even rounding mode) in floating-point format.
@@ -8346,7 +8346,7 @@
  * is the return value and computed cosine is returned
  * in cosval.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld sincos(float x, float *cosval);
 float2 __ovld sincos(float2 x, float2 *cosval);
 float3 __ovld sincos(float3 x, float3 *cosval);
@@ -8428,7 +8428,7 @@
 half8 __ovld sincos(half8 x, __private half8 *cosval);
 half16 __ovld sincos(half16 x, __private half16 *cosval);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute hyperbolic sine.
@@ -11249,7 +11249,7 @@
 half16 

[clang] de79ba9 - [OpenCL] opencl-c.h: CL3.0 generic address space

2021-07-14 Thread Dave Airlie via cfe-commits

Author: Dave Airlie
Date: 2021-07-15T10:51:04+10:00
New Revision: de79ba9f9a2de3d86fa3f44b57e147844b6f2625

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

LOG: [OpenCL] opencl-c.h: CL3.0 generic address space

This is one of the easier pieces of adding CL3.0 support.

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 8a5b6c2919ad..d50f0b8d2e8f 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -7259,7 +7259,7 @@ half16 __ovld __cnfn fmod(half16 x, half16 y);
  * Returns fmin(x - floor (x), 0x1.fep-1f ).
  * floor(x) is returned in iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld fract(float x, float *iptr);
 float2 __ovld fract(float2 x, float2 *iptr);
 float3 __ovld fract(float3 x, float3 *iptr);
@@ -7341,7 +7341,7 @@ half4 __ovld fract(half4 x, __private half4 *iptr);
 half8 __ovld fract(half8 x, __private half8 *iptr);
 half16 __ovld fract(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Extract mantissa and exponent from x. For each
@@ -7349,7 +7349,7 @@ half16 __ovld fract(half16 x, __private half16 *iptr);
  * magnitude in the interval [1/2, 1) or 0. Each
  * component of x equals mantissa returned * 2^exp.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld frexp(float x, int *exp);
 float2 __ovld frexp(float2 x, int2 *exp);
 float3 __ovld frexp(float3 x, int3 *exp);
@@ -7431,7 +7431,7 @@ half4 __ovld frexp(half4 x, __private int4 *exp);
 half8 __ovld frexp(half8 x, __private int8 *exp);
 half16 __ovld frexp(half16 x, __private int16 *exp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute the value of the square root of x^2 + y^2
@@ -7556,7 +7556,7 @@ half8 __ovld __cnfn lgamma(half8 x);
 half16 __ovld __cnfn lgamma(half16 x);
 #endif //cl_khr_fp16
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld lgamma_r(float x, int *signp);
 float2 __ovld lgamma_r(float2 x, int2 *signp);
 float3 __ovld lgamma_r(float3 x, int3 *signp);
@@ -7638,7 +7638,7 @@ half4 __ovld lgamma_r(half4 x, __private int4 *signp);
 half8 __ovld lgamma_r(half8 x, __private int8 *signp);
 half16 __ovld lgamma_r(half16 x, __private int16 *signp);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Compute natural logarithm.
@@ -7862,7 +7862,7 @@ half16 __ovld __cnfn minmag(half16 x, half16 y);
  * the argument. It stores the integral part in the object
  * pointed to by iptr.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld modf(float x, float *iptr);
 float2 __ovld modf(float2 x, float2 *iptr);
 float3 __ovld modf(float3 x, float3 *iptr);
@@ -7944,7 +7944,7 @@ half4 __ovld modf(half4 x, __private half4 *iptr);
 half8 __ovld modf(half8 x, __private half8 *iptr);
 half16 __ovld modf(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 
 /**
  * Returns a quiet NaN. The nancode may be placed
@@ -8122,7 +8122,7 @@ half16 __ovld __cnfn remainder(half16 x, half16 y);
  * sign as x/y. It stores this signed value in the object
  * pointed to by quo.
  */
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__opencl_c_generic_address_space)
 float __ovld remquo(float x, float y, int *quo);
 float2 __ovld remquo(float2 x, float2 y, int2 *quo);
 float3 __ovld remquo(float3 x, float3 y, int3 *quo);
@@ -8205,7 +8205,7 @@ half4 __ovld remquo(half4 x, half4 y, __private int4 
*quo);
 half8 __ovld remquo(half8 x, half8 y, __private int8 *quo);
 half16 __ovld remquo(half16 x, half16 y, __private int16 *quo);
 #endif //cl_khr_fp16
-#endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
+#endif //defined(__opencl_c_generic_address_space)
 /**
  * Round to integral value (using round to nearest
  * even rounding mode) in 

[PATCH] D105601: opencl-c.h: reorder atomic operations

2021-07-14 Thread Dave Airlie via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG090f007e3481: [OpenCL][NFC] opencl-c.h: reorder atomic 
operations (authored by airlied).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105601/new/

https://reviews.llvm.org/D105601

Files:
  clang/lib/Headers/opencl-c.h

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -13306,91 +13306,35 @@
 // atomic_fetch()
 
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_sub(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_sub_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_sub_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_or(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_or_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_or_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_or(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_or_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_or_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_xor(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_xor_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_xor_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_xor(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_xor_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_xor_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_and(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_and_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_and_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_and(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_and_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_and_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_min(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_min_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_min_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_min(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_min_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_min_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_max(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_max_explicit(volatile atomic_int *object, int operand, memory_order order);
-int __ovld atomic_fetch_max_explicit(volatile atomic_int *object, int operand, memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_max(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_max_explicit(volatile atomic_uint *object, uint operand, memory_order order);
-uint __ovld atomic_fetch_max_explicit(volatile atomic_uint *object, uint operand, memory_order order, memory_scope scope);
 
 #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 long __ovld atomic_fetch_add(volatile atomic_long *object, long operand);
-long __ovld 

[clang] 090f007 - [OpenCL][NFC] opencl-c.h: reorder atomic operations

2021-07-14 Thread Dave Airlie via cfe-commits

Author: Dave Airlie
Date: 2021-07-15T10:48:44+10:00
New Revision: 090f007e3481863430e4443765769e73f8f40e5f

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

LOG: [OpenCL][NFC] opencl-c.h: reorder atomic operations

This just reorders the atomics, it doesn't change anything except their layout 
in the header.

This is a prep patch for adding some conditionals around these for CL3.0 but 
that patch is much easier to review if all the atomic operations are grouped 
together like this.

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index bfdd9b84dced..8a5b6c2919ad 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13306,91 +13306,35 @@ void __ovld atomic_work_item_fence(cl_mem_fence_flags 
flags, memory_order order,
 // atomic_fetch()
 
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_add_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_add_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_sub_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_sub(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_sub_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_sub_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_or(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_or_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_or_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_or(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_or_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_or_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_xor(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_xor_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_xor_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_xor(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_xor_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_xor_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_and(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_and_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_and_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_and(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_and_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_and_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_min(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_min_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld atomic_fetch_min_explicit(volatile atomic_int *object, int operand, 
memory_order order, memory_scope scope);
 uint __ovld atomic_fetch_min(volatile atomic_uint *object, uint operand);
-uint __ovld atomic_fetch_min_explicit(volatile atomic_uint *object, uint 
operand, memory_order order);
-uint __ovld atomic_fetch_min_explicit(volatile atomic_uint *object, uint 
operand, memory_order order, memory_scope scope);
 int __ovld atomic_fetch_max(volatile atomic_int *object, int operand);
-int __ovld atomic_fetch_max_explicit(volatile atomic_int *object, int operand, 
memory_order order);
-int __ovld 

[libclc] ea469b0 - libclc: Add -cl-no-stdinc to clang flags on clang >=13

2021-07-14 Thread Dave Airlie via cfe-commits

Author: Jan Vesely
Date: 2021-07-15T10:43:26+10:00
New Revision: ea469b08b847cef5f4c8187228f1e4bbf881706a

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

LOG: libclc: Add -cl-no-stdinc to clang flags on clang >=13

cf3ef15a6ec5e5b45c6c54e8fbe3769255e815ce ("[OpenCL] Add builtin
declarations by default.")
 switched behaviour to include "opencl-c-base.h". We don't want or need
 that for libclc so pass the flag to revert to old behaviour.

Fixes build since cf3ef15a6ec5e5b45c6c54e8fbe3769255e815ce

Reviewed By: tstellar

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

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 7f8d81e9036ab..ec39ea63f2d02 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -124,7 +124,6 @@ set( CMAKE_CLC_ARCHIVE ${LLVM_LINK} )
 set( CMAKE_LLAsm_PREPROCESSOR ${LLVM_CLANG} )
 set( CMAKE_LLAsm_COMPILER ${LLVM_AS} )
 set( CMAKE_LLAsm_ARCHIVE ${LLVM_LINK} )
-enable_language( CLC LLAsm )
 
 # Construct LLVM version define
 string( REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_VERSION} )
@@ -132,6 +131,15 @@ list( GET LLVM_VERSION_LIST 0 LLVM_MAJOR )
 list( GET LLVM_VERSION_LIST 1 LLVM_MINOR )
 set( LLVM_VERSION_DEFINE "-DHAVE_LLVM=0x${LLVM_MAJOR}0${LLVM_MINOR}" )
 
+
+# LLVM 13 enables standard includes by default
+if( ${LLVM_VERSION} VERSION_GREATER "12.99.99" )
+   set( CMAKE_LLAsm_FLAGS ${CMAKE_LLAsm_FLAGS} 
-cl-no-stdinc )
+   set( CMAKE_CLC_FLAGS ${CMAKE_CLC_FLAGS} 
-cl-no-stdinc )
+endif()
+
+enable_language( CLC LLAsm )
+
 # This needs to be set before any target that needs it
 link_directories( ${LLVM_LIBDIR} )
 



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


[PATCH] D105974: [analyzer] Do not assume that all pointers have the same bitwidth as void*

2021-07-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks for the updates, comments and the reproducer. I've added those in this 
update. If possible, I'd like to get this change accepted to avoid the crash we 
currently see, and I'll immediately follow up with the FIXMEs. Otherwise, I'll 
iterate quickly on the FIXMEs. - Vince




Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:718
+  QualType Ty = Sym->getType();
+  // FIXME: Why did we have references at this point?
+  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`

NoQ wrote:
> I guess something like this?
> ```lang=c++
> void foo(int ) {
>   int *p =  // 'p' is the same SVal as 'x'
>   bool b = p;
> }
> ```
> I think we should return a concrete `true` in the reference case. We already 
> know that such symbol is true-ish but returning a concrete `true` might be 
> easier on the solver.
I think this comment is addressed by changing the comment, and deferring a 
subsequent follow up. I'd like to get this change submitted to at least avoid 
the crash if possible? Otherwise, if needed, I'll iterate quickly on trying to 
return a concrete 'true' for the reference case. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105974/new/

https://reviews.llvm.org/D105974

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


[PATCH] D105974: [analyzer] Do not assume that all pointers have the same bitwidth as void*

2021-07-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 358792.
vabridgers added a comment.

address comments, add test case suggested by @bjope


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105974/new/

https://reviews.llvm.org/D105974

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-ptr-bool.cl


Index: clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -target-cpu verde 
-analyze -analyzer-checker=core %s
+
+// expected-no-diagnostics
+
+// This test case covers an issue found in the static analyzer
+// solver where pointer sizes were assumed. Pointer sizes may vary on other
+// architectures. This issue was originally discovered on a downstream,
+// custom target, this assert occurs on the custom target and this one
+// without the fix, and is fixed with this change.
+//
+// The assertion appears to be happening as a result of evaluating the
+// SymIntExpr (reg_$0) != 0U in VisitSymIntExpr located in
+// SimpleSValBuilder.cpp. The LHS is evaluated to 32b and the RHS is
+// evaluated to 16b. This eventually leads to the assertion in APInt.h.
+//
+// APInt.h:1151: bool llvm::APInt::operator==(const llvm::APInt &) const: 
Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"'
+// 
+void test(__attribute__((address_space(256))) int * p) {
+  __attribute__((address_space(256))) int * q = p-1;
+  if (q) {}
+  if (q) {}
+  (void)q;
+} 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -712,9 +712,23 @@
   // symbols to use, only content metadata.
   return nonloc::SymbolVal(SymMgr.getExtentSymbol(FTR));
 
-if (const SymbolicRegion *SymR = R->getSymbolicBase())
-  return makeNonLoc(SymR->getSymbol(), BO_NE,
-BasicVals.getZeroWithPtrWidth(), CastTy);
+if (const SymbolicRegion *SymR = R->getSymbolicBase()) {
+  SymbolRef Sym = SymR->getSymbol();
+  QualType Ty = Sym->getType();
+  // This change is needed for architectures with varying
+  // pointer widths. See the amdgcn opencl reproducer with
+  // this change as an example: solver-sym-simplification-ptr-bool.cl
+  // FIXME: We could encounter a reference here,
+  //try returning a concrete 'true' since it might
+  //be easier on the solver.
+  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
+  //and `getIntWithPtrWidth()` functions to prevent future
+  //confusion
+  const llvm::APSInt  = Ty->isReferenceType()
+ ? BasicVals.getZeroWithPtrWidth()
+ : BasicVals.getZeroWithTypeSize(Ty);
+  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+}
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
   }


Index: clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -analyze -analyzer-checker=core %s
+
+// expected-no-diagnostics
+
+// This test case covers an issue found in the static analyzer
+// solver where pointer sizes were assumed. Pointer sizes may vary on other
+// architectures. This issue was originally discovered on a downstream,
+// custom target, this assert occurs on the custom target and this one
+// without the fix, and is fixed with this change.
+//
+// The assertion appears to be happening as a result of evaluating the
+// SymIntExpr (reg_$0) != 0U in VisitSymIntExpr located in
+// SimpleSValBuilder.cpp. The LHS is evaluated to 32b and the RHS is
+// evaluated to 16b. This eventually leads to the assertion in APInt.h.
+//
+// APInt.h:1151: bool llvm::APInt::operator==(const llvm::APInt &) const: Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"'
+// 
+void test(__attribute__((address_space(256))) int * p) {
+  __attribute__((address_space(256))) int * q = p-1;
+  if (q) {}
+  if (q) {}
+  (void)q;
+} 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -712,9 +712,23 @@
   // symbols to use, only content metadata.
   return nonloc::SymbolVal(SymMgr.getExtentSymbol(FTR));
 
-if (const SymbolicRegion *SymR = R->getSymbolicBase())
-  return 

[PATCH] D106027: Allow setting CLANG_LINKS_TO_CREATE to an empty list

2021-07-14 Thread Dmitry Kalinkin via Phabricator via cfe-commits
veprbl created this revision.
Herald added a subscriber: mgorny.
veprbl requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A user might want to redefine CLANG_LINKS_TO_CREATE to an empty list `""`, but 
such a value would be considered as a `FALSE` by cmake.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106027

Files:
  clang/tools/driver/CMakeLists.txt


Index: clang/tools/driver/CMakeLists.txt
===
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -58,7 +58,7 @@
 
 add_dependencies(clang clang-resource-headers)
 
-if(NOT CLANG_LINKS_TO_CREATE)
+if(NOT DEFINED CLANG_LINKS_TO_CREATE)
   set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
 endif()
 


Index: clang/tools/driver/CMakeLists.txt
===
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -58,7 +58,7 @@
 
 add_dependencies(clang clang-resource-headers)
 
-if(NOT CLANG_LINKS_TO_CREATE)
+if(NOT DEFINED CLANG_LINKS_TO_CREATE)
   set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
 endif()
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104744: [PowerPC] Add PowerPC rotate related builtins and emit target independent code for XL compatibility

2021-07-14 Thread Victor Huang via Phabricator via cfe-commits
NeHuang updated this revision to Diff 358761.
NeHuang marked 4 inline comments as done.
NeHuang added a comment.

Address review comments from Nemanja.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104744/new/

https://reviews.llvm.org/D104744

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+
+extern unsigned int ui;
+extern unsigned long long ull;
+
+void test_builtin_ppc_rldimi() {
+  // CHECK-LABEL: test_builtin_ppc_rldimi
+  // CHECK:   %res = alloca i64, align 8
+  // CHECK-NEXT:  [[RA:%[0-9]+]] = load i64, i64* @ull, align 8
+  // CHECK-NEXT:  [[RB:%[0-9]+]] = load i64, i64* @ull, align 8
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.fshl.i64(i64 [[RA]], i64 [[RA]], i64 63)
+  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i64 [[RC]], 72057593769492480
+  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i64 [[RB]], -72057593769492481
+  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i64 [[RD]], [[RE]]
+  // CHECK-NEXT:  store i64 [[RF]], i64* %res, align 8
+  // CHECK-NEXT:  ret void
+
+  /*shift = 63, mask = 0x00FFF000 = 72057593769492480, ~mask = 0xFF000FFF = -72057593769492481*/
+  unsigned long long res = __builtin_ppc_rldimi(ull, ull, 63, 0x00FFF000);
+}
+
+void test_builtin_ppc_rlwimi() {
+  // CHECK-LABEL: test_builtin_ppc_rlwimi
+  // CHECK:   %res = alloca i32, align 4
+  // CHECK-NEXT:  [[RA:%[0-9]+]] = load i32, i32* @ui, align 4
+  // CHECK-NEXT:  [[RB:%[0-9]+]] = load i32, i32* @ui, align 4
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 [[RA]], i32 31)
+  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i32 [[RC]], 16776960
+  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i32 [[RB]], -16776961
+  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i32 [[RD]], [[RE]]
+  // CHECK-NEXT:  store i32 [[RF]], i32* %res, align 4
+  // CHECK-NEXT:  ret void
+
+  /*shift = 31, mask = 0x00 = 16776960, ~mask = 0xFFFF = -16776961*/
+  unsigned int res = __builtin_ppc_rlwimi(ui, ui, 31, 0x00);
+}
+
+void test_builtin_ppc_rlwnm() {
+  // CHECK-LABEL: test_builtin_ppc_rlwnm
+  // CHECK:   %res = alloca i32, align 4
+  // CHECK-NEXT:  [[RA:%[0-9]+]] = load i32, i32* @ui, align 4
+  // CHECK-NEXT:  [[RB:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 [[RA]], i32 31)
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = and i32 [[RB]], 511
+  // CHECK-NEXT:  store i32 [[RC]], i32* %res, align 4
+  // CHECK-NEXT:  ret void
+
+  /*shift = 31, mask = 0x1FF = 511*/
+  unsigned int res = __builtin_ppc_rlwnm(ui, 31, 0x1FF);
+}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -0,0 +1,37 @@
+// REQUIRES: powerpc-registered-target
+
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -fsyntax-only \
+// RUN:   -Wall -Werror -verify %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
+// RUN:   -Wall -Werror -verify %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -fsyntax-only \
+// RUN:   -Wall -Werror -verify %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -fsyntax-only \
+// RUN:   -Wall -Werror -verify %s
+
+extern unsigned int ui;
+extern unsigned long long ull;
+
+void test_builtin_ppc_rldimi() {
+  unsigned int shift;
+  unsigned long long mask;
+  unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
+  res = __builtin_ppc_rldimi(ull, ull, 63, mask);// expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
+  res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // expected-error {{argument 3 value should represent a contiguous bit field}}
+}
+
+void test_builtin_ppc_rlwimi() {
+  unsigned int shift;
+  unsigned int mask;
+  unsigned int res = __builtin_ppc_rlwimi(ui, ui, shift, 7); // expected-error {{argument to '__builtin_ppc_rlwimi' must be a constant integer}}
+  res = 

[PATCH] D105194: [PowerPC] Add PowerPC cmpb builtin and emit target indepedent code for XL compatibility

2021-07-14 Thread Victor Huang via Phabricator via cfe-commits
NeHuang marked an inline comment as done.
NeHuang added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15081
   }
+  case PPC::BI__builtin_ppc_cmpb: {
+llvm::Type *Ty = Ops[0]->getType();

NeHuang wrote:
> nemanjai wrote:
> > I find it rather surprising that we are emitting this complex sequence for 
> > this builtin. Perhaps there is a good reason for doing so, but at the very 
> > least, this requires a thorough explanation in a comment.
> > 
> > One additional concern I have with this is that if some transformation 
> > proves that some portion of this is unused (perhaps using `DemandedBits` 
> > analysis), it may optimize out a portion of this, thereby making the 
> > sequence emit a whole bunch of xor's, or's, rotates, etc.
> > 
> > For example:
> > ```
> > ...
> > unsigned long long A = __builtin_ppc_cmpb(B, C);
> > return A & 0xFF00FF00FF00FF;
> > ```
> > It is entirely possible that the optimizer will get rid of some of the 
> > produced instructions and then the back end won't be able to emit a single 
> > `cmpb` but will have to emit a whole bunch of scalar instructions.
> - The backend test case define i64 @test64(i64 %x, i64 %y) is in 
> llvm/test/CodeGen/PowerPC/cmpb.ll
> - Also Tried the test case and results look fine.
> ```
> $ cat test_cmpb.c
> long long test_cmpb(long long a, long long b) {
>   //return __cmpb(a, b);
>   unsigned long long A = __builtin_ppc_cmpb(a, b);
>   return A & 0xFF00FF00FF00FF;
> }
> $ clang -cc1 -O3 -triple powerpc-unknown-aix test_cmpb.c -target-cpu pwr9 -S 
> -o test_cmpb_32bit.s
> ...
> .test_cmpb:
> # %bb.0:# %entry
> cmpb 4, 6, 4
> lis 6, 255
> cmpb 3, 5, 3
> ori 6, 6, 255
> and 4, 4, 6
> and 3, 3, 6
> blr
> $ clang -cc1 -O3 -triple powerpc64-unknown-aix test_cmpb.c -target-cpu pwr9 
> -S -o test_cmpb_64bit.s
> .test_cmpb:
> # %bb.0:# %entry
> cmpb 3, 4, 3
> lis 4, 255
> ori 4, 4, 255
> rldimi 4, 4, 32, 0
> and 3, 3, 4
> blr
> ```
The intension of emitting this complex sequence for this builtin is to produce 
the target independent code matching the backend test case IR (in the 
description) and produce asm results matching xlc. Verified the target IR will 
produce expected asm results for 32 bit and 64 bit.
- For 64 bit 
```
cmpb 3, 3, 4
blr
```
- For 32 bit 
```
cmpb 4, 6, 4
cmpb 3, 5, 3
blr
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105194/new/

https://reviews.llvm.org/D105194

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


[PATCH] D105564: Fix for DWARF parsing to better handle auto return type for member functions

2021-07-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:402-403
 case DW_AT_type:
-  type = form_value;
+  if (!type.IsValid())
+type = form_value;
   break;

JDevlieghere wrote:
> What's the purpose of this? Do we expect to see the type attribute more than 
> once? 
Good question, the first iteration was done by @teemperor and then I modified 
it heavily but I did not dig  into this change to deeply but I was pretty sure 
when we first talked about there was a good reason for it.



Comment at: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1337-1339
+TypeSP ret_type = dwarf->FindTypeForAutoReturnForDIE(
+die, ConstString(attrs.mangled_name));
+if (ret_type) {

JDevlieghere wrote:
> LLVM likes to put these variables in the if-clause, which I personally really 
> like because it conveys the scope without hurting readability. 
Good catch, I was changing this code around a lot and forgot to go back and 
clean this up.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2672-2675
+  TypeSP type_sp;
+
+  if (!name)
+return type_sp;

JDevlieghere wrote:
> I know this pattern is common in LLDB, but I really dislike it because you 
> have to backtrack all the way to the beginning of the function to know if 
> `type_sp` has been modified in any way. When I write code like, this I tend 
> to use `return {};` to make it clear I'm returning a default constructed 
> instance of the return type. That also makes it clear where we're actually 
> returning a non-default instance by just looking at the `return`s. 
Good catch, I originally based this on `FindCompleteObjCDefinitionTypeForDIE` 
and stuck with the idiom w/o thinking about it.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h:406
 
+  virtual lldb::TypeSP
+  FindTypeForAutoReturnForDIE(const DWARFDIE ,

shafik wrote:
> teemperor wrote:
> > If this is virtual then I guess `SymbolFileDWARFDwo` should overload it?
> I am actually not sure if this has to be virtual or not, let me dig into this 
> and see if there would be any difference for `SymbolFileDWARFDwo` or not.
Since this is based on the same approach in `GetObjCClassSymbol` and that is 
not `virtual` I am going to drop it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105564/new/

https://reviews.llvm.org/D105564

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

@dyung I appreciate the help tracking this down!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9cfec72ffeec: [clang] Refactor AST printing tests to share 
more infrastructure (authored by nridge).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

Files:
  clang/unittests/AST/ASTPrint.h
  clang/unittests/AST/DeclPrinterTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp

Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -38,11 +38,29 @@
   has(compoundStmt(has(stmt().bind("id");
 }
 
+static void PrintStmt(raw_ostream , const ASTContext *Context,
+  const Stmt *S, PrintingPolicyAdjuster PolicyAdjuster) {
+  assert(S != nullptr && "Expected non-null Stmt");
+  PrintingPolicy Policy = Context->getPrintingPolicy();
+  if (PolicyAdjuster)
+PolicyAdjuster(Policy);
+  S->printPretty(Out, /*Helper*/ nullptr, Policy);
+}
+
+template 
+::testing::AssertionResult
+PrintedStmtMatches(StringRef Code, const std::vector ,
+   const Matcher , StringRef ExpectedPrinted,
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
+  return PrintedNodeMatches(Code, Args, NodeMatch, ExpectedPrinted, "",
+  PrintStmt, PolicyAdjuster);
+}
+
 template 
 ::testing::AssertionResult
 PrintedStmtCXXMatches(StdVer Standard, StringRef Code, const T ,
   StringRef ExpectedPrinted,
-  PolicyAdjusterType PolicyAdjuster = None) {
+  PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   const char *StdOpt;
   switch (Standard) {
   case StdVer::CXX98: StdOpt = "-std=c++98"; break;
@@ -64,7 +82,7 @@
 ::testing::AssertionResult
 PrintedStmtMSMatches(StringRef Code, const T ,
  StringRef ExpectedPrinted,
- PolicyAdjusterType PolicyAdjuster = None) {
+ PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-std=c++98",
 "-target", "i686-pc-win32",
@@ -79,7 +97,7 @@
 ::testing::AssertionResult
 PrintedStmtObjCMatches(StringRef Code, const T ,
StringRef ExpectedPrinted,
-   PolicyAdjusterType PolicyAdjuster = None) {
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-ObjC",
 "-fobjc-runtime=macosx-10.12.0",
@@ -202,10 +220,10 @@
 };
 )";
   // No implicit 'this'.
-  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
-  CPPSource, memberExpr(anything()).bind("id"), "field",
-  PolicyAdjusterType(
-  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; })));
+  ASSERT_TRUE(PrintedStmtCXXMatches(
+  StdVer::CXX11, CPPSource, memberExpr(anything()).bind("id"), "field",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'this'.
   ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
   CPPSource, memberExpr(anything()).bind("id"), "this->field"));
@@ -222,11 +240,10 @@
 @end
   )";
   // No implicit 'self'.
-  ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
- "return ivar;\n",
- PolicyAdjusterType([](PrintingPolicy ) {
-   PP.SuppressImplicitBase = true;
- })));
+  ASSERT_TRUE(PrintedStmtObjCMatches(
+  ObjCSource, returnStmt().bind("id"), "return ivar;\n",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'self'.
   ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
  "return self->ivar;\n"));
@@ -243,5 +260,6 @@
   // body not printed when TerseOutput is on.
   ASSERT_TRUE(PrintedStmtCXXMatches(
   StdVer::CXX11, CPPSource, lambdaExpr(anything()).bind("id"), "[] {}",
-  PolicyAdjusterType([](PrintingPolicy ) { PP.TerseOutput = true; })));
+
+  [](PrintingPolicy ) { PP.TerseOutput = true; }));
 }
Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -15,6 +15,7 @@
 //
 //===--===//
 
+#include "ASTPrint.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/PrettyPrinter.h"
@@ -66,31 +67,11 @@
 const DeclarationMatcher , StringRef ExpectedPrinted,
 StringRef FileName,
 std::function Print) {
-  PrintMatch Printer(std::move(Print));
-  MatchFinder 

[clang] 9cfec72 - [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2021-07-14T19:44:18-04:00
New Revision: 9cfec72ffeec242783b70e792c50bd163dcf9dbb

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

LOG: [clang] Refactor AST printing tests to share more infrastructure

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

Added: 


Modified: 
clang/unittests/AST/ASTPrint.h
clang/unittests/AST/DeclPrinterTest.cpp
clang/unittests/AST/NamedDeclPrinterTest.cpp
clang/unittests/AST/StmtPrinterTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTPrint.h b/clang/unittests/AST/ASTPrint.h
index c3b6b842316d9..58364499bcd9f 100644
--- a/clang/unittests/AST/ASTPrint.h
+++ b/clang/unittests/AST/ASTPrint.h
@@ -19,72 +19,95 @@
 
 namespace clang {
 
-using PolicyAdjusterType =
-Optional>;
-
-static void PrintStmt(raw_ostream , const ASTContext *Context,
-  const Stmt *S, PolicyAdjusterType PolicyAdjuster) {
-  assert(S != nullptr && "Expected non-null Stmt");
-  PrintingPolicy Policy = Context->getPrintingPolicy();
-  if (PolicyAdjuster)
-(*PolicyAdjuster)(Policy);
-  S->printPretty(Out, /*Helper*/ nullptr, Policy);
-}
+using PrintingPolicyAdjuster = llvm::function_ref;
+
+template 
+using NodePrinter =
+std::function;
 
+template 
+using NodeFilter = std::function;
+
+template 
 class PrintMatch : public ast_matchers::MatchFinder::MatchCallback {
+  using PrinterT = NodePrinter;
+  using FilterT = NodeFilter;
+
   SmallString<1024> Printed;
-  unsigned NumFoundStmts;
-  PolicyAdjusterType PolicyAdjuster;
+  unsigned NumFoundNodes;
+  PrinterT Printer;
+  FilterT Filter;
+  PrintingPolicyAdjuster PolicyAdjuster;
 
 public:
-  PrintMatch(PolicyAdjusterType PolicyAdjuster)
-  : NumFoundStmts(0), PolicyAdjuster(PolicyAdjuster) {}
+  PrintMatch(PrinterT Printer, PrintingPolicyAdjuster PolicyAdjuster,
+ FilterT Filter)
+  : NumFoundNodes(0), Printer(std::move(Printer)),
+Filter(std::move(Filter)), PolicyAdjuster(PolicyAdjuster) {}
 
   void run(const ast_matchers::MatchFinder::MatchResult ) override {
-const Stmt *S = Result.Nodes.getNodeAs("id");
-if (!S)
+const NodeType *N = Result.Nodes.getNodeAs("id");
+if (!N || !Filter(N))
   return;
-NumFoundStmts++;
-if (NumFoundStmts > 1)
+NumFoundNodes++;
+if (NumFoundNodes > 1)
   return;
 
 llvm::raw_svector_ostream Out(Printed);
-PrintStmt(Out, Result.Context, S, PolicyAdjuster);
+Printer(Out, Result.Context, N, PolicyAdjuster);
   }
 
   StringRef getPrinted() const { return Printed; }
 
-  unsigned getNumFoundStmts() const { return NumFoundStmts; }
+  unsigned getNumFoundNodes() const { return NumFoundNodes; }
 };
 
-template 
-::testing::AssertionResult
-PrintedStmtMatches(StringRef Code, const std::vector ,
-   const T , StringRef ExpectedPrinted,
-   PolicyAdjusterType PolicyAdjuster = None) {
+template  bool NoNodeFilter(const NodeType *) {
+  return true;
+}
 
-  PrintMatch Printer(PolicyAdjuster);
+template 
+::testing::AssertionResult
+PrintedNodeMatches(StringRef Code, const std::vector ,
+   const Matcher , StringRef ExpectedPrinted,
+   StringRef FileName, NodePrinter Printer,
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr,
+   bool AllowError = false,
+   // Would like to use a lambda for the default value, but 
that
+   // trips gcc 7 up.
+   NodeFilter Filter = ) {
+
+  PrintMatch Callback(Printer, PolicyAdjuster, Filter);
   ast_matchers::MatchFinder Finder;
-  Finder.addMatcher(NodeMatch, );
+  Finder.addMatcher(NodeMatch, );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
 
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+  bool ToolResult;
+  if (FileName.empty()) {
+ToolResult = tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args);
+  } else {
+ToolResult =
+tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args, 
FileName);
+  }
+  if (!ToolResult && !AllowError)
 return testing::AssertionFailure()
<< "Parsing error in \"" << Code.str() << "\"";
 
-  if (Printer.getNumFoundStmts() == 0)
-return testing::AssertionFailure() << "Matcher didn't find any statements";
+  if (Callback.getNumFoundNodes() == 0)
+return testing::AssertionFailure() << "Matcher didn't find any nodes";
 
-  if (Printer.getNumFoundStmts() > 1)
+  if (Callback.getNumFoundNodes() > 1)
 return testing::AssertionFailure()
-   << "Matcher should match only one statement (found "
-   << Printer.getNumFoundStmts() << ")";
+   << "Matcher should match only one node (found "
+   << 

[clang] 4a4229f - [WebAssembly] Codegen for v128.storeX_lane instructions

2021-07-14 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-07-14T16:15:25-07:00
New Revision: 4a4229f70f815a0a83e8e226ec1718af693faf4d

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

LOG: [WebAssembly] Codegen for v128.storeX_lane instructions

Replace the experimental clang builtins and LLVM intrinsics for these
instructions with normal codegen patterns. Resolves PR50435.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/wasm_simd128.h
clang/test/CodeGen/builtins-wasm.c
clang/test/Headers/wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-build-pair.ll
llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index d05f5cd9ba7f..01c80bdf799a 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -195,10 +195,5 @@ 
TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", "si
 TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4iiC*", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLiC*", "n", "simd128")
 
-TARGET_BUILTIN(__builtin_wasm_store8_lane, "vSc*V16ScIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_store16_lane, "vs*V8sIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_store32_lane, "vi*V4iIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_store64_lane, "vLLi*V2LLiIi", "n", "simd128")
-
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d4b2414cde42..2819931664ba 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17776,36 +17776,6 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_load64_zero);
 return Builder.CreateCall(Callee, {Ptr});
   }
-  case WebAssembly::BI__builtin_wasm_store8_lane:
-  case WebAssembly::BI__builtin_wasm_store16_lane:
-  case WebAssembly::BI__builtin_wasm_store32_lane:
-  case WebAssembly::BI__builtin_wasm_store64_lane: {
-Value *Ptr = EmitScalarExpr(E->getArg(0));
-Value *Vec = EmitScalarExpr(E->getArg(1));
-Optional LaneIdxConst =
-E->getArg(2)->getIntegerConstantExpr(getContext());
-assert(LaneIdxConst && "Constant arg isn't actually constant?");
-Value *LaneIdx = llvm::ConstantInt::get(getLLVMContext(), *LaneIdxConst);
-unsigned IntNo;
-switch (BuiltinID) {
-case WebAssembly::BI__builtin_wasm_store8_lane:
-  IntNo = Intrinsic::wasm_store8_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_store16_lane:
-  IntNo = Intrinsic::wasm_store16_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_store32_lane:
-  IntNo = Intrinsic::wasm_store32_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_store64_lane:
-  IntNo = Intrinsic::wasm_store64_lane;
-  break;
-default:
-  llvm_unreachable("unexpected builtin ID");
-}
-Function *Callee = CGM.getIntrinsic(IntNo);
-return Builder.CreateCall(Callee, {Ptr, Vec, LaneIdx});
-  }
   case WebAssembly::BI__builtin_wasm_shuffle_i8x16: {
 Value *Ops[18];
 size_t OpIdx = 0;

diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index d52cbc0d6a12..fdb32bd1d059 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -223,18 +223,48 @@ static __inline__ void __DEFAULT_FN_ATTRS 
wasm_v128_store(void *__mem,
   ((struct __wasm_v128_store_struct *)__mem)->__v = __a;
 }
 
-#define wasm_v128_store8_lane(__ptr, __vec, __i)   
\
-  (__builtin_wasm_store8_lane((signed char *)(__ptr), (__i8x16)(__vec), (__i)))
+static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store8_lane(void *__mem,
+v128_t __vec,
+int __i)
+__REQUIRE_CONSTANT(__i) {
+  struct __wasm_v128_store8_lane_struct {
+int8_t __v;
+  } __attribute__((__packed__, __may_alias__));
+  ((struct __wasm_v128_store8_lane_struct *)__mem)->__v = 
((__i8x16)__vec)[__i];
+}
 
-#define wasm_v128_store16_lane(__ptr, __vec, __i)  
\
-  (__builtin_wasm_store16_lane((short *)(__ptr), (__i16x8)(__vec), (__i)))
+static __inline__ void __DEFAULT_FN_ATTRS 

[PATCH] D106019: [WebAssembly] Codegen for v128.storeX_lane instructions

2021-07-14 Thread Thomas Lively via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4a4229f70f81: [WebAssembly] Codegen for v128.storeX_lane 
instructions (authored by tlively).

Changed prior to commit:
  https://reviews.llvm.org/D106019?vs=358747=358774#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106019/new/

https://reviews.llvm.org/D106019

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-build-pair.ll
  llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
  llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll

Index: llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
+++ llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
@@ -161,6 +161,34 @@
   ret <16 x i8> %v1
 }
 
+; 1 is the default alignment for v128.store8_lane so no attribute is needed.
+define void @store_lane_i8_a1(<16 x i8> %v, i8* %p) {
+; CHECK-LABEL: store_lane_i8_a1:
+; CHECK: .functype store_lane_i8_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <16 x i8> %v, i32 0
+  store i8 %x, i8* %p, align 1
+  ret void
+}
+
+; 2 is greater than the default alignment so it is ignored.
+define void @store_lane_i8_a2(<16 x i8> %v, i8* %p) {
+; CHECK-LABEL: store_lane_i8_a2:
+; CHECK: .functype store_lane_i8_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <16 x i8> %v, i32 0
+  store i8 %x, i8* %p, align 2
+  ret void
+}
+
 ; ==
 ; 8 x i16
 ; ==
@@ -462,6 +490,47 @@
   ret <8 x i16> %v1
 }
 
+define void @store_lane_i16_a1(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a1:
+; CHECK: .functype store_lane_i16_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 1
+  ret void
+}
+
+; 2 is the default alignment for v128.store16_lane so no attribute is needed.
+define void @store_lane_i16_a2(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a2:
+; CHECK: .functype store_lane_i16_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 2
+  ret void
+}
+
+; 4 is greater than the default alignment so it is ignored.
+define void @store_lane_i16_a4(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a4:
+; CHECK: .functype store_lane_i16_a4 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 4
+  ret void
+}
+
 ; ==
 ; 4 x i32
 ; ==
@@ -789,6 +858,60 @@
   ret <4 x i32> %v1
 }
 
+define void @store_lane_i32_a1(<4 x i32> %v, i32* %p) {
+; CHECK-LABEL: store_lane_i32_a1:
+; CHECK: .functype store_lane_i32_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store32_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <4 x i32> %v, i32 0
+  store i32 %x, i32* %p, align 1
+  ret void
+}
+
+define void @store_lane_i32_a2(<4 x i32> %v, i32* %p) {
+; CHECK-LABEL: store_lane_i32_a2:
+; CHECK: .functype store_lane_i32_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store32_lane 0:p2align=1, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <4 x i32> %v, i32 0
+  store i32 %x, i32* %p, align 2
+  ret void
+}
+
+; 4 is the default alignment for v128.store32_lane so no 

[PATCH] D105564: Fix for DWARF parsing to better handle auto return type for member functions

2021-07-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 358773.
shafik marked 8 inline comments as done.
shafik added a comment.

- Removed virtual from `FindTypeForAutoReturnForDIE`
- Added missing nullptr checks
- Modernized the code


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105564/new/

https://reviews.llvm.org/D105564

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/test/API/lang/cpp/auto_return/Makefile
  lldb/test/API/lang/cpp/auto_return/TestCppAutoReturn.py
  lldb/test/API/lang/cpp/auto_return/main.cpp
  lldb/test/API/lang/cpp/auto_return/other.cpp
  lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_symtab.s

Index: lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_symtab.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/x86/auto_return_symtab.s
@@ -0,0 +1,257 @@
+# This tests that lldb when using symbol table we are able to find the definition
+# for an auto return function.
+
+# RUN: llvm-mc -triple x86_64-apple-macosx10.15.0 %s -filetype=obj > %t.o
+# RUN: lldb-test symbols --dump-clang-ast %t.o | FileCheck %s
+
+# CHECK: CXXMethodDecl {{.*}} <>  f 'int ()'
+
+# This was compiled from the following code:
+#
+# struct A {
+# auto f();
+# };
+#
+# auto A::f() {
+# return 0;
+# }
+#
+# Compiled using:
+#
+#  -target x86_64-apple-macosx10.15.0
+#
+# and edited to remove some uneeded sections.
+
+	.section	__TEXT,__text,regular,pure_instructions
+	.globl	__ZN1A1fEv  ## -- Begin function _ZN1A1fEv
+	.p2align	4, 0x90
+__ZN1A1fEv: ## @_ZN1A1fEv
+Lfunc_begin0:
+	.cfi_startproc
+## %bb.0:   ## %entry
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset %rbp, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register %rbp
+	movq	%rdi, -8(%rbp)
+Ltmp0:
+	xorl	%eax, %eax
+	popq	%rbp
+	retq
+Ltmp1:
+Lfunc_end0:
+	.cfi_endproc
+## -- End function
+	.section	__DWARF,__debug_abbrev,regular,debug
+Lsection_abbrev:
+	.byte	1   ## Abbreviation Code
+	.byte	17  ## DW_TAG_compile_unit
+	.byte	1   ## DW_CHILDREN_yes
+	.byte	37  ## DW_AT_producer
+	.byte	14  ## DW_FORM_strp
+	.byte	19  ## DW_AT_language
+	.byte	5   ## DW_FORM_data2
+	.byte	3   ## DW_AT_name
+	.byte	14  ## DW_FORM_strp
+	.ascii	"\202|" ## DW_AT_LLVM_sysroot
+	.byte	14  ## DW_FORM_strp
+	.ascii	"\357\177"  ## DW_AT_APPLE_sdk
+	.byte	14  ## DW_FORM_strp
+	.byte	16  ## DW_AT_stmt_list
+	.byte	23  ## DW_FORM_sec_offset
+	.byte	27  ## DW_AT_comp_dir
+	.byte	14  ## DW_FORM_strp
+	.byte	17  ## DW_AT_low_pc
+	.byte	1   ## DW_FORM_addr
+	.byte	18  ## DW_AT_high_pc
+	.byte	6   ## DW_FORM_data4
+	.byte	0   ## EOM(1)
+	.byte	0   ## EOM(2)
+	.byte	2   ## Abbreviation Code
+	.byte	19  ## DW_TAG_structure_type
+	.byte	1   ## DW_CHILDREN_yes
+	.byte	54  ## DW_AT_calling_convention
+	.byte	11  ## DW_FORM_data1
+	.byte	3   ## DW_AT_name
+	.byte	14  ## DW_FORM_strp
+	.byte	11  ## DW_AT_byte_size
+	.byte	11  ## DW_FORM_data1
+	.byte	58  ## DW_AT_decl_file
+	.byte	11  ## DW_FORM_data1
+	.byte	59  ## DW_AT_decl_line
+	.byte	11  ## DW_FORM_data1
+	.byte	0   ## EOM(1)
+	.byte	0   ## EOM(2)
+	.byte	3   ## Abbreviation Code
+	.byte	46  ## DW_TAG_subprogram
+	.byte	1   ## DW_CHILDREN_yes
+	.byte	110 ## DW_AT_linkage_name
+	.byte	14  ## DW_FORM_strp
+	.byte	3   ## DW_AT_name
+	.byte	14  ## DW_FORM_strp
+	.byte	58  ## DW_AT_decl_file
+	.byte	11  ## DW_FORM_data1
+	.byte	59  ## DW_AT_decl_line

[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Douglas Yung via Phabricator via cfe-commits
dyung accepted this revision.
dyung added a comment.

In D105457#2878352 , @nridge wrote:

> In D105457#2878302 , @dyung wrote:
>
>> Interesting. If you can get me an updated patch, I can give it a try on my 
>> machine with 7.5 to verify if you like.
>
> I posted an updated patch, if you can give that a whirl that would be great!

I can confirm that it builds and tests successfully on a machine with gcc 7.5. 
Assuming you have tested with more recent compilers and that it is fine there, 
LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D104887: [clang] Evaluate strlen of strcpy argument for -Wfortify-source.

2021-07-14 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

thanks for this! mostly just nits from me




Comment at: clang/lib/AST/ExprConstant.cpp:15755
+
+bool Expr::tryEvaluateStrLen(uint64_t , ASTContext ) const {
+  Expr::EvalStatus Status;

Looks like this is the second "try to evaluate the call to this builtin 
function" API endpoint we have here (the other being for 
`__builtin_object_size`). IMO this isn't an issue, but if we need many more of 
these, it might be worth considering exposing a more general 
`Expr::tryEvaluateBuiltinFunctionCall(APValue &, ASTContext &, BuiltinID, 
ArrayRef)` or similar.



Comment at: clang/lib/Sema/SemaChecking.cpp:604
 
+  auto ComputeCheckVariantSize = [&](unsigned Index) -> Optional 
{
+Expr::EvalResult Result;

nit: i'd rename this `ComputeExplicitObjectSizeArgument`



Comment at: clang/lib/Sema/SemaChecking.cpp:621
+
+Expr *ObjArg = TheCall->getArg(Index);
+uint64_t Result;

nit: would `const Expr *` work here? clang prefers to have `const` where 
possible



Comment at: clang/lib/Sema/SemaChecking.cpp:739
 DiagID = diag::warn_fortify_source_size_mismatch;
-SizeIndex = TheCall->getNumArgs() - 1;
-ObjectIndex = 0;
+SourceSize = ComputeCheckVariantSize(TheCall->getNumArgs() - 1);
+DestinationSize = ComputeSizeArgument(0);

i expected `ComputeCheckVariantSize` to imply that the argument was to a `_chk` 
function, but these `case`s don't reference `_chk` functions (nor do we set 
`IsChkVariant = true;`). should this be calling `ComputeSizeArgument` instead?



Comment at: clang/lib/Sema/SemaChecking.cpp:753
 DiagID = diag::warn_fortify_source_overflow;
-SizeIndex = TheCall->getNumArgs() - 1;
-ObjectIndex = 0;
+SourceSize = ComputeCheckVariantSize(TheCall->getNumArgs() - 1);
+DestinationSize = ComputeSizeArgument(0);

same "shouldn't this be `ComputeSizeArgument`?' question



Comment at: clang/lib/Sema/SemaChecking.cpp:762
 DiagID = diag::warn_fortify_source_size_mismatch;
-SizeIndex = 1;
-ObjectIndex = 0;
+SourceSize = ComputeCheckVariantSize(1);
+DestinationSize = ComputeSizeArgument(0);

same question



Comment at: clang/test/Sema/warn-fortify-source.c:64
+  char dst[4];
+  __builtin_strcpy(dst, src); // expected-warning {{'strcpy' will always 
overflow; destination buffer has size 4, but the source string has length 7 
(including null byte)}}
+}

for completeness and consistency, please include a case where this warning 
doesn't fire.

at the same time, it'd be nice to test for an off-by-one (which i believe is 
handled correctly by this patch already); maybe shorten `src` to `"abcd"` and 
have a test on `char dst2[5];` that doesn't fire?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104887/new/

https://reviews.llvm.org/D104887

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


[PATCH] D105890: [NFC] Add paranthesis around logical expression to silence -Wlogical-op-parentheses warning.

2021-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D105890#2873969 , @thakis wrote:

> I think this is incorrect. See D105892  and 
> https://reviews.llvm.org/D104915#2873851 . Don't blindly land changes to 
> suppress warnings – the warnings exist to tell us something :)

Indeed, thanks for pointing this out! On the other hand, it may be worth adding 
this warning with -Werror to the default set or at least enable it when running 
pre-merge checks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105890/new/

https://reviews.llvm.org/D105890

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


[PATCH] D105384: [NVPTX, CUDA] Add .and.popc variant of the b1 MMA instruction.

2021-07-14 Thread Artem Belevich via Phabricator via cfe-commits
tra marked an inline comment as done.
tra added inline comments.



Comment at: clang/test/CodeGen/builtins-nvptx-mma.py:84
+  # It uses __mma_tf32_m16n16k8_ld_c but __mma_m16n16k8_st_c_f32.
+  make_ldst_ops(["m16n16k8"], ["a", "b", "c", "d"], ["tf32", "f32"]))
 

steffenlarsen wrote:
> tra wrote:
> > steffenlarsen wrote:
> > > The following changes would remove the need for the `m16n16k8` cases in 
> > > `is_ldst_variant_supported`.
> > This was done deliberately. I did have that in an earlier variant of the 
> > patch, but eventually settled on the current version.
> > 
> > My thinking is that `make_ldst_ops(m16n16k8)` would create whatever is 
> > necessary for `m16n16k8`, and we'd keep the decision of what to produce in 
> > one place in `is_ldst_variant_supported`. Splitting one make_ldst_ops into 
> > two here makes this decision implicit which would need additional 
> > explanations. Code that needs less explanations  wins. :-)
> > 
> My concern is that it is more confusing this way because they are the only 
> load/store ops generated where the type is then later filtered. It makes 
> sense for MMA because it needs to filter out select combinations, but here 
> the comment above says one thing and `make_ldst_ops` does something else.
> 
> I don't think it makes a huge difference either way, so if you prefer the 
> current version I am okay with keeping it. That said, it might be good to 
> have a comment in the `m16n16k8` case of `is_ldst_variant_supported` making 
> the connection to this.
Fair enough. I've adopted your suggestion. Builtins don't have as much magic as 
intrinsics, so your approach is indeed simpler.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105384/new/

https://reviews.llvm.org/D105384

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


[PATCH] D105660: [PowerPC][AIX] Add warning when alignment is incompatible with XL

2021-07-14 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA marked an inline comment as done.
ZarkoCA added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3255-3256
+def warn_not_xl_compatible
+: Warning<"requested alignment of arguments 16 bytes or greater is not"
+  " compatible with previous versions of the AIX XL compiler">,
+  InGroup>;

aaron.ballman wrote:
> ZarkoCA wrote:
> > aaron.ballman wrote:
> > > Should we be talking about the AIX XL compiler in a Clang diagnostic?
> > I see your point. Sorry if this isn't what is supposed to be done or if it 
> > doesn't a good precedent.
> > 
> > The reasons for adding this warning is that our back end implementation 
> > isn't totally compatible with XL now and, while buggy, users on AIX may 
> > expect clang and xlclang to be compatible since AIX is the reference 
> > compiler.  The xlclang name implies it's clang based and it's possible for 
> > users to expect some sort of binary compatibility.
> > 
> > I see your point. Sorry if this isn't what is supposed to be done or if it 
> > doesn't a good precedent.
> 
> No worries, it's a good discussion to have! We have some MSVC and GCC 
> compatibility warnings, so there's precedent for naming other compilers. Now 
> that you've moved the diagnostic into an AIX compatibility diagnostic group, 
> I am more comfortable with it. Thanks!
Thanks, glad it's better now. 



Comment at: clang/test/Sema/aix-attr-align.c:3
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+
+struct S {

aaron.ballman wrote:
> Can you add two more RUN lines where we expect no warnings? One would be from 
> a non AIX triple and the other would be with `-Wno-aix-compat` specified?
> 
> Btw, in case you don't know about it, you can do `-verify=off` for those RUN 
> lines and add `// off-no-diagnostics` to the top of the file and that should 
> cover it.
Thanks for the suggestion to add more lines, that coverage was missing before 
from the patch. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105660/new/

https://reviews.llvm.org/D105660

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


[PATCH] D105660: [PowerPC][AIX] Add warning when alignment is incompatible with XL

2021-07-14 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 358760.
ZarkoCA added a comment.

- Add more RUN lines to test
- change `if` condition to be one line


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105660/new/

https://reviews.llvm.org/D105660

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/aix-attr-align.c


Index: clang/test/Sema/aix-attr-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-align.c
@@ -0,0 +1,21 @@
+// off-no-diagnostics
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify=off -Wno-aix-compat 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify=off -Wno-aix-compat 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify=off -fsyntax-only 
%s
+
+struct S {
+  int a[8] __attribute__((aligned(8)));  // no-warning
+};
+
+struct T {
+  int a[4] __attribute__((aligned(16))); // expected-warning {{requesting an 
alignment of arguments 16 bytes or greater is not binary compatible with AIX XL 
16.1 and older}}
+};
+
+struct U {
+  int a[2] __attribute__((aligned(32))); // expected-warning {{requesting an 
alignment of arguments 16 bytes or greater is not binary compatible with AIX XL 
16.1 and older}}
+};
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[4] __attribute__((aligned(16))); // no-warning 
+  int c[2] __attribute__((aligned(32))); // no-warning
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3953,6 +3953,12 @@
 return;
 
   uint64_t AlignVal = Alignment.getZExtValue();
+  // 16 byte ByVal alignment not due to a vector member is not honoured by XL
+  // on AIX. Emit a warning here that users are generating binary incompatible
+  // code to be safe.
+  if (AlignVal >= 16 && isa(D) &&
+  Context.getTargetInfo().getTriple().isOSAIX())
+Diag(AttrLoc, diag::warn_not_xl_compatible) << E->getSourceRange();
 
   // C++11 [dcl.align]p2:
   //   -- if the constant expression evaluates to zero, the alignment
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3254,6 +3254,10 @@
 : Warning<"requested alignment must be %0 bytes or smaller; maximum "
   "alignment assumed">,
   InGroup>;
+def warn_not_xl_compatible
+: Warning<"requesting an alignment of arguments 16 bytes or greater is not"
+  " binary compatible with AIX XL 16.1 and older">,
+  InGroup;
 def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<
   "%q0 redeclared without %1 attribute: previous %1 ignored">,
   InGroup;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1083,6 +1083,9 @@
 // A warning group for warnings about code that clang accepts but gcc doesn't.
 def GccCompat : DiagGroup<"gcc-compat">;
 
+// A warning group for warnings about code that may be incompatible on AIX.
+def AIXCompat : DiagGroup<"aix-compat">;
+
 // Warnings for Microsoft extensions.
 def MicrosoftCharize : DiagGroup<"microsoft-charize">;
 def MicrosoftDrectveSection : DiagGroup<"microsoft-drectve-section">;


Index: clang/test/Sema/aix-attr-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-align.c
@@ -0,0 +1,21 @@
+// off-no-diagnostics
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify=off -Wno-aix-compat -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify=off -Wno-aix-compat -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify=off -fsyntax-only %s
+
+struct S {
+  int a[8] __attribute__((aligned(8)));  // no-warning
+};
+
+struct T {
+  int a[4] __attribute__((aligned(16))); // expected-warning {{requesting an alignment of arguments 16 bytes or greater is not binary compatible with AIX XL 16.1 and older}}
+};
+
+struct U {
+  int a[2] __attribute__((aligned(32))); // expected-warning {{requesting an alignment of arguments 16 bytes or greater is not binary compatible with AIX XL 16.1 and older}}
+};
+  int a[8] __attribute__((aligned(8)));  // no-warning
+  int b[4] __attribute__((aligned(16))); // 

[PATCH] D105964: [clang-format] Make AlwaysBreakAfterReturnType work with K C function definitions

2021-07-14 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58494c856a15: [clang-format] Make BreakAfterReturnType work 
with KR C functions (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105964/new/

https://reviews.llvm.org/D105964

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8209,6 +8209,16 @@
"}\n",
Style);
 
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("int f(i);\n" // No break here.
+   "int\n"   // Break here.
+   "f(i)\n"
+   "{\n"
+   "  return i + 1;\n"
+   "}\n",
+   Style);
+
   Style = getGNUStyle();
 
   // Test for comments at the end of function declarations.
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2476,6 +2476,14 @@
   if (Next->MatchingParen->Next &&
   Next->MatchingParen->Next->is(TT_PointerOrReference))
 return true;
+  // Check for K C function definitions, e.g.:
+  //   int f(i)
+  //   {
+  // return i + 1;
+  //   }
+  if (Next->Next && Next->Next->is(tok::identifier) &&
+  !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
+return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
 if (Tok->is(TT_TypeDeclarationParen))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8209,6 +8209,16 @@
"}\n",
Style);
 
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("int f(i);\n" // No break here.
+   "int\n"   // Break here.
+   "f(i)\n"
+   "{\n"
+   "  return i + 1;\n"
+   "}\n",
+   Style);
+
   Style = getGNUStyle();
 
   // Test for comments at the end of function declarations.
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2476,6 +2476,14 @@
   if (Next->MatchingParen->Next &&
   Next->MatchingParen->Next->is(TT_PointerOrReference))
 return true;
+  // Check for K C function definitions, e.g.:
+  //   int f(i)
+  //   {
+  // return i + 1;
+  //   }
+  if (Next->Next && Next->Next->is(tok::identifier) &&
+  !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
+return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
 if (Tok->is(TT_TypeDeclarationParen))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 58494c8 - [clang-format] Make BreakAfterReturnType work with K C functions

2021-07-14 Thread via cfe-commits

Author: owenca
Date: 2021-07-14T14:38:02-07:00
New Revision: 58494c856a15f5b0e886c7baf5d505ac6c05dfe5

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

LOG: [clang-format] Make BreakAfterReturnType work with K C functions

This fixes PR50999.

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 2b83ff4f78503..54e6c7d38e7de 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2476,6 +2476,14 @@ static bool isFunctionDeclarationName(const FormatToken 
,
   if (Next->MatchingParen->Next &&
   Next->MatchingParen->Next->is(TT_PointerOrReference))
 return true;
+  // Check for K C function definitions, e.g.:
+  //   int f(i)
+  //   {
+  // return i + 1;
+  //   }
+  if (Next->Next && Next->Next->is(tok::identifier) &&
+  !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi)))
+return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
 if (Tok->is(TT_TypeDeclarationParen))

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6747fe749a2fa..eed3ea4cdbe37 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8209,6 +8209,16 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"}\n",
Style);
 
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("int f(i);\n" // No break here.
+   "int\n"   // Break here.
+   "f(i)\n"
+   "{\n"
+   "  return i + 1;\n"
+   "}\n",
+   Style);
+
   Style = getGNUStyle();
 
   // Test for comments at the end of function declarations.



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


[PATCH] D106021: [PowerPC] Add PowerPC population count, reversed load and store related builtins and instrinsics for XL compatibility

2021-07-14 Thread Victor Huang via Phabricator via cfe-commits
NeHuang created this revision.
NeHuang added reviewers: nemanjai, stefanp, PowerPC.
NeHuang added a project: LLVM.
Herald added subscribers: shchenz, kbarton, hiraditya.
NeHuang requested review of this revision.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

This patch is in a series of patches to provide builtins for compatibility
with the XL compiler. This patch adds the builtins and instrisics for 
population 
count, reversed load and store related operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106021

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed-64bit-only.c
  clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
  clang/test/CodeGen/builtins-ppc-xlcompat-popcnt.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-popcnt.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-popcnt.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-popcnt.ll
@@ -0,0 +1,51 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-64B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-64B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-32B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-64B
+
+@ui = external global i32, align 4
+@ull = external global i64, align 8
+
+define dso_local signext i32 @test_builtin_ppc_poppar4() {
+; CHECK-32B-LABEL: test_builtin_ppc_poppar4:
+; CHECK-32B: popcntw 3, 3
+; CHECK-32B-NEXT:clrlwi 3, 3, 31
+; CHECK-32B-NEXT:blr
+; CHECK-64B-LABEL: test_builtin_ppc_poppar4:
+; CHECK-64B: popcntw 3, 3
+; CHECK-64B-NEXT:clrlwi 3, 3, 31
+; CHECK-64B-NEXT:blr
+entry:
+  %0 = load i32, i32* @ui, align 4
+  %1 = load i32, i32* @ui, align 4
+  %2 = call i32 @llvm.ctpop.i32(i32 %1)
+  %3 = and i32 %2, 1
+  ret i32 %3
+}
+
+declare i32 @llvm.ctpop.i32(i32)
+
+define dso_local signext i32 @test_builtin_ppc_poppar8() {
+; CHECK-32B-LABEL: test_builtin_ppc_poppar8:
+; CHECK-32B: xor 3, 3, 4
+; CHECK-32B-NEXT:popcntw 3, 3
+; CHECK-32B-NEXT:clrlwi 3, 3, 31
+; CHECK-32B-NEXT:blr
+; CHECK-64B-LABEL: test_builtin_ppc_poppar8:
+; CHECK-64B: popcntd 3, 3
+; CHECK-64B-NEXT:clrldi 3, 3, 63
+; CHECK-64B-NEXT:blr
+entry:
+  %0 = load i64, i64* @ull, align 8
+  %1 = load i64, i64* @ull, align 8
+  %2 = call i64 @llvm.ctpop.i64(i64 %1)
+  %3 = and i64 %2, 1
+  %cast = trunc i64 %3 to i32
+  ret i32 %cast
+}
+
+declare i64 @llvm.ctpop.i64(i64)
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
@@ -0,0 +1,89 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-64B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-64B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-32B
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-64B
+
+@us = external global i16, align 2
+@us_addr = external global i16*, align 8
+@ui = external global i32, align 4
+@ui_addr = external global i32*, align 8
+
+define dso_local void @test_builtin_ppc_store2r() {
+; CHECK-64B-LABEL: test_builtin_ppc_store2r:
+; CHECK-64B: clrlwi 3, 3, 16
+; CHECK-64B-NEXT:sthbrx 3, 0, 4
+; CHECK-64B-NEXT:blr
+
+; CHECK-32B-LABEL: test_builtin_ppc_store2r:
+; CHECK-32B: clrlwi 3, 3, 16
+; CHECK-32B-NEXT:sthbrx 3, 0, 4
+; CHECK-32B-NEXT:blr
+entry:
+  %0 = load i16, i16* @us, align 2
+  %conv = zext i16 %0 to i32
+  %1 = load i16*, i16** @us_addr, align 8
+  %2 = bitcast i16* %1 to i8*
+  call void @llvm.ppc.store2r(i32 %conv, i8* %2)
+  ret void
+}
+
+declare void @llvm.ppc.store2r(i32, i8*)
+
+define dso_local void @test_builtin_ppc_store4r() {
+; CHECK-64B-LABEL: test_builtin_ppc_store4r:
+; CHECK-64B: stwbrx 3, 0, 4
+; 

[PATCH] D105909: [clang][CallGraphSection] Add type id metadata to indirect call and targets

2021-07-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

Also, have you looked into operand bundles 
 instead of metadata?  I don't 
know much about them, but they might help with the 
optimizations-dropping-metadata problem.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105909/new/

https://reviews.llvm.org/D105909

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D105457#2878302 , @dyung wrote:

> Interesting. If you can get me an updated patch, I can give it a try on my 
> machine with 7.5 to verify if you like.

I posted an updated patch, if you can give that a whirl that would be great!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105911: [CallGraphSection] Introduce CGSectionFuncComdatCreator pass

2021-07-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a subscriber: MaskRay.
morehouse added a comment.

Are comdats needed?  Can we get proper dead stripping with just 
`SHF_LINK_ORDER`?

@MaskRay recently updated the documentation for associated metadata 
 to imply that our 
symbol doesn't need to share a comdat with its associated function when the 
function doesn't have a comdat.

Also, @MaskRay: Can adding comdats like this change the final code in the 
fully-linked binary?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105911/new/

https://reviews.llvm.org/D105911

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 358750.
nridge added a comment.

Work around a gcc 7 bug


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

Files:
  clang/unittests/AST/ASTPrint.h
  clang/unittests/AST/DeclPrinterTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp

Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -38,11 +38,29 @@
   has(compoundStmt(has(stmt().bind("id");
 }
 
+static void PrintStmt(raw_ostream , const ASTContext *Context,
+  const Stmt *S, PrintingPolicyAdjuster PolicyAdjuster) {
+  assert(S != nullptr && "Expected non-null Stmt");
+  PrintingPolicy Policy = Context->getPrintingPolicy();
+  if (PolicyAdjuster)
+PolicyAdjuster(Policy);
+  S->printPretty(Out, /*Helper*/ nullptr, Policy);
+}
+
+template 
+::testing::AssertionResult
+PrintedStmtMatches(StringRef Code, const std::vector ,
+   const Matcher , StringRef ExpectedPrinted,
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
+  return PrintedNodeMatches(Code, Args, NodeMatch, ExpectedPrinted, "",
+  PrintStmt, PolicyAdjuster);
+}
+
 template 
 ::testing::AssertionResult
 PrintedStmtCXXMatches(StdVer Standard, StringRef Code, const T ,
   StringRef ExpectedPrinted,
-  PolicyAdjusterType PolicyAdjuster = None) {
+  PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   const char *StdOpt;
   switch (Standard) {
   case StdVer::CXX98: StdOpt = "-std=c++98"; break;
@@ -64,7 +82,7 @@
 ::testing::AssertionResult
 PrintedStmtMSMatches(StringRef Code, const T ,
  StringRef ExpectedPrinted,
- PolicyAdjusterType PolicyAdjuster = None) {
+ PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-std=c++98",
 "-target", "i686-pc-win32",
@@ -79,7 +97,7 @@
 ::testing::AssertionResult
 PrintedStmtObjCMatches(StringRef Code, const T ,
StringRef ExpectedPrinted,
-   PolicyAdjusterType PolicyAdjuster = None) {
+   PrintingPolicyAdjuster PolicyAdjuster = nullptr) {
   std::vector Args = {
 "-ObjC",
 "-fobjc-runtime=macosx-10.12.0",
@@ -202,10 +220,10 @@
 };
 )";
   // No implicit 'this'.
-  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
-  CPPSource, memberExpr(anything()).bind("id"), "field",
-  PolicyAdjusterType(
-  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; })));
+  ASSERT_TRUE(PrintedStmtCXXMatches(
+  StdVer::CXX11, CPPSource, memberExpr(anything()).bind("id"), "field",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'this'.
   ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11,
   CPPSource, memberExpr(anything()).bind("id"), "this->field"));
@@ -222,11 +240,10 @@
 @end
   )";
   // No implicit 'self'.
-  ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
- "return ivar;\n",
- PolicyAdjusterType([](PrintingPolicy ) {
-   PP.SuppressImplicitBase = true;
- })));
+  ASSERT_TRUE(PrintedStmtObjCMatches(
+  ObjCSource, returnStmt().bind("id"), "return ivar;\n",
+
+  [](PrintingPolicy ) { PP.SuppressImplicitBase = true; }));
   // Print implicit 'self'.
   ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
  "return self->ivar;\n"));
@@ -243,5 +260,6 @@
   // body not printed when TerseOutput is on.
   ASSERT_TRUE(PrintedStmtCXXMatches(
   StdVer::CXX11, CPPSource, lambdaExpr(anything()).bind("id"), "[] {}",
-  PolicyAdjusterType([](PrintingPolicy ) { PP.TerseOutput = true; })));
+
+  [](PrintingPolicy ) { PP.TerseOutput = true; }));
 }
Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -15,6 +15,7 @@
 //
 //===--===//
 
+#include "ASTPrint.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/PrettyPrinter.h"
@@ -66,31 +67,11 @@
 const DeclarationMatcher , StringRef ExpectedPrinted,
 StringRef FileName,
 std::function Print) {
-  PrintMatch Printer(std::move(Print));
-  MatchFinder Finder;
-  Finder.addMatcher(NodeMatch, );
-  std::unique_ptr Factory =
-  newFrontendActionFactory();
-
-  if 

[PATCH] D106019: [WebAssembly] Codegen for v128.storeX_lane instructions

2021-07-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100.
tlively requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Replace the experimental clang builtins and LLVM intrinsics for these
instructions with normal codegen patterns. Resolves PR50435.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106019

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-build-pair.ll
  llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
  llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll

Index: llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
+++ llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
@@ -162,6 +162,34 @@
   ret <16 x i8> %v1
 }
 
+; 1 is the default alignment for v128.store8_lane so no attribute is needed.
+define void @store_lane_i8_a1(<16 x i8> %v, i8* %p) {
+; CHECK-LABEL: store_lane_i8_a1:
+; CHECK: .functype store_lane_i8_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <16 x i8> %v, i32 0
+  store i8 %x, i8* %p, align 1
+  ret void
+}
+
+; 2 is greater than the default alignment so it is ignored.
+define void @store_lane_i8_a2(<16 x i8> %v, i8* %p) {
+; CHECK-LABEL: store_lane_i8_a2:
+; CHECK: .functype store_lane_i8_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <16 x i8> %v, i32 0
+  store i8 %x, i8* %p, align 2
+  ret void
+}
+
 ; ==
 ; 8 x i16
 ; ==
@@ -463,6 +491,47 @@
   ret <8 x i16> %v1
 }
 
+define void @store_lane_i16_a1(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a1:
+; CHECK: .functype store_lane_i16_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 1
+  ret void
+}
+
+; 2 is the default alignment for v128.store16_lane so no attribute is needed.
+define void @store_lane_i16_a2(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a2:
+; CHECK: .functype store_lane_i16_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 2
+  ret void
+}
+
+; 4 is greater than the default alignment so it is ignored.
+define void @store_lane_i16_a4(<8 x i16> %v, i16* %p) {
+; CHECK-LABEL: store_lane_i16_a4:
+; CHECK: .functype store_lane_i16_a4 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <8 x i16> %v, i32 0
+  store i16 %x, i16* %p, align 4
+  ret void
+}
+
 ; ==
 ; 4 x i32
 ; ==
@@ -790,6 +859,60 @@
   ret <4 x i32> %v1
 }
 
+define void @store_lane_i32_a1(<4 x i32> %v, i32* %p) {
+; CHECK-LABEL: store_lane_i32_a1:
+; CHECK: .functype store_lane_i32_a1 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store32_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <4 x i32> %v, i32 0
+  store i32 %x, i32* %p, align 1
+  ret void
+}
+
+define void @store_lane_i32_a2(<4 x i32> %v, i32* %p) {
+; CHECK-LABEL: store_lane_i32_a2:
+; CHECK: .functype store_lane_i32_a2 (v128, i32) -> ()
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:v128.store32_lane 0:p2align=1, 0
+; CHECK-NEXT:# fallthrough-return
+  %x = extractelement <4 x i32> %v, i32 0
+  store i32 %x, i32* %p, align 2
+  ret void
+}
+
+; 4 is the default 

[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In D105457#2878292 , @nridge wrote:

> Making the default argument a non-lambda seems to be sufficient to avoid the 
> error:
>
>   template 
>   class function {
>   public:
> template 
> function(F) {}
>   };
>   
>   void DefaultFunc();
>   
>   template 
>   void Foo(M, function = DefaultFunc);
>   
>   void Bar() {
> Foo(42);
> Foo(42.0);
>   }

Interesting. If you can get me an updated patch, I can give it a try on my 
machine with 7.5 to verify if you like.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Making the default argument a non-lambda seems to be sufficient to avoid the 
error:

  template 
  class function {
  public:
template 
function(F) {}
  };
  
  void DefaultFunc();
  
  template 
  void Foo(M, function = DefaultFunc);
  
  void Bar() {
Foo(42);
Foo(42.0);
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks! I reduced it further to:

  template 
  class function {
  public:
template 
function(F) {}
  };
  
  template 
  void Foo(M, function = [](){});
  
  void Bar() {
Foo(42);
Foo(42.0);
  }

with gcc 7, this gives:

  /tmp/cccKjL8O.s: Assembler messages:
  /tmp/cccKjL8O.s:76: Error: symbol `_ZN8functionIFvvEEC2IUlvE_EET_' is already 
defined

I still don't understand this error, but it seems to be related to the lambda 
that appears as a default argument in a function that gets instantiated 
multiple times (and with the default argument value not dependent on the 
function's template parameter), so I think that gives us some idea of where to 
try workarounds.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105946: [PowerPC] Store, load, move from and to registers related builtins

2021-07-14 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 358738.
Conanap marked an inline comment as done.
Conanap added a comment.

Added more sema checking, test case update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105946/new/

https://reviews.llvm.org/D105946

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-LoadReseve-StoreCond.c
  clang/test/CodeGen/builtins-ppc-xlcompat-move-tofrom-regs.c
  clang/test/CodeGen/builtins-ppc-xlcompat-prefetch.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReserve-StoreCond.ll
  llvm/test/CodeGen/builtins-ppc-xlcompat-move-tofrom-regs.ll
  llvm/test/CodeGen/builtins-ppc-xlcompat-prefetch.ll

Index: llvm/test/CodeGen/builtins-ppc-xlcompat-prefetch.ll
===
--- /dev/null
+++ llvm/test/CodeGen/builtins-ppc-xlcompat-prefetch.ll
@@ -0,0 +1,71 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-AIX64
+
+declare void @llvm.ppc.dcbtstt(i8*)
+declare void @llvm.ppc.dcbtt(i8*)
+
+@vpa = external local_unnamed_addr global i8*, align 8
+
+define dso_local void @test_dcbtstt() {
+; CHECK-LABEL: test_dcbtstt:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addis 3, 2, .LC0@toc@ha
+; CHECK-NEXT:ld 3, .LC0@toc@l(3)
+; CHECK-NEXT:ld 3, 0(3)
+; CHECK-NEXT:dcbtstt 0, 3
+; CHECK-NEXT:blr
+;
+; CHECK-AIX-LABEL: test_dcbtstt:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:lwz 3, L..C0(2) # @vpa
+; CHECK-AIX-NEXT:lwz 3, 0(3)
+; CHECK-AIX-NEXT:dcbtstt 0, 3
+; CHECK-AIX-NEXT:blr
+;
+; CHECK-AIX64-LABEL: test_dcbtstt:
+; CHECK-AIX64:   # %bb.0: # %entry
+; CHECK-AIX64-NEXT:ld 3, L..C0(2) # @vpa
+; CHECK-AIX64-NEXT:ld 3, 0(3)
+; CHECK-AIX64-NEXT:dcbtstt 0, 3
+; CHECK-AIX64-NEXT:blr
+entry:
+  %0 = load i8*, i8** @vpa, align 8
+  tail call void @llvm.ppc.dcbtstt(i8* %0)
+  ret void
+}
+
+
+define dso_local void @test_dcbtt() {
+; CHECK-LABEL: test_dcbtt:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addis 3, 2, .LC0@toc@ha
+; CHECK-NEXT:ld 3, .LC0@toc@l(3)
+; CHECK-NEXT:ld 3, 0(3)
+; CHECK-NEXT:dcbtt 0, 3
+; CHECK-NEXT:blr
+;
+; CHECK-AIX-LABEL: test_dcbtt:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:lwz 3, L..C0(2) # @vpa
+; CHECK-AIX-NEXT:lwz 3, 0(3)
+; CHECK-AIX-NEXT:dcbtt 0, 3
+; CHECK-AIX-NEXT:blr
+;
+; CHECK-AIX64-LABEL: test_dcbtt:
+; CHECK-AIX64:   # %bb.0: # %entry
+; CHECK-AIX64-NEXT:ld 3, L..C0(2) # @vpa
+; CHECK-AIX64-NEXT:ld 3, 0(3)
+; CHECK-AIX64-NEXT:dcbtt 0, 3
+; CHECK-AIX64-NEXT:blr
+entry:
+  %0 = load i8*, i8** @vpa, align 8
+  tail call void @llvm.ppc.dcbtt(i8* %0)
+  ret void
+}
Index: llvm/test/CodeGen/builtins-ppc-xlcompat-move-tofrom-regs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/builtins-ppc-xlcompat-move-tofrom-regs.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr8 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s --check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr7 < %s | FileCheck %s
+
+declare i32 @llvm.ppc.mftbu()
+declare i32 @llvm.ppc.mfmsr()
+
+define dso_local zeroext i32 @test_mftbu() {
+; CHECK-LABEL: test_mftbu:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mftbu 3
+; CHECK-NEXT:clrldi 3, 3, 32
+; CHECK-NEXT:blr
+;
+; CHECK-AIX-LABEL: test_mftbu:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mftbu 3
+; CHECK-AIX-NEXT:blr
+entry:
+  %0 = tail call i32 @llvm.ppc.mftbu()
+  ret i32 %0
+}
+
+define dso_local i64 @test_mfmsr() {
+; CHECK-LABEL: test_mfmsr:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mfmsr 3
+; CHECK-NEXT:clrldi 3, 3, 32
+; CHECK-NEXT:blr
+;
+; CHECK-AIX-LABEL: test_mfmsr:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mfmsr 4
+; 

[PATCH] D105909: [clang][CallGraphSection] Add type id metadata to indirect call and targets

2021-07-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2068
+EmittedMDIdGeneralized = true;
+  }
+

This code also seems unnecessary as it puts metadata on function definitions.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2177
+  !CodeGenOpts.SanitizeCfiCanonicalJumpTables ||
+  CodeGenOpts.CallGraphSection)
 CreateFunctionTypeMetadataForIcall(FD, F);

Also seems unnecessary.



Comment at: clang/test/CodeGen/call-graph-section.c:20
+
+// CHECK-DAG: define {{(dso_local)?}} i32 @baz({{.*}} !type 
[[F_TPRIMITIVE:![0-9]+]]
+int baz(char a, float b, double c) {

Do we still expect type metadata on function definitions on the latest diff?



Comment at: clang/test/CodeGen/call-graph-section.c:39
+  fp_qux(0, 0, 0);
+}
+

necipfazil wrote:
> morehouse wrote:
> > Should we also add a test with a C struct parameter?
> I will add one.
I mean an indirect call with a type like this:

```
void foo(struct MyStruct s)
```

Currently all the tests use primitive types.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105909/new/

https://reviews.llvm.org/D105909

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In case it is useful, here is the full preprocessed file.
F17936275: StmtPrinterTest.preproc.cpp.orig.gz 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple cc1 jobs

2021-07-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

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


[PATCH] D105726: [asan][clang] Add flag to outline instrumentation

2021-07-14 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac500fd18f06: [asan][clang] Add flag to outline 
instrumentation (authored by kstoimenov, committed by vitalybuka).

Changed prior to commit:
  https://reviews.llvm.org/D105726?vs=358689=358731#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105726/new/

https://reviews.llvm.org/D105726

Files:
  clang/docs/AddressSanitizer.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/asan-use-callbacks.cpp
  clang/test/Driver/fsanitize.c

Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -247,6 +247,20 @@
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-WARN
+// CHECK-ASAN-OUTLINE-WARN: warning: argument unused during compilation: '-fsanitize-address-outline-instrumentation'
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-OK
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize-address-outline-instrumentation -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-OK
+// CHECK-ASAN-OUTLINE-OK: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-CHECK-ASAN-CALLBACK
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-outline-instrumentation -fno-sanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-CHECK-ASAN-CALLBACK
+// CHECK-NO-CHECK-ASAN-CALLBACK-NOT: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-odr-indicator %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
 // RUN: %clang_cl --target=x86_64-windows -fsanitize=address -fsanitize-address-use-odr-indicator -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
 // CHECK-ASAN-ODR-INDICATOR: -cc1{{.*}}-fsanitize-address-use-odr-indicator
Index: clang/test/CodeGen/asan-use-callbacks.cpp
===
--- /dev/null
+++ clang/test/CodeGen/asan-use-callbacks.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// RUN: | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE
+// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// RUN: -fsanitize-address-outline-instrumentation \
+// RUN: | FileCheck %s --check-prefixes=CHECK-OUTLINE
+
+// CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load4
+// CHECK-OUTLINE: call{{.*}}@__asan_load4
+
+int deref(int *p) {
+  return *p;
+}
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -805,6 +805,11 @@
 options::OPT_fno_sanitize_address_poison_custom_array_cookie,
 AsanPoisonCustomArrayCookie);
 
+AsanOutlineInstrumentation =
+Args.hasFlag(options::OPT_fsanitize_address_outline_instrumentation,
+ options::OPT_fno_sanitize_address_outline_instrumentation,
+ AsanOutlineInstrumentation);
+
 // As a workaround for a bug in gold 2.26 and earlier, dead stripping of
 // globals in ASan is disabled by default on ELF targets.
 // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
@@ -1118,6 +1123,11 @@
 CmdArgs.push_back("-asan-detect-invalid-pointer-sub");
   }
 
+  if (AsanOutlineInstrumentation) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
+  }
+
   // 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) {
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -44,6 +44,7 @@
   bool AsanUseOdrIndicator = false;
   bool AsanInvalidPointerCmp = false;
   

[clang] ac500fd - [asan][clang] Add flag to outline instrumentation

2021-07-14 Thread Vitaly Buka via cfe-commits

Author: Kirill Stoimenov
Date: 2021-07-14T13:36:34-07:00
New Revision: ac500fd18f0615c45d9d127bfb576ffa1e11425a

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

LOG: [asan][clang] Add flag to outline instrumentation

Summary This option can be used to reduce the size of the
binary. The trade-off in this case would be the run-time
performance.

Reviewed By: vitalybuka

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

Added: 
clang/test/CodeGen/asan-use-callbacks.cpp

Modified: 
clang/docs/AddressSanitizer.rst
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/docs/AddressSanitizer.rst b/clang/docs/AddressSanitizer.rst
index 14f3938496c30..15ac6ff5ac850 100644
--- a/clang/docs/AddressSanitizer.rst
+++ b/clang/docs/AddressSanitizer.rst
@@ -276,6 +276,18 @@ library name in the symbolized stack trace of the leak 
report. See
 
`_
 for more details.
 
+Code generation control
+===
+
+Instrumentation code outlining
+--
+
+By default AddressSanitizer inlines the instumentation code to improve the
+run-time performance, which leads to increased binary size. Using the
+(clang flag ``-fsanitize-address-outline-instrumentation` default: ``false``)
+flag forces all code instumentation to be outlined, which reduces the size
+of the binary, but also reduces the run-time performace.
+
 Limitations
 ===
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 57d53415c5807..f7f76ed3f3e20 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1649,6 +1649,14 @@ are listed below.
Enable simple code coverage in addition to certain sanitizers.
See :doc:`SanitizerCoverage` for more details.
 
+**-f[no-]sanitize-address-outline-instrumentation**
+
+   Controls how address sanitizer code is generated. If enabled will always use
+   a function call instead of inlining the code. Turning this option on could
+   reduce the binary size, but might result in a worse run-time performance.
+
+   See :doc: `AddressSanitizer` for more details.
+
 **-f[no-]sanitize-stats**
 
Enable simple statistics gathering for the enabled sanitizers.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15690d448843..79955f4fa4f08 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1558,6 +1558,12 @@ def fno_sanitize_memory_track_origins : Flag<["-"], 
"fno-sanitize-memory-track-o
 Group,
 Flags<[CoreOption, NoXarchOption]>,
 HelpText<"Disable origins tracking in 
MemorySanitizer">;
+def fsanitize_address_outline_instrumentation : Flag<["-"], 
"fsanitize-address-outline-instrumentation">,
+Group,
+HelpText<"Always generate 
function calls for address sanitizer instrumentation">;
+def fno_sanitize_address_outline_instrumentation : Flag<["-"], 
"fno-sanitize-address-outline-instrumentation">,
+   Group,
+   HelpText<"Use default code 
inlining logic for the address sanitizer">;
 def fsanitize_hwaddress_experimental_aliasing
   : Flag<["-"], "fsanitize-hwaddress-experimental-aliasing">,
 Group,

diff  --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 63a195fdf7537..e9e329e7cb53f 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -44,6 +44,7 @@ class SanitizerArgs {
   bool AsanUseOdrIndicator = false;
   bool AsanInvalidPointerCmp = false;
   bool AsanInvalidPointerSub = false;
+  bool AsanOutlineInstrumentation = false;
   llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
   std::string HwasanAbi;
   bool LinkRuntimes = true;

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 68975aafcd370..8770fb1cf9fef 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -805,6 +805,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain ,
 options::OPT_fno_sanitize_address_poison_custom_array_cookie,
 AsanPoisonCustomArrayCookie);
 
+AsanOutlineInstrumentation =
+Args.hasFlag(options::OPT_fsanitize_address_outline_instrumentation,
+   

[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In D105457#2877971 , @dblaikie wrote:

> In D105457#2876511 , @dyung wrote:
>
>> If it helps, I have so far been able to reduce the file to this which still 
>> shows the failure when compiled with gcc 7.5:
>
> Could you provide the preprocessed input file - maybe that run through 
> creduce could be helpful.

I did originally run it through cvise, but wasn't sure if it would be useful 
since it cut out everything except for what was causing one of the two 
failures. But if it helps, here is what it reduced to:

  namespace std {
  template  using __bool_constant = int;
  template  struct is_base_of;
  template  using remove_reference_t = int;
  template  using enable_if_t = int;
  template  struct iterator_traits;
  struct _Any_data;
  enum _Manager_operation {};
  template  class function;
  class _Function_base {
  public:
template  class _Base_manager {
public:
  static bool _M_manager(_Any_data &, const _Any_data &, 
_Manager_operation) {
  }
};
typedef bool (*_Manager_type)(_Any_data &, const _Any_data &,
  _Manager_operation);
_Manager_type _M_manager;
  };
  template  class _Function_handler;
  template 
  class _Function_handler<_Res(_ArgTypes...), _Functor>
  : public _Function_base::_Base_manager<_Functor> {};
  template 
  class function<_Res(_ArgTypes...)> : _Function_base {
template  using _Requires = int;
  public:
template , void>,
  typename = _Requires>
function(_Functor);
  };
  template 
  template 
  function<_Res(_ArgTypes...)>::function(_Functor) {
_M_manager = _Function_handler<_Res(), _Functor>::_M_manager;
  }
  } // namespace std
  template 
  void hasNItems(
  IterTy Begin = [] {},
  std::enable_if_t>>::valuevoid> = [] {},
  std::enable_if_t>>::valuevoid> = [] {});
  class StringRef {
  public:
StringRef(char *);
  };
  namespace clang {
  class Stmt anything();
  template  using NodeFilter = std::function;
  template 
  void PrintedNodeMatches(
  Matcher, NodeFilter = [](const NodeType *) {});
  } // namespace clang
  using namespace clang;
  enum StdVer { CXX98 };
  template  void PrintedStmtMatches(Matcher NodeMatch) {
PrintedNodeMatches(NodeMatch);
  }
  template 
  void PrintedStmtCXXMatches(StdVer, StringRef, T NodeMatch, StringRef) {
PrintedStmtMatches(NodeMatch);
PrintedStmtCXXMatches(CXX98, "", 0, "");
  }
  void StmtPrinter_TestCXXConversionDeclImplicit_TestTestBody() {
PrintedStmtCXXMatches(CXX98, "", anything, "");
  }

Compiled with gcc 7.5 and optimizations yields the following output:

  dyung@frogstar:~/sandbox/StmtPrinterTest$ gcc -O2 -Wno-write-strings 
StmtPrinterTest.preproc.cpp
  /tmp/ccLNKEkE.s: Assembler messages:
  /tmp/ccLNKEkE.s:14: Error: symbol 
`_ZNSt14_Function_base13_Base_managerIN5clangUlPKNS1_4StmtEE2_EE10_M_managerERSt9_Any_dataRKS7_St18_Manager_operation'
 is already defined


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D104536: WIP: [clang][deps] Avoid minimizing PCH input files

2021-07-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 358726.
jansvoboda11 added a comment.

Entirely disable `DepFS` when scanning PCHs.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104536/new/

https://reviews.llvm.org/D104536

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -6,7 +6,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
 // RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_pch.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
@@ -127,9 +127,8 @@
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu.json
-// FIXME: Make this work with '-mode preprocess-minimized-sources'.
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
 //
 // CHECK-TU:  -[[PREFIX:.*]]
@@ -193,7 +192,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu_with_common.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU-WITH-COMMON
 //
 // CHECK-TU-WITH-COMMON:  -[[PREFIX:.*]]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -46,25 +46,73 @@
   DependencyConsumer 
 };
 
-/// A listener that collects the names and paths to imported modules.
-class ImportCollectingListener : public ASTReaderListener {
-  using PrebuiltModuleFilesT =
-  decltype(HeaderSearchOptions::PrebuiltModuleFiles);
-
+/// A listener that collects the imported modules and optionally the input
+/// files.
+class PrebuiltModuleListener : public ASTReaderListener {
 public:
-  ImportCollectingListener(PrebuiltModuleFilesT )
-  : PrebuiltModuleFiles(PrebuiltModuleFiles) {}
+  PrebuiltModuleListener(llvm::StringMap ,
+ llvm::StringSet<> , bool VisitInputFiles)
+  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
+VisitInputFiles(VisitInputFiles) {}
 
   bool needsImportVisitation() const override { return true; }
+  bool needsInputFileVisitation() override { return VisitInputFiles; }
+  bool needsSystemInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
-PrebuiltModuleFiles[std::string(ModuleName)] = std::string(Filename);
+PrebuiltModuleFiles.insert({ModuleName, Filename.str()});
+  }
+
+  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
+  bool isExplicitModule) override {
+InputFiles.insert(Filename);
+return true;
   }
 
 private:
-  PrebuiltModuleFilesT 
+  llvm::StringMap 
+  llvm::StringSet<> 
+  bool VisitInputFiles;
 };
 
+using PrebuiltModuleFilesT = decltype(HeaderSearchOptions::PrebuiltModuleFiles);
+
+/// Visit the given prebuilt module and collect all of the modules it
+/// transitively imports and contributing input files.
+static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
+CompilerInstance ,
+PrebuiltModuleFilesT ,
+llvm::StringSet<> ,
+bool VisitInputFiles) {
+  // Maps the names of modules that weren't yet visited to their PCM path.
+  llvm::StringMap ModuleFilesWorklist;
+  // Contains PCM paths of all visited modules.
+  llvm::StringSet<> VisitedModuleFiles;
+
+  PrebuiltModuleListener Listener(ModuleFilesWorklist, InputFiles,
+  VisitInputFiles);
+
+  auto GatherModuleFileInfo = 

[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple cc1 jobs

2021-07-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 358724.
jansvoboda11 retitled this revision from "[clang][tooling] Accept Clang 
invocations with "-fno-integrated-as"" to "[clang][tooling] Accept Clang 
invocations with multiple cc1 jobs".
jansvoboda11 edited the summary of this revision.
jansvoboda11 added a comment.

Handle cases with multiple input files and architectures, add tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

Files:
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/test/Tooling/clang-check-offload.cpp
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -18,6 +20,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -258,6 +261,84 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+namespace {
+/// Overlays the real filesystem with the given VFS and returns the result.
+llvm::IntrusiveRefCntPtr
+overlayRealFS(llvm::IntrusiveRefCntPtr VFS) {
+  auto RFS = llvm::vfs::getRealFileSystem();
+  auto OverlayFS = llvm::makeIntrusiveRefCnt(RFS);
+  OverlayFS->pushOverlay(VFS);
+  return OverlayFS;
+}
+
+struct CommandLineExtractorTest : public ::testing::Test {
+  llvm::IntrusiveRefCntPtr InMemoryFS;
+  llvm::IntrusiveRefCntPtr Diags;
+  driver::Driver Driver;
+
+public:
+  CommandLineExtractorTest()
+  : InMemoryFS(new llvm::vfs::InMemoryFileSystem),
+Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)),
+Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags,
+   "clang LLVM compiler", overlayRealFS(InMemoryFS)) {}
+
+  void addFile(StringRef Name, StringRef Content) {
+InMemoryFS->addFile(Name, 0, llvm::MemoryBuffer::getMemBuffer(Content));
+  }
+
+  const llvm::opt::ArgStringList *
+  extractCC1Arguments(llvm::ArrayRef Argv) {
+const std::unique_ptr Compilation(
+Driver.BuildCompilation(llvm::makeArrayRef(Argv)));
+
+return getCC1Arguments(Diags.get(), Compilation.get());
+  }
+};
+} // namespace
+
+
+TEST_F(CommandLineExtractorTest, AcceptOffloading) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-x","hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-c","-x",   "hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-fsyntax-only", "-x",   "hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptExternalAssembler) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-fno-integrated-as", "-c", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-arch", "x86_64", "-arch",
+"arm64", "-c","test.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleInputFiles) {
+  addFile("one.c", "void one() {}\n");
+  addFile("two.c", "void two() {}\n");
+  const char *Args[] = {"clang", "-c", "one.c", "two.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
 struct VerifyEndCallback : public SourceFileCallbacks {
   VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {}
   bool handleBeginSource(CompilerInstance ) override {
Index: clang/test/Tooling/clang-check-offload.cpp
===
--- clang/test/Tooling/clang-check-offload.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: not clang-check "%s" -- -c -x hip -nogpulib 2>&1 | FileCheck %s
-
-// CHECK: C++ requires
-invalid;
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ 

[PATCH] D104420: thread_local support for AIX

2021-07-14 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 358717.
jamieschmeiser added a comment.

Remove accidental inclusion


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp

Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -1,19 +1,20 @@
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple powerpc64-unknown-aix-xcoff | FileCheck --check-prefixes=CHECK,AIX,LINUX_AIX %s
 
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
 int f();
 int g();
 
-// LINUX-DAG: @a ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @a ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @a = internal thread_local global i32 0
 thread_local int a = f();
 extern thread_local int b;
@@ -23,7 +24,7 @@
 static thread_local int d = g();
 
 struct U { static thread_local int m; };
-// LINUX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
 thread_local int U::m = f();
 
@@ -89,9 +90,9 @@
 
 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
 
-// LINUX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
-// LINUX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
 // CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
 // CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
@@ -106,16 +107,16 @@
 // Individual variable initialization functions:
 
 // CHECK: define {{.*}} @[[A_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
 
 // CHECK-LABEL: define{{.*}} i32 @_Z1fv()
 int f() {
   // CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
   // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
-  // CHECK: br i1 %[[NEED_INIT]]
+  // CHECK: br i1 %[[NEED_INIT]]{{.*}}
 
-  // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
+  // CHECK: %[[CALL:.*]] = call{{.*}} i32 @_Z1gv()
   // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
   // CHECK: store i8 1, i8* @_ZGVZ1fvE1n
   // CHECK: br label
@@ -126,55 

[PATCH] D104058: ThinLTO: Fix inline assembly references to static functions with CFI

2021-07-14 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

In D104058#2877631 , @nickdesaulniers 
wrote:

> Change LGTM, but I don't understand why the following tests are modified:
>
> - llvm/test/ThinLTO/X86/devirt2.ll

This is needed to fix two `missing symbol resolution` errors that are caused by 
the aliases we added.

> - llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll
> - llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll

And for these, we need to specify a target triple to use module inline 
assembly. According to pcc, there shouldn't be a real-world situation where the 
triple is missing, but these two tests don't currently specify one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104058/new/

https://reviews.llvm.org/D104058

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


[PATCH] D106011: [clang-tidy] performance-unnecessary-copy-initialization: Disable check when variable and initializer have different replaced template param types.

2021-07-14 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: aaron.ballman, ymandel, hokein.
Herald added a subscriber: xazax.hun.
flx requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This can happen when a template with two parameter types is instantiated with a
single type. The fix would only be valid for this instantiation but fail for
others that rely on an implicit type conversion.

The test cases illustrate when the check should trigger and when not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106011

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -17,6 +17,9 @@
   Iterator end() const;
   void nonConstMethod();
   bool constMethod() const;
+  template 
+  const A () const;
+  operator int() const; // Implicit conversion to int.
 };
 
 struct TrivialToCopyType {
@@ -659,3 +662,54 @@
   C.constMethod();
   D.constMethod();
 }
+
+template 
+const A ();
+
+template 
+void negativeTemplateTypes() {
+  A Orig;
+  // Different replaced template type params do not trigger the check. In some
+  // template instantiation this might not be a copy but an implicit
+  // conversion, so converting this to a reference might not work.
+  B AmbiguousCopy = Orig;
+  // CHECK-NOT-FIXES: B AmbiguousCopy = Orig;
+
+  B NecessaryCopy = templatedReference();
+  // CHECK-NOT-FIXES: B NecessaryCopy = templatedReference();
+
+  B NecessaryCopy2 = Orig.template templatedAccessor();
+
+  // Non-dependent types in template still trigger the check.
+  const auto UnnecessaryCopy = ExpensiveTypeReference();
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'UnnecessaryCopy' is copy-constructed
+  // CHECK-FIXES: const auto& UnnecessaryCopy = ExpensiveTypeReference();
+  UnnecessaryCopy.constMethod();
+}
+
+void instantiateNegativeTemplateTypes() {
+  negativeTemplateTypes();
+  // This template instantiation would not compile if the `AmbiguousCopy` above was made a reference.
+  negativeTemplateTypes();
+}
+
+template 
+void positiveSingleTemplateType() {
+  A Orig;
+  A SingleTmplParmTypeCopy = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: local copy 'SingleTmplParmTypeCopy' of the variable 'Orig' is never modified
+  // CHECK-FIXES: const A& SingleTmplParmTypeCopy = Orig;
+  SingleTmplParmTypeCopy.constMethod();
+
+  A UnnecessaryCopy2 = templatedReference();
+  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the variable 'UnnecessaryCopy2' is copy-constructed from a const reference
+  // CHECK-FIXES: const A& UnnecessaryCopy2 = templatedReference();
+  UnnecessaryCopy2.constMethod();
+
+  A UnnecessaryCopy3 = Orig.template templatedAccessor();
+  // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the variable 'UnnecessaryCopy3' is copy-constructed from a const reference
+  // CHECK-FIXES: const A& UnnecessaryCopy3 = Orig.template templatedAccessor();
+  UnnecessaryCopy3.constMethod();
+}
+
+void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -27,6 +27,8 @@
 
 static constexpr StringRef ObjectArgId = "objectArg";
 static constexpr StringRef InitFunctionCallId = "initFunctionCall";
+static constexpr StringRef MethodDeclId = "methodDecl";
+static constexpr StringRef FunctionDeclId = "functionDecl";
 static constexpr StringRef OldVarDeclId = "oldVarDecl";
 
 void recordFixes(const VarDecl , ASTContext ,
@@ -81,7 +83,8 @@
   // returned either points to a global static variable or to a member of the
   // called object.
   return cxxMemberCallExpr(
-  callee(cxxMethodDecl(returns(matchers::isReferenceToConst(,
+  callee(cxxMethodDecl(returns(matchers::isReferenceToConst()))
+ .bind(MethodDeclId)),
   on(declRefExpr(to(varDecl().bind(ObjectArgId);
 }
 
@@ -89,7 +92,8 @@
   // Only allow initialization of a const reference from a free function if it
   // has no arguments. Otherwise it could return an alias to one of its
   // arguments and the arguments need to be checked for const use as well.
-  return callExpr(callee(functionDecl(returns(matchers::isReferenceToConst(,
+  return callExpr(callee(functionDecl(returns(matchers::isReferenceToConst()))
+ 

[PATCH] D105907: [CallGraphSection] Add call graph section options and documentation

2021-07-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a subscriber: MaskRay.
morehouse added a comment.

We should also tests for the new flags in clang/test/Driver/clang_f_opts.c.




Comment at: clang/docs/CallGraphSection.rst:58
+
+A type identifier may be repeated in different entries. The id value 0 is
+reserved for unknown and used for indirect targets with unknown type.

necipfazil wrote:
> morehouse wrote:
> > Why would a type ID be repeated?
> Current implementation [1] creates a call graph section per function comdat 
> group, to which the assembly printer writes the call graph entries related to 
> the function.  This is done to enable dead-stripping of call graph entries.  
> Consequently, the callsites from two functions may share the same type ID but 
> appear as distinct entries as they will be written to distinct sections.  
> Although they are merged to a single section by the linker, the type ID 
> repetition persists since the linker only concatenates.
> 
> Eliminating this to ensure that type IDs are not repeated should only 
> decrease the binary size overhead.
> 
> [1] https://reviews.llvm.org/D105916 , see 
> MCObjectFileInfo::getCallGraphSection()
Indeed, this is a tricky problem.  The current solution is probably OK, but 
maybe we can simplify the callgraph section format in light of this solution.  
e.g.,
```
Format version, Type id, IsFuncEntry, PC
  0, NumericTypeId(foo), 1, FuncEntryPc(foo)
  0, NumericTypeId(foo), 0, CallSitePc(fp_foo())
  0, NumericTypeId(main), 1, FuncEntryPc(main)
```

cc @MaskRay


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105907/new/

https://reviews.llvm.org/D105907

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


[PATCH] D105960: [clang][driver][darwin] Add driver support for Mac Catalyst

2021-07-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM! (Maybe leave a couple of days in case others have comments.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105960/new/

https://reviews.llvm.org/D105960

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


[PATCH] D105457: [clang] Refactor AST printing tests to share more infrastructure

2021-07-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D105457#2876511 , @dyung wrote:

> If it helps, I have so far been able to reduce the file to this which still 
> shows the failure when compiled with gcc 7.5:

Could you provide the preprocessed input file - maybe that run through creduce 
could be helpful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105457/new/

https://reviews.llvm.org/D105457

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


[PATCH] D105257: [clang][darwin] add support for remapping macOS availability to Mac Catalyst availability

2021-07-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM, assuming @aaron.ballman is happy! (a couple of optional nits inline)




Comment at: clang/lib/Basic/DarwinSDKInfo.cpp:28
+  // If no exact entry found, try just the major key version.
+  if (Key.getMinor())
+return map(VersionTuple(Key.getMajor()), MinimumValue, MaximumValue);

arphaman wrote:
> aaron.ballman wrote:
> > Why are you looking for a minor key here?
> To avoid recursing infinitely in the next iteration, when minor is 0.
In the split-out prep patch, I suggested adding a comment to that effect!



Comment at: clang/lib/Sema/Sema.cpp:63
+  StringRef Platform) {
+  if (!CachedDarwinSDKInfo) {
+auto SDKInfo = parseDarwinSDKInfo(

Nit: I think I'd find this function easier to read if it used an early return 
here, duplicating the `CachedDarwinSDKInfo->get()` call. But I'm fine if you 
prefer it this way.



Comment at: clang/lib/Sema/Sema.cpp:67-70
+if (SDKInfo && *SDKInfo)
+  CachedDarwinSDKInfo =
+  std::make_unique(std::move(**SDKInfo));
+else {

Nit: I might refactor this to use an early return (could split out a helper 
function to wrap parseDarwinSDKInfo, or a lambda to wrap setting/returning 
CachedDarwinSDKInfo)...

... but this is fine too -- if you leave it as-is, please add braces to the 
`if` side to match the braces on the `else`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105257/new/

https://reviews.llvm.org/D105257

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


[PATCH] D105951: [clang] P2266 implicit moves STL workaround

2021-07-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 358702.
mizvekov added a comment.

- Small simplification to implementation, don't need to cast to NamespaceDecl.
- Simplification to tests: Use some evil prep hackery to avoid needing multipe 
files.
- Verify result of getReferencedDeclOfCallee is non-null.

No tests added for the last one, as I cannot think how this could actually 
happen in this instance.
That would suggest that maybe we should assert instead, but then it seems that 
if there were
such a case, it's most likely that we would want to return false anyway.
So the assert would be basically fishing for a test case. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105951/new/

https://reviews.llvm.org/D105951

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

Index: clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
===
--- clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
+++ clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
@@ -1,50 +1,129 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions-verify=new %s
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -fms-compatibility -verify=old %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions-verify=old %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only-verify=cxx2b,new %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fms-compatibility -verify=cxx2b,old %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only-verify=cxx20,old %s
 
 // FIXME: This is a test for a temporary workaround where we disable simpler implicit moves
-//when compiling with -fms-compatibility, because the MSVC STL does not compile.
-//A better workaround is under discussion.
-//The test cases here are just a copy from `CXX/class/class.init/class.copy.elision/p3.cpp`,
-//so feel free to delete this file when the workaround is not needed anymore.
-
-struct CopyOnly {
-  CopyOnly(); // new-note {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
-  // new-note@-1 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
-  CopyOnly(CopyOnly &); // new-note {{candidate constructor not viable: expects an lvalue for 1st argument}}
-  // new-note@-1 {{candidate constructor not viable: expects an lvalue for 1st argument}}
-};
-struct MoveOnly {
-  MoveOnly();
-  MoveOnly(MoveOnly &&);
-};
-MoveOnly &();
-
-MoveOnly &(MoveOnly &) {
-  return w; // old-error {{cannot bind to lvalue of type}}
-}
-
-CopyOnly test2(bool b) {
-  static CopyOnly w1;
-  CopyOnly w2;
-  if (b) {
-return w1;
-  } else {
-return w2; // new-error {{no matching constructor for initialization}}
-  }
-}
-
-template  T &(T &) { return x; } // old-error {{cannot bind to lvalue of type}}
-template MoveOnly (MoveOnly &);
-template MoveOnly &(MoveOnly &&); // old-note {{in instantiation of function template specialization}}
-
-MoveOnly &() {
-  MoveOnly & = rref();
-  return x; // old-error {{cannot bind to lvalue of type}}
-}
-
-void test5() try {
-  CopyOnly x;
-  throw x; // new-error {{no matching constructor for initialization}}
-} catch (...) {
-}
+//in the STL when compiling with -fms-compatibility, because of issues with the
+//implementation there.
+//Feel free to delete this file when the workaround is not needed anymore.
+
+#if __INCLUDE_LEVEL__ == 0
+
+#if __cpluscplus > 202002L && __cpp_implicit_move < 202011L
+#error "__cpp_implicit_move not defined correctly"
+#endif
+
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+
+namespace {
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+} // namespace
+
+namespace foo {
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+namespace std {
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+} // namespace std
+} // namespace foo
+
+namespace std {
+
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+
+namespace {
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+} // namespace
+
+namespace foo {
+int &(int &) { return x; } // cxx20-error {{cannot bind to lvalue}}
+int (int &) { return x; }  // cxx2b-error {{cannot bind to a temporary}}
+} // namespace foo
+
+} // namespace std
+

[PATCH] D105943: [clang-format++] Create a new variant of the clang-format tool to allow additional code mutating behaviour such as East/West Const Fixer

2021-07-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D105943#2877886 , 
@HazardyKnusperkeks wrote:

> This could be a way, but I will also state here that I prefer adding it to 
> plain `clang-format`.

I do too, and that is my preference, Perhaps this way we can establish this as 
a way of showing we can reliably mutate the code with confidence. For this and 
a few of the other ideas collectively our clang-format community has had.

If we are able to prove it has value then I would hope and fully expect in the 
future to be able to at least discuss revisiting that decision, but for now I 
feel we have to prove its worth.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105943/new/

https://reviews.llvm.org/D105943

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


[PATCH] D69764: [clang-format] Add East/West Const fixer capability

2021-07-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D69764#2877618 , @atomgalaxy wrote:

> It would probably be better to make the config option names for passes that
> may mutate whitespace be prefixed with MaybeIncorrect than fork the tool.
> Scary options are better than forks.

I don't feel this is necessary.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764

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


[PATCH] D105958: [clang][darwin] add support for version remapping to the Darwin SDK Info class

2021-07-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a subscriber: aaron.ballman.
dexonsmith added a comment.

Thanks for splitting this out! It mostly looks good, just a few things inline.




Comment at: clang/lib/Basic/DarwinSDKInfo.cpp:27-28
+return KV->getSecond();
+  // If no exact entry found, try just the major key version.
+  if (Key.getMinor())
+return map(VersionTuple(Key.getMajor()), MinimumValue, MaximumValue);

Your answer (https://reviews.llvm.org/D105257#inline-1007563) to 
@aaron.ballman's comment in the original patch was informative: this check is 
to avoid infinite recursion. That wasn't obvious to me either though. Might you 
add something to the comment for the benefit of other readers?



Comment at: clang/lib/Basic/DarwinSDKInfo.cpp:116
   if (const auto *Obj = Result->getAsObject()) {
+// FIXME: Switch to use parseDarwinSDKSettingsJSON in the next commit.
 auto VersionString = Obj->getString("Version");

Nit: I'd suggest skipping the "in the next commit" part.

Instead, I'd suggest documenting in the commit message why this wasn't done 
here:
- This patch adds/tests new low-level functionality.
- Future commit will adopt it in `parseDarwinSDKInfo` and actually change the 
driver/frontend/whatever.



Comment at: clang/unittests/Basic/DarwinSDKinfoTest.cpp:35-49
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 15), VersionTuple(), None),
+VersionTuple(13, 1));
+  EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), None),
+VersionTuple(14, 0));
+  EXPECT_EQ(*Mapping->map(VersionTuple(11, 2), VersionTuple(), None),
+VersionTuple(14, 2));
+

Can you add a couple of comments saying what the EXPECTs are testing? (Maybe 
not each one individually, but at least groups by what they're testing (maybe 
exists, fallback to major, infinite loop, big minimum value, etc., but in full 
sentences)).

Should there be a test that passes both minimum and maximum values?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105958/new/

https://reviews.llvm.org/D105958

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


[PATCH] D69764: [clang-format] Add East/West Const fixer capability

2021-07-14 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D69764#2876916 , @MyDeveloperDay 
wrote:

>> So yes, I'm in favour of landing this patch (though not exactly in the 
>> current form, I'd prefer more future-proof options for instance, not only 
>> handling const)
>
> I am in agreement, but I don't want to put more effort into improving the 
> current design of this patch to handle more use-cases and options UNTIL we 
> round out on the go/no go decision.
>
> From my perspective the use of violate is lower priority as its used like 
> less than 0.01% as often as const. but I definitely think that we can add 
> additional options on the lines of ReSharper to give even greater flexibility
>
> F17930223: image.png 

I would basically enumerate the qualifiers we can have and let the user decide 
the desired order.

In D69764#2877614 , @MyDeveloperDay 
wrote:

> If we create a new tool, I recommend you, I and some of the other 
> clang-format regulars also be the CODE_OWNERS so we can innovate without 
> feeling stifled.

On another note, I think you could already now run for that position of 
`clang-format`. :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764

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


[PATCH] D105951: [clang] P2266 implicit moves STL workaround

2021-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaStmt.cpp:3317-3321
+  for (const DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent()) {
+if (const auto *NS = dyn_cast(DC))
+  if (NS->isStdNamespace())
+return true;
+  }

mizvekov wrote:
> aaron.ballman wrote:
> > Can you use `D->isInStdNamespace()` instead?
> It doesn't look like `isInStdNamespace` is equivalent here, even though the 
> name suggests otherwise.
> This is a small helper, all it does is:
> ```
> bool Decl::isInStdNamespace() const {
>   const DeclContext *DC = getDeclContext();
>   return DC && DC->isStdNamespace();
> }
> ```
> It helps you check `isStdNamespace` from a Decl, without having to through a 
> DeclContext yourself.
> 
> Now if we really need this workaround to apply 'recursively' like this, that 
> is a different question which I am not sure.
Good point -- `isInStdNamespace()` only looks if the declaration is in the 
`std` namespace, not whether any declaration context containing the declaration 
is in `std`. I don't have an issue with the current approach, was mostly 
thinking if there were ways to simplify it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105951/new/

https://reviews.llvm.org/D105951

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


[PATCH] D105943: [clang-format++] Create a new variant of the clang-format tool to allow additional code mutating behaviour such as East/West Const Fixer

2021-07-14 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

This could be a way, but I will also state here that I prefer adding it to 
plain `clang-format`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105943/new/

https://reviews.llvm.org/D105943

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


[PATCH] D105491: [clang] Use i64 for the !srcloc metadata on asm IR nodes.

2021-07-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Does this need an upgrade for old bitcode that has serialized 32-bit types? If 
not, can you explain why not?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105491/new/

https://reviews.llvm.org/D105491

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


[libunwind] 850b57c - [runtimes] Bring back TARGET_TRIPLE

2021-07-14 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2021-07-14T15:15:22-04:00
New Revision: 850b57c5fbe7b44d18c9667bb31adfbe307453a6

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

LOG: [runtimes] Bring back TARGET_TRIPLE

This commit reverts 5099e01568 and 77396bbc98, which broke the build
in various ways. I'm reverting until I can investigate, since that
change appears to be way more subtle than it seemed.

Added: 


Modified: 
libcxx/CMakeLists.txt
libcxx/lib/abi/CMakeLists.txt
libcxx/test/CMakeLists.txt
libcxxabi/CMakeLists.txt
libcxxabi/test/CMakeLists.txt
libunwind/CMakeLists.txt
libunwind/test/CMakeLists.txt

Removed: 




diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index ff8bfb4dea6a1..654bed5de88ce 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -251,7 +251,7 @@ option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM 
unwinder." OFF)
 
 # Target options --
 option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS})
-set(LIBCXX_TARGET_TRIPLE "${TARGET_TRIPLE}" CACHE STRING "Use alternate target 
triple.")
+set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.")
 set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
 set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
 
@@ -480,6 +480,10 @@ elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
   set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
 endif()
 
+if(LIBCXX_TARGET_TRIPLE)
+  set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}")
+endif()
+
 # Configure compiler.
 include(config-ix)
 

diff  --git a/libcxx/lib/abi/CMakeLists.txt b/libcxx/lib/abi/CMakeLists.txt
index c406330426d0f..3d19c0bd16f25 100644
--- a/libcxx/lib/abi/CMakeLists.txt
+++ b/libcxx/lib/abi/CMakeLists.txt
@@ -41,7 +41,7 @@ function(cxx_abi_list_identifier result triple abi_library 
abi_version unstable
 endfunction()
 
 cxx_abi_list_identifier(abi_list_identifier
-  "${LIBCXX_TARGET_TRIPLE}"
+  "${TARGET_TRIPLE}"
   "${LIBCXX_CXX_ABI_LIBNAME}"
   "${LIBCXX_ABI_VERSION}"
   "${LIBCXX_ABI_UNSTABLE}"

diff  --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index f7fa9ea06be5c..0252ff42963ff 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -105,8 +105,8 @@ if (NOT LIBCXX_ENABLE_DEBUG_MODE_SUPPORT)
   serialize_lit_param(enable_debug_tests False)
 endif()
 
-if (LIBCXX_TARGET_TRIPLE)
-  serialize_lit_param(target_triple "\"${LIBCXX_TARGET_TRIPLE}\"")
+if (TARGET_TRIPLE)
+  serialize_lit_param(target_triple "\"${TARGET_TRIPLE}\"")
 endif()
 
 if (LLVM_USE_SANITIZER)

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 33cabdad798f6..584bcbd2adde6 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -111,7 +111,7 @@ option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for 
the libc++abi unit te
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
-set(LIBCXXABI_TARGET_TRIPLE "${TARGET_TRIPLE}" CACHE STRING "Target triple for 
cross compiling.")
+set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
@@ -273,6 +273,10 @@ elseif(CMAKE_SYSROOT)
   set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}")
 endif()
 
+if (LIBCXXABI_TARGET_TRIPLE)
+  set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}")
+endif()
+
 # Configure compiler. Must happen after setting the target flags.
 include(config-ix)
 

diff  --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 0003449b390af..788fd5a448bb2 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -86,8 +86,8 @@ if (LLVM_USE_SANITIZER)
   serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
 endif()
 
-if (LIBCXXABI_TARGET_TRIPLE)
-  serialize_lit_param(target_triple "\"${LIBCXXABI_TARGET_TRIPLE}\"")
+if (TARGET_TRIPLE)
+  serialize_lit_param(target_triple "\"${TARGET_TRIPLE}\"")
 endif()
 
 if (LIBCXXABI_BUILD_32_BITS)

diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index c75532b6d3315..9eada6895e009 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -77,7 +77,7 @@ cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
 cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
   "Install the shared libunwind library." ON
   "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
-set(LIBUNWIND_TARGET_TRIPLE 

[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D104601#2848366 , @Meinersbur 
wrote:

> In D104601#2847400 , @aaron.ballman 
> wrote:
>
>> ... would add that it's very common for implementers to ask developers to 
>> run their code through `-E` mode to submit preprocessed output in order to 
>> reproduce a customer issue with the compiler, and I worry that uses of this 
>> flag will have unintended consequences in that scenario.
>
> Why would one add `-fnormalize-whitespace` for this use case?

I don't think they'd *add* it, I worry it's already used by their build system 
for reasons unknown and the developer replicates it when reporting the bug 
because they're not looking at what flags can be removed.

>> The "very long line" example mentioned by @dblaikie is sort of along these 
>> lines (sorry for the bad pun).
>
> I can add forced line breaks (after/before 80 cols? configurable?) if 
> requested.

I don't think that's necessary just yet. If there's an issue in practice, it 
seems like we could address it once we have the real world use in front of us. 
However, It'd help my confidence if you were able to run this functionality 
over a large corpus of code to see if any issues do pop out, if that's 
plausible for you.

That said, I think I've convinced myself that this functionality is reasonable 
(if a bit novel), but I'd like to see it diagnosed when used outside of a 
preprocessor invocation because it really serves no purpose there. I also think 
we should rename it because "normalize whitespace" can be ambiguous depending 
on what context you're reading the words in.




Comment at: clang/docs/ClangCommandLineReference.rst:2484
+-P option to normlize whitespace such that two files with only formatted
+changes are equal.
+

Should this option be ignored when not performing a preprocessing action (and 
documented as such)?



Comment at: clang/include/clang/Driver/Options.td:1789
   PosFlag, 
NegFlag>;
+defm normalize_whitespace : BoolFOption<"normalize-whitespace",
+  PreprocessorOutputOpts<"NormalizeWhitespace">, DefaultFalse,

I think I'd feel most comfortable if this didn't use "normalize" in the name. 
When I hear that, I think it's going to be doing something like converting all 
(perhaps funky Unicode) notions of whitespace into ASCII space characters. But 
this option doesn't actually do that -- it's removing as much whitespace from 
the preprocessed output as possible. Would it be better named as 
`-felide-unnecessary-whitespace` or something along those lines?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104601/new/

https://reviews.llvm.org/D104601

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


[PATCH] D105951: [clang] P2266 implicit moves STL workaround

2021-07-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaStmt.cpp:3314
+return false;
+  const Decl *D = E.getReferencedDeclOfCallee();
+  if (!S.SourceMgr.isInSystemHeader(D->getLocation()))

aaron.ballman wrote:
> This can return `nullptr`, so we should probably return `false` in that case; 
> WDYT?
Yes I missed that, you are absolutely right!



Comment at: clang/lib/Sema/SemaStmt.cpp:3317-3321
+  for (const DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent()) {
+if (const auto *NS = dyn_cast(DC))
+  if (NS->isStdNamespace())
+return true;
+  }

aaron.ballman wrote:
> Can you use `D->isInStdNamespace()` instead?
It doesn't look like `isInStdNamespace` is equivalent here, even though the 
name suggests otherwise.
This is a small helper, all it does is:
```
bool Decl::isInStdNamespace() const {
  const DeclContext *DC = getDeclContext();
  return DC && DC->isStdNamespace();
}
```
It helps you check `isStdNamespace` from a Decl, without having to through a 
DeclContext yourself.

Now if we really need this workaround to apply 'recursively' like this, that is 
a different question which I am not sure.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105951/new/

https://reviews.llvm.org/D105951

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


[PATCH] D105726: Added fsanitize-address-instrument-via-callback, which controls if address sanitizer will always use a callback.

2021-07-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM.
Do you have commit access?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105726/new/

https://reviews.llvm.org/D105726

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


[PATCH] D104420: thread_local support for AIX

2021-07-14 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2971
+isEmittedWithConstantInitializer(VD, true) &&
+!VD->needsDestruction(getContext())) {
+  // Emit a weak global function referring to the initialization function.

hubert.reinterpretcast wrote:
> Unfortunately `needsDestruction` cannot be counted on at this time for some 
> incomplete types, see https://llvm.org/pr51079.
I think it is okay to leave the code as-is as it will then be fixed when that 
problem is fixed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420

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


[PATCH] D104420: thread_local support for AIX

2021-07-14 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 358690.
jamieschmeiser added a comment.

Respond to review comments: update comments and make functions not weak


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp

Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -1,19 +1,20 @@
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple powerpc64-unknown-aix-xcoff | FileCheck --check-prefixes=CHECK,AIX,LINUX_AIX %s
 
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
 int f();
 int g();
 
-// LINUX-DAG: @a ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @a ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @a = internal thread_local global i32 0
 thread_local int a = f();
 extern thread_local int b;
@@ -23,7 +24,7 @@
 static thread_local int d = g();
 
 struct U { static thread_local int m; };
-// LINUX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
 thread_local int U::m = f();
 
@@ -89,9 +90,9 @@
 
 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
 
-// LINUX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
-// LINUX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
 // CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
 // CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
@@ -106,16 +107,16 @@
 // Individual variable initialization functions:
 
 // CHECK: define {{.*}} @[[A_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
 
 // CHECK-LABEL: define{{.*}} i32 @_Z1fv()
 int f() {
   // CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
   // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
-  // CHECK: br i1 %[[NEED_INIT]]
+  // CHECK: br i1 %[[NEED_INIT]]{{.*}}
 
-  // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
+  // CHECK: %[[CALL:.*]] = call{{.*}} i32 @_Z1gv()
   // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
   // CHECK: store i8 1, i8* 

[PATCH] D105726: Added fsanitize-address-instrument-via-callback, which controls if address sanitizer will always use a callback.

2021-07-14 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 358689.
kstoimenov added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105726/new/

https://reviews.llvm.org/D105726

Files:
  clang/docs/AddressSanitizer.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/asan-use-callbacks.cpp
  clang/test/Driver/fsanitize.c

Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -247,6 +247,20 @@
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-WARN
+// CHECK-ASAN-OUTLINE-WARN: warning: argument unused during compilation: '-fsanitize-address-outline-instrumentation'
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-OK
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize-address-outline-instrumentation -fsanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-ASAN-OUTLINE-OK
+// CHECK-ASAN-OUTLINE-OK: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-CHECK-ASAN-CALLBACK
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-outline-instrumentation -fno-sanitize-address-outline-instrumentation %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-CHECK-ASAN-CALLBACK
+// CHECK-NO-CHECK-ASAN-CALLBACK-NOT: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-odr-indicator %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
 // RUN: %clang_cl --target=x86_64-windows -fsanitize=address -fsanitize-address-use-odr-indicator -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
 // CHECK-ASAN-ODR-INDICATOR: -cc1{{.*}}-fsanitize-address-use-odr-indicator
Index: clang/test/CodeGen/asan-use-callbacks.cpp
===
--- /dev/null
+++ clang/test/CodeGen/asan-use-callbacks.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// RUN: | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE
+// RUN: %clang -S -fsanitize=address -emit-llvm -o - -fsanitize=address %s \
+// RUN: -fsanitize-address-outline-instrumentation \
+// RUN: | FileCheck %s --check-prefixes=CHECK-OUTLINE
+
+
+// CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load4
+// CHECK-OUTLINE: call{{.*}}@__asan_load4
+
+int deref(int *p) {
+  return *p;
+}
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -805,6 +805,11 @@
 options::OPT_fno_sanitize_address_poison_custom_array_cookie,
 AsanPoisonCustomArrayCookie);
 
+AsanOutlineInstrumentation =
+Args.hasFlag(options::OPT_fsanitize_address_outline_instrumentation,
+ options::OPT_fno_sanitize_address_outline_instrumentation,
+ AsanOutlineInstrumentation);
+
 // As a workaround for a bug in gold 2.26 and earlier, dead stripping of
 // globals in ASan is disabled by default on ELF targets.
 // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
@@ -1118,6 +1123,11 @@
 CmdArgs.push_back("-asan-detect-invalid-pointer-sub");
   }
 
+  if (AsanOutlineInstrumentation) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
+  }
+
   // 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) {
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -44,6 +44,7 @@
   bool AsanUseOdrIndicator = false;
   bool AsanInvalidPointerCmp = false;
   bool AsanInvalidPointerSub = false;
+  bool AsanOutlineInstrumentation = false;
   llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
   std::string HwasanAbi;
   bool LinkRuntimes = true;
Index: clang/include/clang/Driver/Options.td

[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-07-14 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h:293-296
+SymbolRef Sym = Operand;
+while (isa(Sym))
+  Sym = cast(Sym)->Operand;
+return Sym;

vsavchenko wrote:
> ASDenysPetrov wrote:
> > vsavchenko wrote:
> > > ASDenysPetrov wrote:
> > > > vsavchenko wrote:
> > > > > ASDenysPetrov wrote:
> > > > > > vsavchenko wrote:
> > > > > > > 
> > > > > > Do you think the recursive call is better than the loop? But, I 
> > > > > > guess, I see your point. You option could be safer if we had 
> > > > > > another implementation of the virtual method. Or you think such 
> > > > > > alike cast symbol is possible in the future? Well, for now 
> > > > > > `ignoreCasts` doesn't make sense to any other `Expr` successors.
> > > > > Oh, wait, why is it even virtual?  I don't think that it should be 
> > > > > virtual.
> > > > > Are similar functions in `Expr` virtual?
> > > > > And I think that this implementation should live in `SymExpr` 
> > > > > directly.  Then it would look like:
> > > > > ```
> > > > > if (const SymbolCast *ThisAsCast = dyn_cast(this)) {
> > > > >   return ThisAsCast->ignoreCasts();
> > > > > }
> > > > > return this;
> > > > > ```
> > > > Yes, `SymExpr` is an abstract class. And because of limitations and 
> > > > dependency of inheritance we are not able to know the implementaion of 
> > > > `SymbolCast`. Unfortunately, this is not a CRTP.
> > > Re-read my comment, please.
> > > Oh, wait, why is it even virtual?
> > `ignoreCasts` is a virtual function because I haven't found any other way 
> > to implement it better.
> > > I don't think that it should be virtual.
> > Unfortunately, this is not a CRTP to avoid dynamic linking.
> > > Are similar functions in Expr virtual?
> > `SymExpr` is an abstract class. I'm not sure about similarity but `SymExpr` 
> > has such virtual methods:
> >   - computeComplexity
> >   - getType 
> >   - getOriginRegion
> > > And I think that this implementation should live in SymExpr directly.
> > It's impossible due to `SymExpr` implementation design. `SymExpr` knows 
> > nothing about implementation details of `SymbolCast` to invoke 
> > `ignoreCasts()`.
> > 
> a) `Expr` is also an abstract class
> b) I put the implementation right there in the comment above.  I don't see 
> any reasons not to use it.
> c) I don't buy it about "impossible" and "implementation design" because you 
> can always declare function in one place and define it in the other.
I think I achieved of what you've been concerned.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103096/new/

https://reviews.llvm.org/D103096

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


[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-07-14 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 358685.
ASDenysPetrov added a comment.

Made`ignoreCast` non-virtual .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103096/new/

https://reviews.llvm.org/D103096

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/symbol-integral-cast.cpp

Index: clang/test/Analysis/symbol-integral-cast.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-integral-cast.cpp
@@ -0,0 +1,353 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config eagerly-assume=false -analyzer-config support-symbolic-integer-casts=true -verify %s
+
+template 
+void clang_analyzer_eval(T);
+void clang_analyzer_warnIfReached();
+
+typedef short int16_t;
+typedef int int32_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+void test1(int x) {
+  // Even if two lower bytes of `x` equal to zero, it doesn't mean that
+  // the entire `x` is zero. We are not able to know the exact value of x.
+  // It can be one of  65536 possible values like [0, 65536, 131072, ...]
+  // and so on. To avoid huge range sets we still assume `x` in the range
+  // [INT_MIN, INT_MAX].
+  if (!(short)x) {
+if (!x)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test2(int x) {
+  // If two lower bytes of `x` equal to zero, and we know x to be 65537,
+  // which is not truncated to short as zero. Thus the branch is infisible.
+  short s = x;
+  if (!s) {
+if (x == 65537)
+  clang_analyzer_warnIfReached(); // no-warning
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test3(int x, short s) {
+  s = x;
+  if ((short)x > -10 && s < 10) {
+if (x > 0 && x < 10) {
+  // If the range of the whole variable was constrained then reason again
+  // about truncated bytes to make the ranges more precise.
+  clang_analyzer_eval((short)x <= 0); // expected-warning {{FALSE}}
+}
+  }
+}
+
+void test4(unsigned x) {
+  if ((char)x > 8) {
+// Constraint the range of the lowest byte of `x` to [9, CHAR_MAX].
+// The original range of `x` still remains [0, UINT_MAX].
+clang_analyzer_eval((char)x < 42); // expected-warning {{UNKNOWN}}
+if (x < 42) {
+  // Constraint the original range to [0, 42] and update (re-constraint)
+  // the range of the lowest byte of 'x' to [9, 42].
+  clang_analyzer_eval((char)x < 42); // expected-warning {{TRUE}}
+}
+  }
+}
+
+void test5(unsigned x) {
+  if ((char)x > -10 && (char)x < 10) {
+if ((short)x == 8) {
+  // If the range of higher bytes(short) was constrained then reason again
+  // about smaller truncated ranges(char) to make it more precise.
+  clang_analyzer_eval((char)x == 8);  // expected-warning {{TRUE}}
+  clang_analyzer_eval((short)x == 8); // expected-warning {{TRUE}}
+  // We still assume full version of `x` in the range [INT_MIN, INT_MAX].
+  clang_analyzer_eval(x == 8); // expected-warning {{UNKNOWN}}
+}
+  }
+}
+
+void test6(int x) {
+  // Even if two lower bytes of `x` less than zero, it doesn't mean that `x`
+  // can't be greater than zero. Thence we don't change the native range of
+  // `x` and this branch is feasible.
+  if (x > 0)
+if ((short)x < 0)
+  clang_analyzer_eval(x > 0); // expected-warning {{TRUE}}
+}
+
+void test7(int x) {
+  // The range of two lower bytes of `x` [1, SHORT_MAX] is enough to cover
+  // all possible values of char [CHAR_MIN, CHAR_MAX]. So the lowest byte
+  // can be lower than zero.
+  if ((short)x > 0) {
+if ((char)x < 0)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test8(int x) {
+  // Promotion from `signed int` to `signed long long` also reasoning about the
+  // original range, because we know the fact that even after promotion it
+  // remains in the range [INT_MIN, INT_MAX].
+  if ((long long)x < 0)
+clang_analyzer_eval(x < 0); // expected-warning {{TRUE}}
+}
+
+void test9(signed int x) {
+  // Any cast `signed` to `unsigned` produces an unsigned range, which is
+  // [0, UNSIGNED_MAX] and can not be lower than zero.
+  if ((unsigned long long)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+
+  if ((unsigned int)x < 0)
+

[PATCH] D105946: [PowerPC] Store, load, move from and to registers related builtins

2021-07-14 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

please add sema checking for pwr8 builtins.




Comment at: 
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReserve-StoreCond.ll:80
+declare i32 @llvm.ppc.lharx(i8*)
+define dso_local signext i16 @test_lharx(i16* %a) local_unnamed_addr #0 {
+; CHECK-64-LABEL: test_lharx:

remove all reference to attributes, `local_unnamed_addr #[0..9]` since it's not 
in the IR.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105946/new/

https://reviews.llvm.org/D105946

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-14 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As part of https://bugs.llvm.org/show_bug.cgi?id=46251, this patch adds 
definition of matrix initialisation. I am not very familiar with this part of 
C++
so please let me know if I am wrong here, which I suspect I am.

I have been trying to follow the reference documentation 
https://en.cppreference.com/w/cpp/language/initialization and the commented out 
test in the
bugzilla ticket 
https://github.com/llvm/llvm-project/blob/3323a628ec821b8b75d3b60bf1510931f97d3883/clang/test/CodeGenCXX/matrix-type-builtins.cpp#L78


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106005

Files:
  clang/docs/MatrixTypes.rst


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,22 @@
   }
 
 
+Initialization Syntax
+-
+An empty value of a matrix type M can be initialised using this syntax:
+
+.. code-block:: c++
+
+  constexpr M m = {};
+
+A non-empty value of a matrix type M can be initialised using the nested 
initialisation syntax:
+
+.. code-block: c++
+  constexpr M m = {{a, b, c}, {d, e, f}}
+
+where the number of constituent arrays must equal the number rows in the 
matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +290,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,22 @@
   }
 
 
+Initialization Syntax
+-
+An empty value of a matrix type M can be initialised using this syntax:
+
+.. code-block:: c++
+
+  constexpr M m = {};
+
+A non-empty value of a matrix type M can be initialised using the nested initialisation syntax:
+
+.. code-block: c++
+  constexpr M m = {{a, b, c}, {d, e, f}}
+
+where the number of constituent arrays must equal the number rows in the matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +290,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105052: [clang][darwin] add support for Mac Catalyst availability

2021-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105052/new/

https://reviews.llvm.org/D105052

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


[PATCH] D105360: [PowerPC] Fix popcntb XL Compat Builtin for 32bit

2021-07-14 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCInstr64Bit.td:831
+// 64bit version of popcntb for 64bit sized unsigned long. 
+let isCodeGenOnly = 1 in
+def POPCNTB8 : XForm_11<31, 122, (outs g8rc:$rA), (ins g8rc:$rS),

efriedma wrote:
> nemanjai wrote:
> > efriedma wrote:
> > > I'm sort of confused by the instruction variations here... let me see if 
> > > I'm understanding correctly:
> > > 
> > > 1. popcntb always produces a 64-bit result.
> > > 2. The 32-bit variation of the intrinsic just throws away the high bits.
> > > 3. We can't use the 64-bit instruction in "32-bit" mode because we marked 
> > > the register class illegal in isel, and Feature64BitRegs has been marked 
> > > "beta" for the last 15 years.
> > > 4. Therefore, there are two versions of the instruction: the real 
> > > instruction that produces a 64-bit result, and a fake version of the 
> > > instruction we can use in 32-bit mode.
> > This is correct. We have two GPR register classes that model the same 
> > register file. The `gprc` registers pretend the high bits don't exist. The 
> > two versions of the instructions that have GPR operands are quite common in 
> > PPC.
> > 
> > There have historically been some operating systems on which context 
> > switches spill the full width GPRs even in 32-bit mode. Others spill only 
> > the low 32 bits of the GPRs. The addition of two different register classes 
> > and `Feature64BitRegs` likely had to do with that.
> > There have historically been some operating systems on which context 
> > switches 
> 
> Oh, that makes sense.  You can't really use the high bits of a 64-bit 
> register if they can get randomly zeroed out from under you.
> 
> Are any commonly used operating systems today in the "spill only the low 32 
> bits" category?
Unfortunately, 32-bit AIX is in this category. We are hoping to be able to 
change that so that once we no longer support the old versions, we have more 
freedom with code generation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105360/new/

https://reviews.llvm.org/D105360

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


[PATCH] D105703: [hwasan] Use stack safety analysis.

2021-07-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Other than missing llvm test is LGTM




Comment at: clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c:4
+
+int main(int argc, char **argv) {
+  char buf[10];

fmayer wrote:
> vitalybuka wrote:
> > this patch mostly change code under llvm/ so tests should be also there, as 
> > IR tests
> > 
> > 
> I don't have strong feelings, but clang/test/CodeGen/lifetime-sanitizer.c is 
> a very similar test, so I think we should either move all of these to llvm/ 
> or add the new ones here to clang/. What do you think?
That lifetime tests how clang inserts lifetime markers. So it must be in clang/ 
this is from https://reviews.llvm.org/D20759 which is clang only patch.
Here the only change for clang is forwarded BuilderWrapper.getTargetTriple().
I don't mind if you keep your tests here, but we also need something which 
tests llvm without clang as you change llvm tranformation.
Usually if contributor changes code in llvm/, expectation is that check-llvm 
should discover regression. It's not always possible, but that's the goal and 
easy to do with this patch.



Comment at: llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h:40
+  Triple TargetTriple;
+  bool IsOptNull;
 };

!IsOptNull -> Optimize
or
IsOptNull -> DisableOptimization




Comment at: llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h:32
+  Triple TargetTriple = {});
   PreservedAnalyses run(Module , ModuleAnalysisManager );
   static bool isRequired() { return true; }

fmayer wrote:
> vitalybuka wrote:
> > Why not from M.getTargetTriple() ?
> Mostly for consistency with the legacy pass. Either way is fine for me 
> though, what do you prefer?
I don't know if will cause any issues, but usually most passes get triple from 
the module.
I prefer we stay consistent with the rest of the code if possible.




Comment at: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp:444
+  const StackSafetyGlobalInfo *SSI = nullptr;
+  if (shouldUseStackSafetyAnalysis(TargetTriple, IsOptNull)) {
+SSI = (M);

we usually don't use {} for single line 
also maybe good candidate for ?: operator



Comment at: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp:390
+  void getAnalysisUsage(AnalysisUsage ) const override {
+if (shouldUseStackSafetyAnalysis(TargetTriple)) {
+  AU.addRequired();

fmayer wrote:
> vitalybuka wrote:
> > why we need to check TargetTriple for that?
> Because we only need the stack safety analysis if we instrument the stack, 
> which we do not do on x86_64 (see shouldInstrumentStack).
I see, I forgot about this limitation.
LGTM, but unconditional is fine as well, assuming we are going to have stack 
instrumentation at some point?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105703/new/

https://reviews.llvm.org/D105703

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


[PATCH] D105950: [WebAssembly] Codegen for v128.loadX_lane instructions

2021-07-14 Thread Thomas Lively via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG970e0900104d: [WebAssembly] Codegen for v128.loadX_lane 
instructions (authored by tlively).

Changed prior to commit:
  https://reviews.llvm.org/D105950?vs=358668=358676#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105950/new/

https://reviews.llvm.org/D105950

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
  llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
  llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll

Index: llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
+++ llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll
@@ -133,6 +133,34 @@
   ret <16 x i8> %v2
 }
 
+; 1 is the default alignment for v128.load8_lane so no attribute is needed.
+define <16 x i8> @load_lane_i8_a1(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_a1:
+; CHECK: .functype load_lane_i8_a1 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i8, i8* %p, align 1
+  %v1 = insertelement <16 x i8> %v, i8 %e, i32 0
+  ret <16 x i8> %v1
+}
+
+; 2 is greater than the default alignment so it is ignored.
+define <16 x i8> @load_lane_i8_a2(i8* %p, <16 x i8> %v) {
+; CHECK-LABEL: load_lane_i8_a2:
+; CHECK: .functype load_lane_i8_a2 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load8_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i8, i8* %p, align 2
+  %v1 = insertelement <16 x i8> %v, i8 %e, i32 0
+  ret <16 x i8> %v1
+}
+
 ; ==
 ; 8 x i16
 ; ==
@@ -393,6 +421,47 @@
   ret <8 x i16> %v2
 }
 
+define <8 x i16> @load_lane_i16_a1(i16* %p, <8 x i16> %v) {
+; CHECK-LABEL: load_lane_i16_a1:
+; CHECK: .functype load_lane_i16_a1 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load16_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i16, i16* %p, align 1
+  %v1 = insertelement <8 x i16> %v, i16 %e, i32 0
+  ret <8 x i16> %v1
+}
+
+; 2 is the default alignment for v128.load16_lane so no attribute is needed.
+define <8 x i16> @load_lane_i16_a2(i16* %p, <8 x i16> %v) {
+; CHECK-LABEL: load_lane_i16_a2:
+; CHECK: .functype load_lane_i16_a2 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i16, i16* %p, align 2
+  %v1 = insertelement <8 x i16> %v, i16 %e, i32 0
+  ret <8 x i16> %v1
+}
+
+; 4 is greater than the default alignment so it is ignored.
+define <8 x i16> @load_lane_i16_a4(i16* %p, <8 x i16> %v) {
+; CHECK-LABEL: load_lane_i16_a4:
+; CHECK: .functype load_lane_i16_a4 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load16_lane 0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i16, i16* %p, align 4
+  %v1 = insertelement <8 x i16> %v, i16 %e, i32 0
+  ret <8 x i16> %v1
+}
+
 ; ==
 ; 4 x i32
 ; ==
@@ -666,6 +735,60 @@
   ret <4 x i32> %v2
 }
 
+define <4 x i32> @load_lane_i32_a1(i32* %p, <4 x i32> %v) {
+; CHECK-LABEL: load_lane_i32_a1:
+; CHECK: .functype load_lane_i32_a1 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load32_lane 0:p2align=0, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load i32, i32* %p, align 1
+  %v1 = insertelement <4 x i32> %v, i32 %e, i32 0
+  ret <4 x i32> %v1
+}
+
+define <4 x i32> @load_lane_i32_a2(i32* %p, <4 x i32> %v) {
+; CHECK-LABEL: load_lane_i32_a2:
+; CHECK: .functype load_lane_i32_a2 (i32, v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:v128.load32_lane 0:p2align=1, 0
+; CHECK-NEXT:# fallthrough-return
+  %e = load 

[clang] 970e090 - [WebAssembly] Codegen for v128.loadX_lane instructions

2021-07-14 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-07-14T11:31:53-07:00
New Revision: 970e0900104d6f67a9c15fa9c913cf3eeba5d06a

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

LOG: [WebAssembly] Codegen for v128.loadX_lane instructions

Replace the experimental clang builtin and LLVM intrinsics for these
instructions with normal codegen patterns. Resolves PR50433.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/wasm_simd128.h
clang/test/CodeGen/builtins-wasm.c
clang/test/Headers/wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll
llvm/test/CodeGen/WebAssembly/simd-load-store-alignment.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index 58d10ea1012e1..d05f5cd9ba7f9 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -195,10 +195,6 @@ 
TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", "si
 TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4iiC*", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLiC*", "n", "simd128")
 
-TARGET_BUILTIN(__builtin_wasm_load8_lane, "V16ScScC*V16ScIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_load16_lane, "V8ssC*V8sIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_load32_lane, "V4iiC*V4iIi", "n", "simd128")
-TARGET_BUILTIN(__builtin_wasm_load64_lane, "V2LLiLLiC*V2LLiIi", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_store8_lane, "vSc*V16ScIi", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_store16_lane, "vs*V8sIi", "n", "simd128")
 TARGET_BUILTIN(__builtin_wasm_store32_lane, "vi*V4iIi", "n", "simd128")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index baa1436954183..d4b2414cde425 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17776,10 +17776,6 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_load64_zero);
 return Builder.CreateCall(Callee, {Ptr});
   }
-  case WebAssembly::BI__builtin_wasm_load8_lane:
-  case WebAssembly::BI__builtin_wasm_load16_lane:
-  case WebAssembly::BI__builtin_wasm_load32_lane:
-  case WebAssembly::BI__builtin_wasm_load64_lane:
   case WebAssembly::BI__builtin_wasm_store8_lane:
   case WebAssembly::BI__builtin_wasm_store16_lane:
   case WebAssembly::BI__builtin_wasm_store32_lane:
@@ -17792,18 +17788,6 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Value *LaneIdx = llvm::ConstantInt::get(getLLVMContext(), *LaneIdxConst);
 unsigned IntNo;
 switch (BuiltinID) {
-case WebAssembly::BI__builtin_wasm_load8_lane:
-  IntNo = Intrinsic::wasm_load8_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_load16_lane:
-  IntNo = Intrinsic::wasm_load16_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_load32_lane:
-  IntNo = Intrinsic::wasm_load32_lane;
-  break;
-case WebAssembly::BI__builtin_wasm_load64_lane:
-  IntNo = Intrinsic::wasm_load64_lane;
-  break;
 case WebAssembly::BI__builtin_wasm_store8_lane:
   IntNo = Intrinsic::wasm_store8_lane;
   break;

diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index dc54bb91e135b..d52cbc0d6a12f 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -170,21 +170,49 @@ wasm_v128_load64_zero(const void *__mem) {
   return (v128_t)(__i64x2){__v, 0};
 }
 
-#define wasm_v128_load8_lane(__ptr, __vec, __i)
\
-  ((v128_t)__builtin_wasm_load8_lane((const signed char *)(__ptr), 
\
- (__i8x16)(__vec), (__i)))
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load8_lane(
+const void *__mem, v128_t __vec, int __i) __REQUIRE_CONSTANT(__i) {
+  struct __wasm_v128_load8_lane_struct {
+int8_t __v;
+  } __attribute__((__packed__, __may_alias__));
+  int8_t __v = ((const struct __wasm_v128_load8_lane_struct *)__mem)->__v;
+  __i8x16 __ret = (__i8x16)__vec;
+  __ret[__i] = __v;
+  return (v128_t)__ret;
+}
 
-#define wasm_v128_load16_lane(__ptr, __vec, __i)   
\
-  ((v128_t)__builtin_wasm_load16_lane((const short *)(__ptr),  
\
-  (__i16x8)(__vec), (__i)))

[PATCH] D105660: [PowerPC][AIX] Add warning when alignment is incompatible with XL

2021-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3255-3256
+def warn_not_xl_compatible
+: Warning<"requested alignment of arguments 16 bytes or greater is not"
+  " compatible with previous versions of the AIX XL compiler">,
+  InGroup>;

ZarkoCA wrote:
> aaron.ballman wrote:
> > Should we be talking about the AIX XL compiler in a Clang diagnostic?
> I see your point. Sorry if this isn't what is supposed to be done or if it 
> doesn't a good precedent.
> 
> The reasons for adding this warning is that our back end implementation isn't 
> totally compatible with XL now and, while buggy, users on AIX may expect 
> clang and xlclang to be compatible since AIX is the reference compiler.  The 
> xlclang name implies it's clang based and it's possible for users to expect 
> some sort of binary compatibility.
> 
> I see your point. Sorry if this isn't what is supposed to be done or if it 
> doesn't a good precedent.

No worries, it's a good discussion to have! We have some MSVC and GCC 
compatibility warnings, so there's precedent for naming other compilers. Now 
that you've moved the diagnostic into an AIX compatibility diagnostic group, I 
am more comfortable with it. Thanks!



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3959-3962
+  if (const auto *FD = dyn_cast(D)) {
+if (Context.getTargetInfo().getTriple().isOSAIX() && AlignVal >= 16)
+  Diag(AttrLoc, diag::warn_not_xl_compatible) << E->getSourceRange();
+  }





Comment at: clang/test/Sema/aix-attr-align.c:3
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s
+
+struct S {

Can you add two more RUN lines where we expect no warnings? One would be from a 
non AIX triple and the other would be with `-Wno-aix-compat` specified?

Btw, in case you don't know about it, you can do `-verify=off` for those RUN 
lines and add `// off-no-diagnostics` to the top of the file and that should 
cover it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105660/new/

https://reviews.llvm.org/D105660

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


[libunwind] 5099e01 - [runtimes] Inherit the TARGET_TRIPLE that may be set by LLVM

2021-07-14 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2021-07-14T14:29:29-04:00
New Revision: 5099e0156818665ae5381337f64ca68d659e0556

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

LOG: [runtimes] Inherit the TARGET_TRIPLE that may be set by LLVM

Added: 


Modified: 
libcxx/CMakeLists.txt
libcxxabi/CMakeLists.txt
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 7b2c662f3ac5..ff8bfb4dea6a 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -251,7 +251,7 @@ option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM 
unwinder." OFF)
 
 # Target options --
 option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS})
-set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.")
+set(LIBCXX_TARGET_TRIPLE "${TARGET_TRIPLE}" CACHE STRING "Use alternate target 
triple.")
 set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
 set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
 

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index d29195eae0b4..33cabdad798f 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -111,7 +111,7 @@ option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for 
the libc++abi unit te
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
-set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
+set(LIBCXXABI_TARGET_TRIPLE "${TARGET_TRIPLE}" CACHE STRING "Target triple for 
cross compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")

diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 68fb07c4a28e..c75532b6d331 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -77,7 +77,7 @@ cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY
 cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
   "Install the shared libunwind library." ON
   "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)
-set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
+set(LIBUNWIND_TARGET_TRIPLE "${TARGET_TRIPLE}" CACHE STRING "Target triple for 
cross compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
 set(LIBUNWIND_TEST_LINKER_FLAGS "" CACHE STRING



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


[PATCH] D105930: [PowerPC] Implement XL compact math builtins

2021-07-14 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

Please change `compact` in the title to `compat`.




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:76-79
+BUILTIN(__builtin_ppc_mtfsb0, "vUi", "")
+BUILTIN(__builtin_ppc_mtfsb1, "vUi", "")
+BUILTIN(__builtin_ppc_mtfsf, "vUiUi", "")
+BUILTIN(__builtin_ppc_mtfsfi, "vUiUi", "")

I think at least some of these should be `I` because the parameter must be 
foldable to an integer constant expression (see `Builtins.def`).



Comment at: llvm/include/llvm/IR/IntrinsicsPowerPC.td:1588
+  : GCCBuiltin<"__builtin_ppc_mtfsf">,
+Intrinsic <[], [llvm_i32_ty, llvm_i32_ty],
+   [IntrNoMem, IntrHasSideEffects]>;

For parameters that need to be immediates, please mark them as such with the 
respective intrinsic property.



Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.td:3650
+// XL Compat intrinsics.
+def : Pat<(int_ppc_fmsub f64:$A, f64:$B, f64:$C), (FMSUB $A, $B, $C)>;
+def : Pat<(int_ppc_fmsubs f32:$A, f32:$B, f32:$C), (FMSUBS $A, $B, $C)>;

Please review the order of operands carefully here. I believe the order is 
wrong either for this one or for the VSX version. Double-check all of the 
others as well please.



Comment at: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.ll:2
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s |\
+; RUN:   FileCheck %s --check-prefix=CHECK-PWR8

Please add `-mattr=-vsx` to one of the run lines since you have added patterns 
for non-VSX but do not appear to be testing that code path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105930/new/

https://reviews.llvm.org/D105930

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


[PATCH] D105974: [analyzer] Do not assume that all pointers have the same bitwidth as void*

2021-07-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks all for the updates and comments. I'll address promptly and resubmit. 
Best!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105974/new/

https://reviews.llvm.org/D105974

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


[PATCH] D104420: thread_local support for AIX

2021-07-14 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 358673.
jamieschmeiser added a comment.

Respond to review comments: create stub functions, return 0 from function and 
other fixes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp

Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -1,19 +1,20 @@
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple powerpc64-unknown-aix-xcoff | FileCheck --check-prefixes=CHECK,AIX,LINUX_AIX %s
 
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
-// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX,CHECK-OPT %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
-// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefixes=CHECK,LINUX,LINUX_AIX %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
 int f();
 int g();
 
-// LINUX-DAG: @a ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @a ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @a = internal thread_local global i32 0
 thread_local int a = f();
 extern thread_local int b;
@@ -23,7 +24,7 @@
 static thread_local int d = g();
 
 struct U { static thread_local int m; };
-// LINUX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
+// LINUX_AIX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
 thread_local int U::m = f();
 
@@ -89,9 +90,9 @@
 
 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
 
-// LINUX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
-// LINUX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
+// LINUX_AIX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
 // CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
 // CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
@@ -106,16 +107,16 @@
 // Individual variable initialization functions:
 
 // CHECK: define {{.*}} @[[A_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
 
 // CHECK-LABEL: define{{.*}} i32 @_Z1fv()
 int f() {
   // CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
   // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
-  // CHECK: br i1 %[[NEED_INIT]]
+  // CHECK: br i1 %[[NEED_INIT]]{{.*}}
 
-  // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
+  // CHECK: %[[CALL:.*]] = call{{.*}} i32 @_Z1gv()
   // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
   // 

[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-07-14 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 358669.
ASDenysPetrov added a comment.

Rebased


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103096/new/

https://reviews.llvm.org/D103096

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/symbol-integral-cast.cpp

Index: clang/test/Analysis/symbol-integral-cast.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-integral-cast.cpp
@@ -0,0 +1,353 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config eagerly-assume=false -analyzer-config support-symbolic-integer-casts=true -verify %s
+
+template 
+void clang_analyzer_eval(T);
+void clang_analyzer_warnIfReached();
+
+typedef short int16_t;
+typedef int int32_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+void test1(int x) {
+  // Even if two lower bytes of `x` equal to zero, it doesn't mean that
+  // the entire `x` is zero. We are not able to know the exact value of x.
+  // It can be one of  65536 possible values like [0, 65536, 131072, ...]
+  // and so on. To avoid huge range sets we still assume `x` in the range
+  // [INT_MIN, INT_MAX].
+  if (!(short)x) {
+if (!x)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test2(int x) {
+  // If two lower bytes of `x` equal to zero, and we know x to be 65537,
+  // which is not truncated to short as zero. Thus the branch is infisible.
+  short s = x;
+  if (!s) {
+if (x == 65537)
+  clang_analyzer_warnIfReached(); // no-warning
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test3(int x, short s) {
+  s = x;
+  if ((short)x > -10 && s < 10) {
+if (x > 0 && x < 10) {
+  // If the range of the whole variable was constrained then reason again
+  // about truncated bytes to make the ranges more precise.
+  clang_analyzer_eval((short)x <= 0); // expected-warning {{FALSE}}
+}
+  }
+}
+
+void test4(unsigned x) {
+  if ((char)x > 8) {
+// Constraint the range of the lowest byte of `x` to [9, CHAR_MAX].
+// The original range of `x` still remains [0, UINT_MAX].
+clang_analyzer_eval((char)x < 42); // expected-warning {{UNKNOWN}}
+if (x < 42) {
+  // Constraint the original range to [0, 42] and update (re-constraint)
+  // the range of the lowest byte of 'x' to [9, 42].
+  clang_analyzer_eval((char)x < 42); // expected-warning {{TRUE}}
+}
+  }
+}
+
+void test5(unsigned x) {
+  if ((char)x > -10 && (char)x < 10) {
+if ((short)x == 8) {
+  // If the range of higher bytes(short) was constrained then reason again
+  // about smaller truncated ranges(char) to make it more precise.
+  clang_analyzer_eval((char)x == 8);  // expected-warning {{TRUE}}
+  clang_analyzer_eval((short)x == 8); // expected-warning {{TRUE}}
+  // We still assume full version of `x` in the range [INT_MIN, INT_MAX].
+  clang_analyzer_eval(x == 8); // expected-warning {{UNKNOWN}}
+}
+  }
+}
+
+void test6(int x) {
+  // Even if two lower bytes of `x` less than zero, it doesn't mean that `x`
+  // can't be greater than zero. Thence we don't change the native range of
+  // `x` and this branch is feasible.
+  if (x > 0)
+if ((short)x < 0)
+  clang_analyzer_eval(x > 0); // expected-warning {{TRUE}}
+}
+
+void test7(int x) {
+  // The range of two lower bytes of `x` [1, SHORT_MAX] is enough to cover
+  // all possible values of char [CHAR_MIN, CHAR_MAX]. So the lowest byte
+  // can be lower than zero.
+  if ((short)x > 0) {
+if ((char)x < 0)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test8(int x) {
+  // Promotion from `signed int` to `signed long long` also reasoning about the
+  // original range, because we know the fact that even after promotion it
+  // remains in the range [INT_MIN, INT_MAX].
+  if ((long long)x < 0)
+clang_analyzer_eval(x < 0); // expected-warning {{TRUE}}
+}
+
+void test9(signed int x) {
+  // Any cast `signed` to `unsigned` produces an unsigned range, which is
+  // [0, UNSIGNED_MAX] and can not be lower than zero.
+  if ((unsigned long long)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+
+  if ((unsigned int)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // 

[PATCH] D105951: [clang] P2266 implicit moves STL workaround

2021-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! We're testing the patch out internally to see if 
it solves issues for us with some of the failures we're seeing.




Comment at: clang/lib/Sema/SemaStmt.cpp:3314
+return false;
+  const Decl *D = E.getReferencedDeclOfCallee();
+  if (!S.SourceMgr.isInSystemHeader(D->getLocation()))

This can return `nullptr`, so we should probably return `false` in that case; 
WDYT?



Comment at: clang/lib/Sema/SemaStmt.cpp:3317-3321
+  for (const DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent()) {
+if (const auto *NS = dyn_cast(DC))
+  if (NS->isStdNamespace())
+return true;
+  }

Can you use `D->isInStdNamespace()` instead?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105951/new/

https://reviews.llvm.org/D105951

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


[PATCH] D105950: [WebAssembly] Codegen for v128.loadX_lane instructions

2021-07-14 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td:324
+  PatFrag<(ops node:$ptr, node:$vec, node:$idx),
+  (vector_insert $vec, (i32 (extloadi8 $ptr)), $idx)>;
+def load16_lane :

aheejin wrote:
> Why are i8 and i16 are extended-loaded?
For i8x16 and i16x8 vectors, loading a lane  from memory means loading just the 
i8 or i16. But after selection DAG legalization, the result of those loads are 
legalized to be i32, making these extending loads. If this were a DAG combine 
rather than an ISel pattern, I would use the pre-legalization i8 and i16 with 
non-extending loads.



Comment at: llvm/test/CodeGen/WebAssembly/simd-build-vector.ll:214
 ; CHECK:   v128.const  $push[[L0:[0-9]+]]=, 0, 0, 0, 0, 42, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 42, 0
-; CHECK:   i8x16.replace_lane
+; CHECK:   v128.load8_lane
 ; CHECK:   i8x16.replace_lane

aheejin wrote:
> Why the change?
The lane for the swizzle comes from a load from the stack, so that now gets 
selected to v128.load8_lane rather than a load followed by a replace_lane.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105950/new/

https://reviews.llvm.org/D105950

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


  1   2   3   >