[PATCH] D70537: [clang] CGDebugInfo asserts `!DT.isNull()` when compiling with debug symbols

2019-12-13 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui updated this revision to Diff 233919.
kamleshbhalui added a comment.

added validation check in testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70537

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/pr42710.cpp


Index: clang/test/CodeGenCXX/pr42710.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr42710.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -debug-info-kind=limited %s -o - | 
FileCheck %s --check-prefix=CHECK
+
+namespace INT {
+struct TypeId
+{
+   inline static int counter{};
+
+   template
+   inline static const int identifier = counter++;
+
+   template
+   inline static const int value = identifier;
+
+};
+
+int main()
+{
+return TypeId::value;
+}
+}
+
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "identifier", 
linkageName: "_ZN3INT6TypeId10identifierIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "identifier", 
linkageName: "_ZN4AUTO6TypeId10identifierIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "counter", 
linkageName: "_ZN3INT6TypeId7counterE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "value", 
linkageName: "_ZN3INT6TypeId5valueIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "counter", 
linkageName: "_ZN4AUTO6TypeId7counterE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "value", 
linkageName: "_ZN4AUTO6TypeId5valueIJiEEE"
+
+namespace AUTO {
+struct TypeId
+{
+inline static int counter{};
+
+template
+inline static const auto identifier = counter++;
+
+template
+inline static const auto value = identifier;
+};
+
+int main()
+{
+return TypeId::value;
+}
+}
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1428,6 +1428,10 @@
 if (isa(V))
   continue;
 
+if (isa(V)
+&& V->getType()->isUndeducedType())
+  continue;
+
 // Reuse the existing static member declaration if one exists
 auto MI = StaticDataMemberCache.find(V->getCanonicalDecl());
 if (MI != StaticDataMemberCache.end()) {


Index: clang/test/CodeGenCXX/pr42710.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr42710.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=CHECK
+
+namespace INT {
+struct TypeId
+{
+   inline static int counter{};
+
+   template
+   inline static const int identifier = counter++;
+
+   template
+   inline static const int value = identifier;
+
+};
+
+int main()
+{
+return TypeId::value;
+}
+}
+
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "identifier", linkageName: "_ZN3INT6TypeId10identifierIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "identifier", linkageName: "_ZN4AUTO6TypeId10identifierIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "counter", linkageName: "_ZN3INT6TypeId7counterE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "value", linkageName: "_ZN3INT6TypeId5valueIJiEEE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "counter", linkageName: "_ZN4AUTO6TypeId7counterE"
+// CHECK: ![[L:[0-9]+]] = distinct !DIGlobalVariable(name: "value", linkageName: "_ZN4AUTO6TypeId5valueIJiEEE"
+
+namespace AUTO {
+struct TypeId
+{
+inline static int counter{};
+
+template
+inline static const auto identifier = counter++;
+
+template
+inline static const auto value = identifier;
+};
+
+int main()
+{
+return TypeId::value;
+}
+}
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1428,6 +1428,10 @@
 if (isa(V))
   continue;
 
+if (isa(V)
+&& V->getType()->isUndeducedType())
+  continue;
+
 // Reuse the existing static member declaration if one exists
 auto MI = StaticDataMemberCache.find(V->getCanonicalDecl());
 if (MI != StaticDataMemberCache.end()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69893: libunwind: Evaluating DWARF operation DW_OP_pick is broken

2019-12-13 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui added a comment.

ping?
can someone commit this for me?


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D69893



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


[PATCH] D71491: [ubsan] Check implicit casts in ObjC for-in statements

2019-12-13 Thread Dan Liew via Phabricator via cfe-commits
delcypher added inline comments.



Comment at: clang/lib/Driver/ToolChain.cpp:953
+  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
+  SanitizerKind::LocalBounds | SanitizerKind::ObjCCast;
   if (getTriple().getArch() == llvm::Triple::x86 ||

`SanitizerKind::ObjCCast` doesn't seem to fit the comment above. It is platform 
dependent (only really works for Apple platforms) and it **does** require 
runtime support (i.e. the Objective-C runtime).


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

https://reviews.llvm.org/D71491



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


[clang] d14a569 - MSVC build fix: forget some unneeded and incorrect friends.

2019-12-13 Thread John McCall via cfe-commits

Author: John McCall
Date: 2019-12-14T01:02:09-05:00
New Revision: d14a5693c07f0fb1b82c75ed72f77a495751dcf7

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

LOG: MSVC build fix: forget some unneeded and incorrect friends.

On MSVC, friend declarations are (incorrectly) visible even if
not otherwise declared, which causes them to interfere with
lookup.  ASTTypeWriter is actually in an anonymous namespace
and cannot be ASTWriter's friend.  The others simply don't need
to be anymore.

Added: 


Modified: 
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 37c6467b97e2..3f321f03d966 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -365,7 +365,6 @@ class ASTReader
   friend class ASTDeclReader;
   friend class ASTIdentifierIterator;
   friend class ASTRecordReader;
-  friend class ASTStmtReader;
   friend class ASTUnit; // ASTUnit needs to remap source locations.
   friend class ASTWriter;
   friend class PCHValidator;

diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index d465939f1c2f..3f0e1e48af93 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -106,8 +106,6 @@ class ASTWriter : public ASTDeserializationListener,
 public:
   friend class ASTDeclWriter;
   friend class ASTRecordWriter;
-  friend class ASTStmtWriter;
-  friend class ASTTypeWriter;
 
   using RecordData = SmallVector;
   using RecordDataImpl = SmallVectorImpl;



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


[PATCH] D69732: [WIP][LTO] Apply SamplePGO pipeline tunes for ThinLTO pre-link to full LTO

2019-12-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D69732#1784511 , @wristow wrote:

> >> Given the performance improvements here, I'd like to develop this patch 
> >> further.
> > 
> > In D69732#1784290 , @ormris wrote:
> >  //Ping// @tejohnson
>
> @ormris, I think that since @tejohnson originally suggested that someone with 
> more interest in full LTO performance pick this up (and she specifically 
> suggested you or me), then you can feel free to take this over.


Yep, sorry, I didn't realize you were waiting for me to confirm! That sounds 
great.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69732



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


[PATCH] D71508: [DebugInfo] Duplicate file names in debug info

2019-12-13 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui created this revision.
kamleshbhalui added reviewers: probinson, dblaikie, vsk, labath.
kamleshbhalui added a project: debug-info.
Herald added subscribers: cfe-commits, aprantl.
Herald added a project: clang.

strip/remove the dot slash before creating files for debug info.
This fixes https://bugs.llvm.org/show_bug.cgi?id=44170

I am unable to add a test for this.
since it requires to pass command like this.
$clang ./t.c -g -emit-llvm -S


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71508

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -409,6 +409,10 @@
 // If the location is not valid then use main input file.
 return TheCU->getFile();
 
+  if (!llvm::sys::path::is_absolute(FileName)) {
+  FileName = llvm::sys::path::remove_leading_dotslash(FileName);
+}
+
   // Cache the results.
   auto It = DIFileCache.find(FileName.data());
   if (It != DIFileCache.end()) {


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -409,6 +409,10 @@
 // If the location is not valid then use main input file.
 return TheCU->getFile();
 
+  if (!llvm::sys::path::is_absolute(FileName)) {
+  FileName = llvm::sys::path::remove_leading_dotslash(FileName);
+}
+
   // Cache the results.
   auto It = DIFileCache.find(FileName.data());
   if (It != DIFileCache.end()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71491: [ubsan] Check implicit casts in ObjC for-in statements

2019-12-13 Thread Dan Liew via Phabricator via cfe-commits
delcypher added inline comments.



Comment at: compiler-rt/lib/ubsan/ubsan_value.cpp:29
+const char *__ubsan::getObjCClassName(ValueHandle Pointer) {
+#if defined(__APPLE__)
+  // We need to query the ObjC runtime for some information, but do not want

The compiler-rt codebase tends to use `SANITIZER_MAC` macro (defined to be 1 if 
Apple otherwise it's 0) rather than `__APPLE__`.



Comment at: compiler-rt/lib/ubsan/ubsan_value.cpp:37
+
+  if (!AttemptedDlopen) {
+ObjCHandle = dlopen(

You might want some sort of lock here (or atomic variable) to ensure we don't 
race and try to `dlopen()` multiple times.


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

https://reviews.llvm.org/D71491



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


[clang] a7950ff - [NFC] Correct accidental use of tabs.

2019-12-13 Thread John McCall via cfe-commits

Author: John McCall
Date: 2019-12-14T00:16:47-05:00
New Revision: a7950ffd12caa2fb7ed4704128011bceeacd35e9

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

LOG: [NFC] Correct accidental use of tabs.

Added: 


Modified: 
clang/utils/TableGen/ClangTypeNodesEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangTypeNodesEmitter.cpp 
b/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
index e20998c47ddc..4a3772915ec4 100644
--- a/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
@@ -71,146 +71,146 @@ using namespace llvm;
 #define TypeClassName "Type"
 
 static StringRef getIdForType(Record *type) {
-   // The record name is expected to be the full C++ class name,
-   // including "Type".  Check for that and strip it off.
-   auto fullName = type->getName();
-   if (!fullName.endswith("Type"))
-   PrintFatalError(type->getLoc(), "name of Type node doesn't end 
in Type");
-   return fullName.drop_back(4);
+  // The record name is expected to be the full C++ class name,
+  // including "Type".  Check for that and strip it off.
+  auto fullName = type->getName();
+  if (!fullName.endswith("Type"))
+PrintFatalError(type->getLoc(), "name of Type node doesn't end in Type");
+  return fullName.drop_back(4);
 }
 
 namespace {
 class TypeNodeEmitter {
-   RecordKeeper 
-   raw_ostream 
-   const std::vector Types;
-   std::vector MacrosToUndef;
+  RecordKeeper 
+  raw_ostream 
+  const std::vector Types;
+  std::vector MacrosToUndef;
 
 public:
-   TypeNodeEmitter(RecordKeeper , raw_ostream )
-   : Records(records), Out(out),
-   
Types(Records.getAllDerivedDefinitions(TypeNodeClassName)) {
-   }
+  TypeNodeEmitter(RecordKeeper , raw_ostream )
+: Records(records), Out(out),
+  Types(Records.getAllDerivedDefinitions(TypeNodeClassName)) {
+  }
 
-   void emit();
+  void emit();
 
 private:
-   void emitFallbackDefine(StringRef macroName, StringRef 
fallbackMacroName,
-   
StringRef args);
+  void emitFallbackDefine(StringRef macroName, StringRef fallbackMacroName,
+  StringRef args);
 
-   void emitNodeInvocations();
-   void emitLastNodeInvocation();
-   void emitLeafNodeInvocations();
+  void emitNodeInvocations();
+  void emitLastNodeInvocation();
+  void emitLeafNodeInvocations();
 
-   void addMacroToUndef(StringRef macroName);
-   void emitUndefs();
+  void addMacroToUndef(StringRef macroName);
+  void emitUndefs();
 };
 }
 
 void TypeNodeEmitter::emit() {
-   if (Types.empty())
-   PrintFatalError("no Type records in input!");
-
-   emitSourceFileHeader("An x-macro database of Clang type nodes", Out);
-
-   // Preamble
-   addMacroToUndef(TypeMacroName);
-   addMacroToUndef(AbstractTypeMacroName);
-   emitFallbackDefine(AbstractTypeMacroName, TypeMacroName, TypeMacroArgs);
-   emitFallbackDefine(NonCanonicalTypeMacroName, TypeMacroName, 
TypeMacroArgs);
-   emitFallbackDefine(DependentTypeMacroName, TypeMacroName, 
TypeMacroArgs);
-   emitFallbackDefine(NonCanonicalUnlessDependentTypeMacroName, 
TypeMacroName, 
-   
 TypeMacroArgs);
-
-   // Invocations.
-   emitNodeInvocations();
-   emitLastNodeInvocation();
-   emitLeafNodeInvocations();
-
-   // Postmatter
-   emitUndefs();
+  if (Types.empty())
+PrintFatalError("no Type records in input!");
+
+  emitSourceFileHeader("An x-macro database of Clang type nodes", Out);
+
+  // Preamble
+  addMacroToUndef(TypeMacroName);
+  addMacroToUndef(AbstractTypeMacroName);
+  emitFallbackDefine(AbstractTypeMacroName, TypeMacroName, TypeMacroArgs);
+  emitFallbackDefine(NonCanonicalTypeMacroName, TypeMacroName, TypeMacroArgs);
+  emitFallbackDefine(DependentTypeMacroName, TypeMacroName, TypeMacroArgs);
+  emitFallbackDefine(NonCanonicalUnlessDependentTypeMacroName, TypeMacroName, 
+ TypeMacroArgs);
+
+  // Invocations.
+  emitNodeInvocations();
+  emitLastNodeInvocation();
+  emitLeafNodeInvocations();
+
+  // Postmatter
+  emitUndefs();
 }
 
 void TypeNodeEmitter::emitFallbackDefine(StringRef macroName,
-   

 StringRef fallbackMacroName,
-   

 StringRef args) {

[clang] b6f03a5 - [NFC] Rename ClangASTEmitters.h -> ASTTableGen.h

2019-12-13 Thread John McCall via cfe-commits

Author: John McCall
Date: 2019-12-14T00:16:47-05:00
New Revision: b6f03a5a6b57b7858098051e60c2ce2fd4058461

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

LOG: [NFC] Rename ClangASTEmitters.h -> ASTTableGen.h

Added: 
clang/utils/TableGen/ASTTableGen.h

Modified: 
clang/utils/TableGen/ClangASTNodesEmitter.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/ClangTypeNodesEmitter.cpp
clang/utils/TableGen/TableGen.cpp

Removed: 
clang/utils/TableGen/ClangASTEmitters.h



diff  --git a/clang/utils/TableGen/ClangASTEmitters.h 
b/clang/utils/TableGen/ASTTableGen.h
similarity index 90%
rename from clang/utils/TableGen/ClangASTEmitters.h
rename to clang/utils/TableGen/ASTTableGen.h
index 942c85f1613a..ae85fc9c22b6 100644
--- a/clang/utils/TableGen/ClangASTEmitters.h
+++ b/clang/utils/TableGen/ASTTableGen.h
@@ -1,4 +1,4 @@
-//=== ClangASTEmitters.h - Definitions for AST node emitters *- C++ 
-*-===//
+//=== ASTTableGen.h - Common definitions for AST node tablegen --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 
//===--===//
 
-#ifndef CLANG_AST_EMITTERS
-#define CLANG_AST_EMITTERS
+#ifndef CLANG_AST_TABLEGEN_H
+#define CLANG_AST_TABLEGEN_H
 
 #include "llvm/TableGen/Record.h"
 #include "llvm/ADT/STLExtras.h"

diff  --git a/clang/utils/TableGen/ClangASTNodesEmitter.cpp 
b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
index 704ccda9bbd1..0a4ce8744995 100644
--- a/clang/utils/TableGen/ClangASTNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangASTNodesEmitter.cpp
@@ -10,7 +10,7 @@
 //
 
//===--===//
 
-#include "ClangASTEmitters.h"
+#include "ASTTableGen.h"
 #include "TableGenBackends.h"
 
 #include "llvm/TableGen/Error.h"

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index f9f285c0d4fa..6c32c5f8e24a 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -11,7 +11,7 @@
 
//===--===//
 
 #include "TableGenBackends.h"
-#include "ClangASTEmitters.h"
+#include "ASTTableGen.h"
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"

diff  --git a/clang/utils/TableGen/ClangTypeNodesEmitter.cpp 
b/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
index 764095393514..e20998c47ddc 100644
--- a/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangTypeNodesEmitter.cpp
@@ -45,7 +45,7 @@
 //
 
//===--===//
 
-#include "ClangASTEmitters.h"
+#include "ASTTableGen.h"
 #include "TableGenBackends.h"
 
 #include "llvm/ADT/StringRef.h"

diff  --git a/clang/utils/TableGen/TableGen.cpp 
b/clang/utils/TableGen/TableGen.cpp
index c988a580f298..c118a32f2c33 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -11,7 +11,7 @@
 
//===--===//
 
 #include "TableGenBackends.h" // Declares all backends.
-#include "ClangASTEmitters.h"
+#include "ASTTableGen.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"



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


[PATCH] D71507: [perf-training] Make training data location configurable

2019-12-13 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

I'm not sure where best to document this. We have 
https://llvm.org/docs/HowToBuildWithPGO.html, but that doesn't mention the 
build system's built-in PGO support as far as I can tell.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71507



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


[PATCH] D71507: [perf-training] Make training data location configurable

2019-12-13 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.
smeenai added reviewers: beanz, compnerd, phosek, xiaobai.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

We may wish to keep the PGO training data outside the repository. Add a
CMake variable to allow referencing an external lit testsuite.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71507

Files:
  clang/utils/perf-training/CMakeLists.txt
  clang/utils/perf-training/lit.cfg
  clang/utils/perf-training/lit.site.cfg.in
  clang/utils/perf-training/order-files.lit.cfg
  clang/utils/perf-training/order-files.lit.site.cfg.in


Index: clang/utils/perf-training/order-files.lit.site.cfg.in
===
--- clang/utils/perf-training/order-files.lit.site.cfg.in
+++ clang/utils/perf-training/order-files.lit.site.cfg.in
@@ -3,8 +3,9 @@
 import sys
 
 config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
+config.perf_helper_dir = "@CMAKE_CURRENT_SOURCE_DIR@"
 config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
-config.test_source_root = "@CMAKE_CURRENT_SOURCE_DIR@"
+config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.python_exe = "@PYTHON_EXECUTABLE@"
 
Index: clang/utils/perf-training/order-files.lit.cfg
===
--- clang/utils/perf-training/order-files.lit.cfg
+++ clang/utils/perf-training/order-files.lit.cfg
@@ -28,8 +28,8 @@
 config.name = 'Clang Perf Training'
 config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', 
'.modulemap']
 
-dtrace_wrapper = '%s %s/perf-helper.py dtrace' % (config.python_exe, 
config.test_source_root)
-dtrace_wrapper_cc1 = '%s %s/perf-helper.py dtrace --cc1' % (config.python_exe, 
config.test_source_root)
+dtrace_wrapper = '%s %s/perf-helper.py dtrace' % (config.python_exe, 
config.perf_helper_dir)
+dtrace_wrapper_cc1 = '%s %s/perf-helper.py dtrace --cc1' % (config.python_exe, 
config.perf_helper_dir)
 
 if 'darwin' in config.target_triple:
 lit_config.note('using DTrace oneshot probe')
Index: clang/utils/perf-training/lit.site.cfg.in
===
--- clang/utils/perf-training/lit.site.cfg.in
+++ clang/utils/perf-training/lit.site.cfg.in
@@ -3,8 +3,9 @@
 import sys
 
 config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
+config.perf_helper_dir = "@CMAKE_CURRENT_SOURCE_DIR@"
 config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
-config.test_source_root = "@CMAKE_CURRENT_SOURCE_DIR@"
+config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.python_exe = "@PYTHON_EXECUTABLE@"
 
Index: clang/utils/perf-training/lit.cfg
===
--- clang/utils/perf-training/lit.cfg
+++ clang/utils/perf-training/lit.cfg
@@ -27,7 +27,7 @@
 config.name = 'Clang Perf Training'
 config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', 
'.modulemap']
 
-cc1_wrapper = '%s %s/perf-helper.py cc1' % (config.python_exe, 
config.test_source_root)
+cc1_wrapper = '%s %s/perf-helper.py cc1' % (config.python_exe, 
config.perf_helper_dir)
 
 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
 config.test_format = lit.formats.ShTest(use_lit_shell == "0")
Index: clang/utils/perf-training/CMakeLists.txt
===
--- clang/utils/perf-training/CMakeLists.txt
+++ clang/utils/perf-training/CMakeLists.txt
@@ -10,6 +10,10 @@
 
 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR 
${LLVM_RUNTIME_OUTPUT_INTDIR})
 
+set(CLANG_PGO_TRAINING_DATA "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH
+  "The path to a lit testsuite containing samples for PGO and order file 
generation"
+  )
+
 if(LLVM_BUILD_INSTRUMENTED)
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in


Index: clang/utils/perf-training/order-files.lit.site.cfg.in
===
--- clang/utils/perf-training/order-files.lit.site.cfg.in
+++ clang/utils/perf-training/order-files.lit.site.cfg.in
@@ -3,8 +3,9 @@
 import sys
 
 config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
+config.perf_helper_dir = "@CMAKE_CURRENT_SOURCE_DIR@"
 config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
-config.test_source_root = "@CMAKE_CURRENT_SOURCE_DIR@"
+config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.python_exe = "@PYTHON_EXECUTABLE@"
 
Index: clang/utils/perf-training/order-files.lit.cfg
===
--- clang/utils/perf-training/order-files.lit.cfg
+++ clang/utils/perf-training/order-files.lit.cfg
@@ -28,8 +28,8 @@
 config.name = 'Clang Perf Training'
 config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap']
 
-dtrace_wrapper = '%s %s/perf-helper.py dtrace' % 

[PATCH] D71428: [clang] Move CLANG_BOOTSTRAP_CMAKE_ARGS above PASSTHROUGH_VARIABLES

2019-12-13 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG61c8ee6a2fa4: [clang] Move CLANG_BOOTSTRAP_CMAKE_ARGS above 
PASSTHROUGH_VARIABLES (authored by xinxinw1, committed by smeenai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71428

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -801,8 +801,8 @@
 # We shouldn't need to set this here, but INSTALL_DIR doesn't
 # seem to work, so instead I'm passing this through
 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-${CLANG_BOOTSTRAP_CMAKE_ARGS}
 ${PASSTHROUGH_VARIABLES}
+${CLANG_BOOTSTRAP_CMAKE_ARGS}
  -DCLANG_STAGE=${NEXT_CLANG_STAGE}
 ${COMPILER_OPTIONS}
 ${${CLANG_STAGE}_CONFIG}


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -801,8 +801,8 @@
 # We shouldn't need to set this here, but INSTALL_DIR doesn't
 # seem to work, so instead I'm passing this through
 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-${CLANG_BOOTSTRAP_CMAKE_ARGS}
 ${PASSTHROUGH_VARIABLES}
+${CLANG_BOOTSTRAP_CMAKE_ARGS}
  -DCLANG_STAGE=${NEXT_CLANG_STAGE}
 ${COMPILER_OPTIONS}
 ${${CLANG_STAGE}_CONFIG}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 61c8ee6 - [clang] Move CLANG_BOOTSTRAP_CMAKE_ARGS above PASSTHROUGH_VARIABLES

2019-12-13 Thread Shoaib Meenai via cfe-commits

Author: Xin-Xin Wang
Date: 2019-12-13T19:05:04-08:00
New Revision: 61c8ee6a2fa490bc224d006cd03efd650f6561bb

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

LOG: [clang] Move CLANG_BOOTSTRAP_CMAKE_ARGS above PASSTHROUGH_VARIABLES

I want to pass some CMake cache files in CLANG_BOOTSTRAP_CMAKE_ARGS as
`-C .cmake` arguments. I want to be able to use the values
of the bootstrap passthrough variables in the cache files, so the cache
file arguments need to be after passthrough variables. This should be
safe because the values of passthrough variables are all constants and
can't refer to values in CLANG_BOOTSTRAP_CMAKE_ARGS.

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

Added: 


Modified: 
clang/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 45d2431a7462..bc172b468512 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -801,8 +801,8 @@ if (CLANG_ENABLE_BOOTSTRAP)
 # We shouldn't need to set this here, but INSTALL_DIR doesn't
 # seem to work, so instead I'm passing this through
 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-${CLANG_BOOTSTRAP_CMAKE_ARGS}
 ${PASSTHROUGH_VARIABLES}
+${CLANG_BOOTSTRAP_CMAKE_ARGS}
  -DCLANG_STAGE=${NEXT_CLANG_STAGE}
 ${COMPILER_OPTIONS}
 ${${CLANG_STAGE}_CONFIG}



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


[PATCH] D71503: New warning on for-loops that never run because condition is false on the first iteration

2019-12-13 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu created this revision.

This is a proposed warning to be added to -Wfor-loop-analysis, which is part of 
-Wall.  This warning will catch instances where the condition will be false on 
the first iteration and the loop body will never be run.  The warning will be 
emitted when:

1. The for-loop initializes or sets the value of a single variable to a 
constant value
2. The condition is a simple comparison between the variable and another 
constant value
3. If the initial value of the variable substituted into the comparison would 
cause the comparison to be false

In order to make step 3 work, the constant value from step 1 may need to be 
casted to a different type.  The casts can be extracted from the comparison 
operand.  This allows the warning to work with both integer and floating point 
types, as well as mixing types.

Two exceptions to this warning.

1. Parentheses around the condition will silence this warning.  This is 
suggested in a note.
2. If the variable is used as an array index in the body, and the condition is 
less than a value the same as the array size.

Example:
https://reviews.llvm.org/D48498
This warning would have caught the issue that lebedev.ri brought up about the 
loop not running.


https://reviews.llvm.org/D71503

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaStmt.cpp

Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -1739,6 +1740,258 @@
  << LoopIncrement;
   }
 
+  // Look for any array access of the form array[x] where 'x' is a given Decl
+  // and array is constant array with given size.
+  class ArrayFinder : public ConstEvaluatedExprVisitor {
+// Tracking boolean
+bool FoundArray;
+// Decl used as array index
+const VarDecl *VD;
+// Target size for array
+llvm::APInt Size;
+
+  public:
+typedef ConstEvaluatedExprVisitor Inherited;
+ArrayFinder(const ASTContext ) : Inherited(Context) { }
+
+bool CheckForArrays(const Stmt *Body, llvm::APInt TargetArraySize,
+const VarDecl *D) {
+  FoundArray = false;
+  Size = TargetArraySize;
+  VD = D;
+  Visit(Body);
+  return FoundArray;
+}
+
+void VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+  if (CheckArrayType(E->getBase()) && CheckIndex(E->getIdx())) {
+FoundArray = true;
+  }
+  Inherited::VisitArraySubscriptExpr(E);
+}
+
+  private:
+// Helper function for checking array access.
+bool CheckArrayType(const Expr *E) {
+  QualType ArrayTy = E->IgnoreImpCasts()->getType();
+  if (!ArrayTy->isConstantArrayType())
+return false;
+  const ConstantArrayType *CAT = Context.getAsConstantArrayType(ArrayTy);
+  if (!CAT)
+return false;
+  if (!llvm::APInt::isSameValue(CAT->getSize(), Size))
+return false;
+  return true;
+}
+
+// Helper function for checking array access.
+bool CheckIndex(const Expr *E) {
+  const DeclRefExpr *DRE = dyn_cast(E->IgnoreImpCasts());
+  return DRE && DRE->getDecl() == VD;
+}
+
+  };
+
+  // Emit a warning when the condition of a for-loop is false on the first
+  // iteration, making the loop body never executed.  Conditions in parenthesis
+  // will silence the warning.  Loop variables used as array accesses are also
+  // skipped.
+  void CheckFirstIterationCondition(Sema , const Stmt *First,
+const Expr *Second, const Stmt *Body) {
+if (!First || !Second || Second->isTypeDependent() ||
+Second->isValueDependent())
+  return;
+if (S.inTemplateInstantiation())
+  return;
+if (Second->getExprLoc().isMacroID())
+  return;
+
+if (S.Diags.isIgnored(diag::warn_loop_never_run, Second->getBeginLoc()))
+  return;
+
+// Only work on loop conditions that are comparisons.
+const BinaryOperator *CompareBO = dyn_cast(Second);
+if (!CompareBO || !CompareBO->isComparisonOp())
+  return;
+
+// Examine the loop initilization and extract the single Decl used and its
+// initial value.
+const VarDecl *D = nullptr;
+APValue InitValue;
+if (const DeclStmt *DS = dyn_cast(First)) {
+  // A loop variable being declared.
+  if (!DS->isSingleDecl())
+return;
+  D = dyn_cast(DS->getSingleDecl());
+  if (!D || !D->getInit())
+return;
+  Expr::EvalResult Result;
+  if (!D->getInit()->EvaluateAsRValue(Result, S.Context))
+return;
+  InitValue = Result.Val;
+} else if (const Expr 

[PATCH] D71155: [analyzer] CERT: STR30-C

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 3 inline comments as done.
Charusso added a comment.

In order to bypass the `CK_LValueToRValue` `evalCast()` we have to create en 
`ElementRegion` as a return-value of the problematic function call. In that 
case for a mythical reason we miss the fact the pointer is nullable. I have not 
figured out yet why, but tried to create an appropriate return-value.




Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2122
+
+  SVal ConjuredV = SVB.getConjuredHeapSymbolVal(CE, LCtx, C.blockCount());
+  SVal ResultV = loc::MemRegionVal(SVB.getRegionManager().getElementRegion(

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Why "heap"?
> > Well, a string which length is at least 16 characters long is going to be 
> > allocated on the heap. I have to conjure the string here to create its 
> > element.
> o.o
> ```lang=c++
> void foo() {
>   // This string is 20 characters long
>   // but it's clearly on the stack.
>   char str[] = "12345678901234567890";
>   // This one is therefore also on the stack.
>   char *ptr = strchr(str, '0');
> }
> ```
> Well, a string which length is at least 16 characters long is going to be 
> allocated on the heap. I have to conjure the string here to create its 
> element.

I really felt that the `std::string` should behave like the C-strings, but 
C-strings are on the stack whatever it takes, yes, my bad. Thanks for pointing 
that out!



Comment at: clang/test/Analysis/cert/str30-c-notes.cpp:29
+  if (slash) {
+// expected-note@-1 {{'slash' is non-null}}
+// expected-note@-2 {{Taking true branch}}

Needs to be an assumption.


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

https://reviews.llvm.org/D71155



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


[PATCH] D71033: [analyzer] CERT: STR32-C

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

We need to add the interestingness to the `NoteTags` so that we only emit notes 
on initialization/function calls which leads to an error.


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

https://reviews.llvm.org/D71033



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


[PATCH] D71167: [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG074323c84658: [Driver] Default to -momit-leaf-frame-pointer 
for AArch64 (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D71167?vs=232714=233906#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71167

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/frame-pointer-elim.c


Index: clang/test/Driver/frame-pointer-elim.c
===
--- clang/test/Driver/frame-pointer-elim.c
+++ clang/test/Driver/frame-pointer-elim.c
@@ -90,7 +90,9 @@
 // WARN-OMIT-LEAF-7S-NOT: warning: optimization flag 
'-momit-leaf-frame-pointer' is not supported for target 'armv7s'
 // WARN-OMIT-LEAF-7S: "-mframe-pointer=non-leaf"
 
-// On the PS4, we default to omitting the frame pointer on leaf functions
+// On AArch64 and PS4, default to omitting the frame pointer on leaf functions
+// RUN: %clang -### -target aarch64 -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S -O2 %s 2>&1 | \
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -182,7 +182,7 @@
 // Oy_2: -O2
 
 // RUN: %clang_cl --target=aarch64-pc-windows-msvc -Werror /Oy- /O2 -### -- %s 
2>&1 | FileCheck -check-prefix=Oy_aarch64 %s
-// Oy_aarch64: -mframe-pointer=all
+// Oy_aarch64: -mframe-pointer=non-leaf
 // Oy_aarch64: -O2
 
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | 
FileCheck -check-prefix=O2O2 %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -603,9 +603,9 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf =
-  Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer, 
Triple.isPS4CPU());
+  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+   options::OPT_mno_omit_leaf_frame_pointer,
+   Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
 if (KeepLeaf)


Index: clang/test/Driver/frame-pointer-elim.c
===
--- clang/test/Driver/frame-pointer-elim.c
+++ clang/test/Driver/frame-pointer-elim.c
@@ -90,7 +90,9 @@
 // WARN-OMIT-LEAF-7S-NOT: warning: optimization flag '-momit-leaf-frame-pointer' is not supported for target 'armv7s'
 // WARN-OMIT-LEAF-7S: "-mframe-pointer=non-leaf"
 
-// On the PS4, we default to omitting the frame pointer on leaf functions
+// On AArch64 and PS4, default to omitting the frame pointer on leaf functions
+// RUN: %clang -### -target aarch64 -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S -O2 %s 2>&1 | \
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -182,7 +182,7 @@
 // Oy_2: -O2
 
 // RUN: %clang_cl --target=aarch64-pc-windows-msvc -Werror /Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_aarch64 %s
-// Oy_aarch64: -mframe-pointer=all
+// Oy_aarch64: -mframe-pointer=non-leaf
 // Oy_aarch64: -O2
 
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | FileCheck -check-prefix=O2O2 %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -603,9 +603,9 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf =
-  Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer, Triple.isPS4CPU());
+  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+   options::OPT_mno_omit_leaf_frame_pointer,
+   Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || 

[PATCH] D71155: [analyzer] CERT: StrChecker: 30.c

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 233905.
Charusso marked 6 inline comments as done.
Charusso added a comment.

- Try to conjure the index of the 'ElementRegion'.


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

https://reviews.llvm.org/D71155

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
  clang/test/Analysis/cert/str30-c-explain.cpp
  clang/test/Analysis/cert/str30-c-notes.cpp
  clang/test/Analysis/cert/str30-c.cpp

Index: clang/test/Analysis/cert/str30-c.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str30-c.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.30c \
+// RUN:  -verify %s
+
+// See the examples on the page of STR30-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR30-C.+Do+not+attempt+to+modify+string+literals
+
+#include "../Inputs/system-header-simulator.h"
+
+#define EOF -1
+typedef __SIZE_TYPE__ size_t;
+typedef __typeof__((char *)0 - (char *)0) ptrdiff_t;
+
+void free(void *memblock);
+void *malloc(size_t size);
+
+char *strrchr(const char *str, int c);
+int puts(const char *str);
+
+namespace test_strrchr_bad {
+const char *get_dirname(const char *pathname) {
+  char *slash;
+  slash = strrchr(pathname, '/');
+  if (slash) {
+*slash = '\0'; /* Undefined behavior */
+// expected-warning@-1 {{'slash' is pointing to a constant string}}
+  }
+  return pathname;
+}
+
+int main(void) {
+  puts(get_dirname(__FILE__));
+  return 0;
+}
+} // namespace test_strrchr_bad
+
+namespace test_strrchr_good {
+char *get_dirname(const char *pathname, char *dirname, size_t size) {
+  const char *slash;
+  slash = strrchr(pathname, '/');
+  if (slash) {
+ptrdiff_t slash_idx = slash - pathname;
+if ((size_t)slash_idx < size) {
+  memcpy(dirname, pathname, slash_idx);
+  dirname[slash_idx] = '\0';
+  return dirname;
+}
+  }
+  return 0;
+}
+
+int main(void) {
+  char dirname[260];
+  if (get_dirname(__FILE__, dirname, sizeof(dirname))) {
+puts(dirname);
+  }
+  return 0;
+}
+} // namespace test_strrchr_good
Index: clang/test/Analysis/cert/str30-c-notes.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str30-c-notes.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.30c \
+// RUN:  -analyzer-output=text -verify %s
+
+// See the examples on the page of STR30-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR30-C.+Do+not+attempt+to+modify+string+literals
+
+#include "../Inputs/system-header-simulator.h"
+
+#define EOF -1
+typedef __SIZE_TYPE__ size_t;
+
+void free(void *memblock);
+void *malloc(size_t size);
+
+char *strrchr(const char *str, int c);
+int puts(const char *str);
+
+namespace test_strrchr_bad {
+const char *get_dirname(const char *pathname) {
+  char *slash;
+  slash = strrchr(pathname, '/');
+  // expected-note@-1 {{'strrchr' returns a pointer to the constant 'pathname'}}
+
+  slash = strrchr(slash, '/');
+  // expected-note@-1 {{'strrchr' returns a pointer to the constant 'pathname'}}
+
+  if (slash) {
+// expected-note@-1 {{'slash' is non-null}}
+// expected-note@-2 {{Taking true branch}}
+
+*slash = '\0'; /* Undefined behavior */
+// expected-note@-1 {{'slash' is pointing to a constant string}}
+// expected-warning@-2 {{'slash' is pointing to a constant string}}
+  }
+  return pathname;
+}
+
+int main(void) {
+  puts(get_dirname(__FILE__));
+  // expected-note@-1 {{Calling 'get_dirname'}}
+  return 0;
+}
+} // namespace test_strrchr_bad
Index: clang/test/Analysis/cert/str30-c-explain.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str30-c-explain.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.30c \
+// RUN:  -analyzer-checker=debug.ExprInspection \
+// RUN:  %s 2>&1 | FileCheck %s
+
+// See the examples on the page of STR30-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR30-C.+Do+not+attempt+to+modify+string+literals
+
+#include "../Inputs/system-header-simulator.h"
+
+char *strrchr(const char *str, int c);
+
+void clang_analyzer_explain(char *);
+void clang_analyzer_dump(char *);
+
+void dump(const char *pathname) {
+  char *slash;
+  slash = strrchr(pathname, '/');
+
+  clang_analyzer_dump(slash);
+  // CHECK: {pathname,conj_$1{long long, LC1, S{{[0-9]+}}, #1},char}
+
+  clang_analyzer_explain(slash);
+  // CHECK: pointer to element of type 'char' with index 'symbol of type 'long long' conjured at statement 'pathname'' of parameter 'pathname'
+}
Index: clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp

[PATCH] D71033: [analyzer] CERT: STR32-C

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp:479
+if (VD->getType()->getAsArrayTypeUnsafe()) {
+  VD->dumpColor();
+  ProgramStateRef State = C.getState();

-1 line


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

https://reviews.llvm.org/D71033



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


[clang] 074323c - [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2019-12-13T18:48:34-08:00
New Revision: 074323c84658e51522e7d8d3d0179e53004b219c

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

LOG: [Driver] Default to -momit-leaf-frame-pointer for AArch64

This matches https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html

> -momit-leaf-frame-pointer
> -mno-omit-leaf-frame-pointer
>
>   Omit or keep the frame pointer in leaf functions. The former behavior is 
> the default.

-mno-omit-leaf-frame-pointer is currently a no-op because
TargetOptions::DisableFramePointerElim is only considered for non-leaf
functions.

Reviewed By: efriedma

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/frame-pointer-elim.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1ba755622136..5c28a3ab1735 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -603,9 +603,9 @@ getFramePointerKind(const ArgList , const llvm::Triple 
) {
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf =
-  Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer, 
Triple.isPS4CPU());
+  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+   options::OPT_mno_omit_leaf_frame_pointer,
+   Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
 if (KeepLeaf)

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index b82d69b6430a..2a5453b10d26 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -182,7 +182,7 @@
 // Oy_2: -O2
 
 // RUN: %clang_cl --target=aarch64-pc-windows-msvc -Werror /Oy- /O2 -### -- %s 
2>&1 | FileCheck -check-prefix=Oy_aarch64 %s
-// Oy_aarch64: -mframe-pointer=all
+// Oy_aarch64: -mframe-pointer=non-leaf
 // Oy_aarch64: -O2
 
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | 
FileCheck -check-prefix=O2O2 %s

diff  --git a/clang/test/Driver/frame-pointer-elim.c 
b/clang/test/Driver/frame-pointer-elim.c
index 099df7175f67..47c1c0549212 100644
--- a/clang/test/Driver/frame-pointer-elim.c
+++ b/clang/test/Driver/frame-pointer-elim.c
@@ -90,7 +90,9 @@
 // WARN-OMIT-LEAF-7S-NOT: warning: optimization flag 
'-momit-leaf-frame-pointer' is not supported for target 'armv7s'
 // WARN-OMIT-LEAF-7S: "-mframe-pointer=non-leaf"
 
-// On the PS4, we default to omitting the frame pointer on leaf functions
+// On AArch64 and PS4, default to omitting the frame pointer on leaf functions
+// RUN: %clang -### -target aarch64 -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NON-LEAF %s
 // RUN: %clang -### -target x86_64-scei-ps4 -S -O2 %s 2>&1 | \



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


[PATCH] D71033: [analyzer] CERT: STR32-C

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 233904.
Charusso retitled this revision from "[analyzer] CERT: StrChecker: 32.c" to 
"[analyzer] CERT: STR32-C".
Charusso added a comment.

- Add notes to the initialization of char-arrays.


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

https://reviews.llvm.org/D71033

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/cert/str31-c-notes-warn-on-call-off.cpp
  clang/test/Analysis/cert/str31-c-notes-warn-on-call-on.cpp
  clang/test/Analysis/cert/str32-c-notes.cpp
  clang/test/Analysis/cert/str32-c.cpp
  clang/test/Analysis/malloc.c

Index: clang/test/Analysis/malloc.c
===
--- clang/test/Analysis/malloc.c
+++ clang/test/Analysis/malloc.c
@@ -9,21 +9,6 @@
 
 void clang_analyzer_eval(int);
 
-// Without -fms-compatibility, wchar_t isn't a builtin type. MSVC defines
-// _WCHAR_T_DEFINED if wchar_t is available. Microsoft recommends that you use
-// the builtin type: "Using the typedef version can cause portability
-// problems", but we're ok here because we're not actually running anything.
-// Also of note is this cryptic warning: "The wchar_t type is not supported
-// when you compile C code".
-//
-// See the docs for more:
-// https://msdn.microsoft.com/en-us/library/dh8che7s.aspx
-#if !defined(_WCHAR_T_DEFINED)
-// "Microsoft implements wchar_t as a two-byte unsigned value"
-typedef unsigned short wchar_t;
-#define _WCHAR_T_DEFINED
-#endif // !defined(_WCHAR_T_DEFINED)
-
 typedef __typeof(sizeof(int)) size_t;
 void *malloc(size_t);
 void *alloca(size_t);
Index: clang/test/Analysis/cert/str32-c.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str32-c.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.32c \
+// RUN:  -verify %s
+
+// See the examples on the page of STR32-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string
+
+#include "../Inputs/system-header-simulator.h"
+
+void *realloc(void *memblock, size_t size);
+
+namespace test_strncpy_bad {
+enum { STR_SIZE = 32 };
+
+size_t func(const char *source) {
+  char c_str[STR_SIZE];
+  size_t ret = 0;
+
+  if (source) {
+c_str[sizeof(c_str) - 1] = '\0';
+strncpy(c_str, source, sizeof(c_str));
+ret = strlen(c_str);
+// expected-warning@-1 {{'c_str' is not null-terminated}}
+  }
+  return ret;
+}
+} // namespace test_strncpy_bad
+
+namespace test_strncpy_good {
+enum { STR_SIZE = 32 };
+
+size_t func(const char *src) {
+  char c_str[STR_SIZE];
+  size_t ret = 0;
+
+  if (src) {
+strncpy(c_str, src, sizeof(c_str) - 1);
+c_str[sizeof(c_str) - 1] = '\0';
+ret = strlen(c_str);
+  }
+  return ret;
+}
+} // namespace test_strncpy_good
+
+namespace test_realloc_bad {
+wchar_t *cur_msg = NULL;
+size_t cur_msg_size = 1024;
+size_t cur_msg_len = 0;
+
+void lessen_memory_usage(void) {
+  if (cur_msg == NULL)
+return;
+
+  size_t temp_size = cur_msg_size / 2 + 1;
+  wchar_t *temp = (wchar_t *)realloc(cur_msg, temp_size * sizeof(wchar_t));
+  /* temp and cur_msg may no longer be null-terminated */
+  if (temp == NULL)
+return;
+
+  cur_msg = temp;
+  cur_msg_size = temp_size;
+  cur_msg_len = wcslen(cur_msg);
+  // expected-warning@-1 {{'cur_msg' is not null-terminated}}
+}
+} // namespace test_realloc_bad
+
+namespace test_realloc_good {
+wchar_t *cur_msg = NULL;
+size_t cur_msg_size = 1024;
+size_t cur_msg_len = 0;
+
+void lessen_memory_usage(void) {
+  if (cur_msg == NULL)
+return;
+
+  size_t temp_size = cur_msg_size / 2 + 1;
+  wchar_t *temp = (wchar_t *)realloc(cur_msg, temp_size * sizeof(wchar_t));
+  /* temp and cur_msg may no longer be null-terminated */
+  if (temp == NULL)
+return;
+
+  cur_msg = temp;
+  /* Properly null-terminate cur_msg */
+  cur_msg[temp_size - 1] = L'\0';
+  cur_msg_size = temp_size;
+  cur_msg_len = wcslen(cur_msg);
+}
+} // namespace test_realloc_good
Index: clang/test/Analysis/cert/str32-c-notes.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str32-c-notes.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.32c \
+// RUN:  -analyzer-output=text -verify %s
+
+// See the examples on the page of STR32-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string
+
+#include "../Inputs/system-header-simulator.h"
+
+void 

[PATCH] D70411: [analyzer] CERT: STR31-C

2019-12-13 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 233903.
Charusso retitled this revision from "[analyzer] CERT: StrChecker: Implementing 
most of the STR31-C" to "[analyzer] CERT: STR31-C".
Charusso added a comment.

- Iterate over parameters rather arguments for searching string-reading.
- Better notes of the argument's index.
- Avoid `C.getPredecessor()`, use the error-node instead.


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

https://reviews.llvm.org/D70411

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSizeInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/lib/StaticAnalyzer/Checkers/AllocationState.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
  clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cert/str31-c-notes-warn-on-call-off.cpp
  clang/test/Analysis/cert/str31-c-notes-warn-on-call-on.cpp
  clang/test/Analysis/cert/str31-c-warn-on-call-off.cpp
  clang/test/Analysis/cert/str31-c-warn-on-call-on.cpp
  clang/test/Analysis/cert/str31-c.cpp

Index: clang/test/Analysis/cert/str31-c.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str31-c.cpp
@@ -0,0 +1,196 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.31c \
+// RUN:  -verify %s
+
+// See the examples on the page of STR31-C:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR31-C.+Guarantee+that+storage+for+strings+has+sufficient+space+for+character+data+and+the+null+terminator
+
+#include "../Inputs/system-header-simulator.h"
+
+#define EOF -1
+typedef __SIZE_TYPE__ size_t;
+
+void free(void *memblock);
+void *malloc(size_t size);
+
+void do_something(char *buffer);
+
+namespace test_gets_bad {
+#define BUFFER_SIZE 1024
+
+void func(void) {
+  char buf[BUFFER_SIZE];
+  if (gets(buf)) {
+// expected-warning@-1 {{'gets' could write outside of 'buf'}}
+  }
+}
+} // namespace test_gets_bad
+
+namespace test_gets_good {
+enum { BUFFERSIZE = 32 };
+
+void func(void) {
+  char buff[BUFFERSIZE];
+
+  if (fgets(buff, sizeof(buff), stdin)) {
+  }
+}
+} // namespace test_gets_good
+
+namespace test_sprintf_bad {
+void func(const char *name) {
+  char buf[128];
+  sprintf(buf, "%s.txt", name);
+  // expected-warning@-1 {{'sprintf' could write outside of 'buf'}}
+}
+} // namespace test_sprintf_bad
+
+namespace test_sprintf_good {
+void func(const char *name) {
+  char buff[128];
+  snprintf(buff, sizeof(buff), "%s.txt", name);
+
+  do_something(buff);
+}
+} // namespace test_sprintf_good
+
+namespace test_fscanf_bad {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buf[BUF_LENGTH];
+  if (fscanf(stdin, "%s", buf)) {
+// expected-warning@-1 {{'fscanf' could write outside of 'buf'}}
+  }
+}
+} // namespace test_fscanf_bad
+
+namespace test_fscanf_good {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buff[BUF_LENGTH];
+  if (fscanf(stdin, "%1023s", buff)) {
+do_something(buff);
+  }
+}
+} // namespace test_fscanf_good
+
+namespace test_strcpy_bad {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char prog_name[128];
+  strcpy(prog_name, name);
+  // expected-warning@-1 {{'strcpy' could write outside of 'prog_name'}}
+
+  return 0;
+}
+
+void func(void) {
+  char buff[256];
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+strcpy(buff, editor);
+// expected-warning@-1 {{'strcpy' could write outside of 'buff'}}
+  }
+}
+} // namespace test_strcpy_bad
+
+namespace test_strcpy_good {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char *prog_name2 = (char *)malloc(strlen(name) + 1);
+  if (prog_name2 != NULL) {
+strcpy(prog_name2, name);
+  }
+
+  do_something(prog_name2);
+
+  free(prog_name2);
+  return 0;
+}
+
+void func(void) {
+  char *buff2;
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+size_t len = strlen(editor) + 1;
+buff2 = (char *)malloc(len);
+if (buff2 != NULL) {
+  strcpy(buff2, editor);
+}
+
+do_something(buff2);
+free(buff2);
+  }
+}
+} // namespace test_strcpy_good
+
+//===--===//
+// The following are from the rule's page which we do not handle yet.
+//===--===//
+
+namespace test_loop_index_bad {
+void copy(size_t n, char src[n], char dest[n]) {
+  size_t i;
+
+  for (i = 0; src[i] && (i < n); ++i) {
+dest[i] = src[i];
+  }

[clang] 38c3b5d - [c++20] Improve phrasing of diagnostic for missing #include .

2019-12-13 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2019-12-13T18:41:54-08:00
New Revision: 38c3b5d562ac6a5ab0ef5503838aad362af866e0

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

LOG: [c++20] Improve phrasing of diagnostic for missing #include .

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/std-compare-cxx2a.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b91fd262c9d3..d657c29adafd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10145,8 +10145,8 @@ def warn_dispatch_body_ignored : Warning<
 
 // three-way comparison operator diagnostics
 def err_implied_comparison_category_type_not_found : Error<
-  "cannot deduce return type of 'operator<=>' because type '%0' was not found; 
"
-  "include ">;
+  "cannot %select{use builtin operator '<=>'|default 'operator<=>'}1 "
+  "because type '%0' was not found; include ">;
 def err_spaceship_argument_narrowing : Error<
   "argument to 'operator<=>' "
   "%select{cannot be narrowed from type %1 to %2|"

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 53db210a0177..6d0f79a2d2ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5038,6 +5038,16 @@ class Sema final {
  IdentifierInfo *MemberOrBase);
 
 public:
+  enum class ComparisonCategoryUsage {
+/// The '<=>' operator was used in an expression and a builtin operator
+/// was selected.
+OperatorInExpression,
+/// A defaulted 'operator<=>' needed the comparison category. This
+/// typically only applies to 'std::strong_ordering', due to the implicit
+/// fallback return value.
+DefaultedOperator,
+  };
+
   /// Lookup the specified comparison category types in the standard
   ///   library, an check the VarDecls possibly returned by the operator<=>
   ///   builtins for that type.
@@ -5045,7 +5055,8 @@ class Sema final {
   /// \return The type of the comparison category type corresponding to the
   ///   specified Kind, or a null type if an error occurs
   QualType CheckComparisonCategoryType(ComparisonCategoryType Kind,
-   SourceLocation Loc);
+   SourceLocation Loc,
+   ComparisonCategoryUsage Usage);
 
   /// Tests whether Ty is an instance of std::initializer_list and, if
   /// it is and Element is not NULL, assigns the element type to Element.

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ba4d450984a3..239aaf65c86b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7599,7 +7599,8 @@ class DefaultedComparisonSynthesizer
   // Per C++2a [class.spaceship]p3, as a fallback add:
   // return static_cast(std::strong_ordering::equal);
   QualType StrongOrdering = S.CheckComparisonCategoryType(
-  ComparisonCategoryType::StrongOrdering, Loc);
+  ComparisonCategoryType::StrongOrdering, Loc,
+  Sema::ComparisonCategoryUsage::DefaultedOperator);
   if (StrongOrdering.isNull())
 return StmtError();
   VarDecl *EqualVD = 
S.Context.CompCategories.getInfoForType(StrongOrdering)
@@ -8057,7 +8058,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   RetLoc = FD->getBeginLoc();
 // FIXME: Should we really care whether we have the complete type and the
 // 'enumerator' constants here? A forward declaration seems sufficient.
-QualType Cat = CheckComparisonCategoryType(Info.Category, RetLoc);
+QualType Cat = CheckComparisonCategoryType(
+Info.Category, RetLoc, ComparisonCategoryUsage::DefaultedOperator);
 if (Cat.isNull())
   return true;
 Context.adjustDeducedFunctionResultType(
@@ -10591,7 +10593,8 @@ struct InvalidSTLDiagnoser {
 } // namespace
 
 QualType Sema::CheckComparisonCategoryType(ComparisonCategoryType Kind,
-   SourceLocation Loc) {
+   SourceLocation Loc,
+   ComparisonCategoryUsage Usage) {
   assert(getLangOpts().CPlusPlus &&
  "Looking for comparison category type outside of C++.");
 
@@ -10620,7 +10623,7 @@ QualType 
Sema::CheckComparisonCategoryType(ComparisonCategoryType Kind,
 std::string NameForDiags = "std::";
 NameForDiags += ComparisonCategories::getCategoryString(Kind);
 Diag(Loc, 

[clang] c5b890e - PR44268: Fix crash if __builtin_object_size is applied to a heap

2019-12-13 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2019-12-13T18:41:54-08:00
New Revision: c5b890e922432bd80a5e3c6d82994ef4cdc41900

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

LOG: PR44268: Fix crash if __builtin_object_size is applied to a heap
allocation.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/builtin-object-size-cxx14.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fbc706b25d15..f3856f58b113 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10218,7 +10218,7 @@ static QualType getObjectType(APValue::LValueBase B) {
   if (const ValueDecl *D = B.dyn_cast()) {
 if (const VarDecl *VD = dyn_cast(D))
   return VD->getType();
-  } else if (const Expr *E = B.get()) {
+  } else if (const Expr *E = B.dyn_cast()) {
 if (isa(E))
   return E->getType();
   } else if (B.is()) {

diff  --git a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp 
b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
index a57bb6b53787..b7c6f6be01f5 100644
--- a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
+++ b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -std=c++14 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
 
 typedef __SIZE_TYPE__ size_t;
@@ -113,3 +113,9 @@ namespace InvalidBase {
   constexpr size_t bos_dtor = 
__builtin_object_size(&(T&)(T&&)invalid_base_2(), 0);
   static_assert(bos_dtor == -1, "");
 }
+
+// PR44268
+constexpr int bos_new() { // cxx14-error {{constant expression}}
+  void *p = new int; // cxx14-note {{until C++20}}
+  return __builtin_object_size(p, 0);
+}



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


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D62731#1784491 , @pengfei wrote:

> >> It's good that people are looking at achieving better modeling for the x86 
> >> backend, but we need to have a plan that doesn't require heroic effort 
> >> just to get basic correctness.
> > 
> > Do you mean in the backend? If so, I don't think that's possible. The 
> > backends just don't have any sort of feature that could be used to get 
> > conservatively correct behavior for cheap the way intrinsics give it to us 
> > in the middle end. Once you go into instruction selection things get very 
> > low level in a hurry.
>
> I'm looking for simple ways to modeling X86 intrinsics, but haven't find 
> better one than modeling it one by one.
>
> > I would suggest that we need a function/call attribute roughly on the level 
> > of `readonly` / `readnone`, maybe `readfponly`, that says that a function 
> > has no side-effects and no dependencies on anything *except* the FP state.
>
> Do you mean mark it at the declaration of intrinsics? Is it reasonable to 
> mark `except` on dependent intrinsics?
>
> > Basic queries like `Instruction::mayReadMemory()` that are supposed to be 
> > used generically in code-motion transforms would then return true for calls 
> > marked that way only if they're FP-constrained functions.
>
> Middle end or back end? I think in middle end you may need to change all 
> releated passes to get such information to prevent optimization. And in back 
> end, I think we can simply chain intrinsics marked `except` with other FP 
> nodes like what common code doing.


We don't want to do this all the time. So we need a new property for the 
intrinsics that means we should prevent code motion in the middle end when the 
calling function has the strictfp attribute. Similarly SelectionDAGBuilder 
should use INTRINSIC_W_CHAIN instead of INTRINSIC_WO_CHAIN for any of these 
intrinsics when strictp is enabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[PATCH] D69732: [WIP][LTO] Apply SamplePGO pipeline tunes for ThinLTO pre-link to full LTO

2019-12-13 Thread Warren Ristow via Phabricator via cfe-commits
wristow added a comment.

>> Given the performance improvements here, I'd like to develop this patch 
>> further.
> 
> In D69732#1784290 , @ormris wrote:
>  //Ping// @tejohnson

@ormris, I think that since @tejohnson originally suggested that someone with 
more interest in full LTO performance pick this up (and she specifically 
suggested you or me), then you can feel free to take this over.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69732



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


[PATCH] D66049: [analyzer] PR41729: Fix some false positives and improve strlcat and strlcpy modeling

2019-12-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1710-1711
+  // strlcat returns strlen(src) + strlen(dst)
+  SVal retSize = svalBuilder.evalBinOpNN(
+  state, BO_Add, *strLengthNL, *dstStrLengthNL, sizeTy);
+  StateZeroSize =

rGf450dd63a14d

Please use the normal `evalBinOp` without suffixes, it just works!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66049



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


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

>> It's good that people are looking at achieving better modeling for the x86 
>> backend, but we need to have a plan that doesn't require heroic effort just 
>> to get basic correctness.
> 
> Do you mean in the backend? If so, I don't think that's possible. The 
> backends just don't have any sort of feature that could be used to get 
> conservatively correct behavior for cheap the way intrinsics give it to us in 
> the middle end. Once you go into instruction selection things get very low 
> level in a hurry.

I'm looking for simple ways to modeling X86 intrinsics, but haven't find better 
one than modeling it one by one.

> I would suggest that we need a function/call attribute roughly on the level 
> of `readonly` / `readnone`, maybe `readfponly`, that says that a function has 
> no side-effects and no dependencies on anything *except* the FP state.

Do you mean mark it at the declaration of intrinsics? Is it reasonable to mark 
`except` on dependent intrinsics?

> Basic queries like `Instruction::mayReadMemory()` that are supposed to be 
> used generically in code-motion transforms would then return true for calls 
> marked that way only if they're FP-constrained functions.

Middle end or back end? I think in middle end you may need to change all 
releated passes to get such information to prevent optimization. And in back 
end, I think we can simply chain intrinsics marked `except` with other FP nodes 
like what common code doing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[PATCH] D67923: [TLI] Support for per-Function TLI that overrides available libfuncs

2019-12-13 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

In D67923#1784015 , @tejohnson wrote:

> Please take a look. This is now updated to reflect the commit of D71193 
> , which translated the options to the new 
> attributes. I also removed some comments that I realized didn't make sense, 
> as we need to keep a baseline availability array on the base TLII since that 
> is set based on the architecture. We simply override this for no-builtin* 
> attributes on the function. I removed the code from clang that was setting up 
> the availability array based on the options, and all tests pass.


LGTM.




Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:52
   unsigned char AvailableArray[(NumLibFuncs+3)/4];
+
   llvm::DenseMap CustomNames;

Unintentional new whitespace?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67923



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


[clang] f450dd6 - [analyzer] CStringChecker: Fix a crash on unknown value passed to strlcat.

2019-12-13 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2019-12-13T18:00:24-08:00
New Revision: f450dd63a14d6cb16418f6a6f4de26916502c13f

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

LOG: [analyzer] CStringChecker: Fix a crash on unknown value passed to strlcat.

Checkers should always account for unknown values.

Also use a slightly more high-level API that naturally avoids the problem.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/test/Analysis/bsd-string.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 4203f790e211..0cf7056a0783 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -1706,13 +1706,12 @@ void CStringChecker::evalStrcpyCommon(CheckerContext 
, const CallExpr *CE,
   } else {
 if (appendK == ConcatFnKind::none) {
   // strlcpy returns strlen(src)
-  StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, *strLengthNL);
-} else if (dstStrLengthNL) {
+  StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, strLength);
+} else {
   // strlcat returns strlen(src) + strlen(dst)
-  SVal retSize = svalBuilder.evalBinOpNN(
-  state, BO_Add, *strLengthNL, *dstStrLengthNL, sizeTy);
-  StateZeroSize =
-  StateZeroSize->BindExpr(CE, LCtx, 
*(retSize.getAs()));
+  SVal retSize = svalBuilder.evalBinOp(
+  state, BO_Add, strLength, dstStrLength, sizeTy);
+  StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, retSize);
 }
   }
   C.addTransition(StateZeroSize);

diff  --git a/clang/test/Analysis/bsd-string.c 
b/clang/test/Analysis/bsd-string.c
index 3778664a8ef5..adb8721c3fa2 100644
--- a/clang/test/Analysis/bsd-string.c
+++ b/clang/test/Analysis/bsd-string.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: %clang_analyze_cc1 -w -verify %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=unix.cstring.NullArg \
 // RUN:   -analyzer-checker=alpha.unix.cstring \
@@ -131,3 +131,9 @@ void f11() {
   strlcpy(b, "hello ", sizeof(b));
   strlcat(b, a, sizeof(b)); // no-warning
 }
+
+int a, b;
+void unknown_val_crash() {
+  // We're unable to evaluate the integer-to-pointer cast.
+  strlcat(, a, 0); // no-crash
+}



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


[PATCH] D71167: [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

Okay, LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71167



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


[PATCH] D71500: [WebAssembly] Replace SIMD int min/max builtins with patterns

2019-12-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 60871 tests passed, 0 failed 
and 726 were skipped.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
console-log.txt 
,
 CMakeCache.txt 
,
 test-results.xml 
,
 diff.json 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71500



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


[PATCH] D71500: [WebAssembly] Replace SIMD int min/max builtins with patterns

2019-12-13 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.

The instructions were originally implemented via builtins and
intrinsics so users would have to explicitly opt-in to using
them. This was useful while were validating whether these instructions
should have been merged into the spec proposal. Now that they have
been, we can use normal codegen patterns, so the intrinsics and
builtins are no longer useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71500

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-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-arith.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -65,46 +65,6 @@
   ret <16 x i8> %a
 }
 
-; CHECK-LABEL: min_s_v16i8:
-; SIMD128-NEXT: .functype min_s_v16i8 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i8x16.min_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <16 x i8> @llvm.wasm.min.signed.v16i8(<16 x i8>, <16 x i8>)
-define <16 x i8> @min_s_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <16 x i8> @llvm.wasm.min.signed.v16i8(<16 x i8> %x, <16 x i8> %y)
-  ret <16 x i8> %a
-}
-
-; CHECK-LABEL: min_u_v16i8:
-; SIMD128-NEXT: .functype min_u_v16i8 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i8x16.min_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <16 x i8> @llvm.wasm.min.unsigned.v16i8(<16 x i8>, <16 x i8>)
-define <16 x i8> @min_u_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <16 x i8> @llvm.wasm.min.unsigned.v16i8(<16 x i8> %x, <16 x i8> %y)
-  ret <16 x i8> %a
-}
-
-; CHECK-LABEL: max_s_v16i8:
-; SIMD128-NEXT: .functype max_s_v16i8 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i8x16.max_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <16 x i8> @llvm.wasm.max.signed.v16i8(<16 x i8>, <16 x i8>)
-define <16 x i8> @max_s_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <16 x i8> @llvm.wasm.max.signed.v16i8(<16 x i8> %x, <16 x i8> %y)
-  ret <16 x i8> %a
-}
-
-; CHECK-LABEL: max_u_v16i8:
-; SIMD128-NEXT: .functype max_u_v16i8 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i8x16.max_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <16 x i8> @llvm.wasm.max.unsigned.v16i8(<16 x i8>, <16 x i8>)
-define <16 x i8> @max_u_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %a = call <16 x i8> @llvm.wasm.max.unsigned.v16i8(<16 x i8> %x, <16 x i8> %y)
-  ret <16 x i8> %a
-}
-
 ; CHECK-LABEL: any_v16i8:
 ; SIMD128-NEXT: .functype any_v16i8 (v128) -> (i32){{$}}
 ; SIMD128-NEXT: i8x16.any_true $push[[R:[0-9]+]]=, $0{{$}}
@@ -208,46 +168,6 @@
   ret <8 x i16> %a
 }
 
-; CHECK-LABEL: min_s_v8i16:
-; SIMD128-NEXT: .functype min_s_v8i16 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i16x8.min_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.min.signed.v8i16(<8 x i16>, <8 x i16>)
-define <8 x i16> @min_s_v8i16(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <8 x i16> @llvm.wasm.min.signed.v8i16(<8 x i16> %x, <8 x i16> %y)
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: min_u_v8i16:
-; SIMD128-NEXT: .functype min_u_v8i16 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i16x8.min_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.min.unsigned.v8i16(<8 x i16>, <8 x i16>)
-define <8 x i16> @min_u_v8i16(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <8 x i16> @llvm.wasm.min.unsigned.v8i16(<8 x i16> %x, <8 x i16> %y)
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: max_s_v8i16:
-; SIMD128-NEXT: .functype max_s_v8i16 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i16x8.max_s $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.max.signed.v8i16(<8 x i16>, <8 x i16>)
-define <8 x i16> @max_s_v8i16(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <8 x i16> @llvm.wasm.max.signed.v8i16(<8 x i16> %x, <8 x i16> %y)
-  ret <8 x i16> %a
-}
-
-; CHECK-LABEL: max_u_v8i16:
-; SIMD128-NEXT: .functype max_u_v8i16 (v128, v128) -> (v128){{$}}
-; SIMD128-NEXT: i16x8.max_u $push[[R:[0-9]+]]=, $0, $1{{$}}
-; SIMD128-NEXT: return $pop[[R]]{{$}}
-declare <8 x i16> @llvm.wasm.max.unsigned.v8i16(<8 x i16>, <8 x i16>)
-define <8 x i16> @max_u_v8i16(<8 x i16> %x, <8 x i16> %y) {
-  %a = call <8 x i16> @llvm.wasm.max.unsigned.v8i16(<8 x i16> %x, <8 x i16> %y)
-  ret <8 x i16> %a
-}
-
 ; CHECK-LABEL: any_v8i16:
 ; SIMD128-NEXT: 

[PATCH] D70048: [LLD] Add NetBSD support as a new flavor of LLD (nb.lld)

2019-12-13 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Stating it from a different side. If you do not care about GNU ld drop-in 
replacement property for Linux it's not our business, but we do care about this 
in NetBSD and we restrict this to our project only (from ELF targets).  If you 
do not care about NetBSD, you shall not care how and whether we use LLD. We try 
hard to not interfere with Linux looking for a consensus.

You are not forced to use the NetBSD driver neither define it in 
`LLD_SYMLINKS_TO_CREATE`. If you have a strong disrespect to this GNU ld 
drop-in replacement approach, I can patch the `die("")` invocation in `main()` 
to conditionally print `"nb.lld"`. There are around 20 lines patches in the 
generic code and around 1/3 of that is in the code comments. This shall not be 
burden for any of you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70048



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


[PATCH] D71499: Add builtins for aligning and checking alignment of pointers and integers

2019-12-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 60874 tests passed, 1 failed 
and 726 were skipped.

  failed: Clang.SemaCXX/builtin-align-cxx.cpp

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
console-log.txt 
,
 CMakeCache.txt 
,
 test-results.xml 
,
 diff.json 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71499



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


[PATCH] D69770: [APFloat] Add recoverable string parsing errors to APFloat

2019-12-13 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

If we really want to be confident that this is robust, we should probably 
fuzz-test it. Regardless, this seems like a definite improvement. LGTM.


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

https://reviews.llvm.org/D69770



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


[PATCH] D71499: Add builtins for aligning and checking alignment of pointers and integers

2019-12-13 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson created this revision.
arichardson added reviewers: rsmith, aaron.ballman, theraven, fhahn.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change introduces three new builtins (which work on both pointers
and integers) that can be used instead of common bitwise arithmetic:
__builtin_align_up(x, alignment), __builtin_align_down(x, alignment) and
__builtin_is_aligned(x, alignment).

I originally added these builtins to the CHERI fork of LLVM a few years ago
to handle the slightly different C semantics that we use for CHERI [1].
Until recently these builtins (or sequences of other builtins) were
required to generate correct code. I have since made changes to the default
C semantics so that they are no longer strictly necessary (but using them
does generate slightly more efficient code). However, based on our
experience using them in various projects over the past few years, I
believe that adding these builtins to clang would be useful.

These builtins have the following benefit over bit-manipulation and casts
via uintptr_t:

- The named builtins clearly convey the semantics of the operation. While 
checking alignment using __builtin_is_aligned(x, 16) versus ((x & 15) == 0) is 
probably not a huge win in readably, I personally find __builtin_align_up(x, N) 
a lot easier to read than (x+(N-1))&~(N-1).
- They preserve the type of the argument (including const qualifiers). When 
using casts via uintptr_t, it is easy to cast to the wrong type or strip 
qualifiers such as const.
- If the alignment argument is a constant value, clang can check that it is a 
power-of-two and within the range of the type. Since the semantics of these 
builtins is well defined compared to arbitraty bit-manipulation, it is possible 
to add a UBSAN checker that the run-time value is a valid power-of-two. I 
intend to add this as a follow-up to this change.
- The builtins avoids int-to-pointer casts both in C and LLVM IR. In this patch 
I use the new llvm.ptrmask intrinsic to avoid the inttoptr+ptrtoint 
instructions that would normally be generated.
- They can be used to round up/down to the next aligned value for both integers 
and pointers without requiring two separate macros.

[1] In our CHERI compiler we have compilation mode where all pointers are
implemented as capabilities (essentially unforgeable 128-bit fat pointers).
In our original model, casts from uintptr_t (which is a 128-bit capability)
to an integer value returned the "offset" of the capability (i.e. the
difference between the virtual address and the base of the allocation).
This causes problems for cases such as checking the alignment: for example,
the expression `if ((uintptr_t)ptr & 63) == 0` is generally used to check
if the pointer is aligned to a multiple of 64 bytes. The problem offsets is
that any pointer to the beginning of an allocation will have an offset of
zero, so this check always succeeds in that case (even if the address is
not correctly aligned). The same issues also exist when aligning up or
down. Using the alignment builtins ensures that the address is used instead
of the offset. While I have since changed the default C semantics to return
the address instead of the offset when casting, this offset compilation
mode can still be used by setting with command-line flag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71499

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-align-array.c
  clang/test/CodeGen/builtin-align.c
  clang/test/Sema/builtin-align.c
  clang/test/SemaCXX/builtin-align-cxx.cpp

Index: clang/test/SemaCXX/builtin-align-cxx.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-align-cxx.cpp
@@ -0,0 +1,99 @@
+// C++-specific checks for the alignment builtins
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -std=c++11 -o - %s -fsyntax-only -verify
+
+// Check that we don't crash when using dependent types in __builtin_align:
+template 
+void *c(void *d) { // expected-note{{candidate template ignored}}
+  return __builtin_align_down(d, b);
+}
+
+struct x {};
+x foo;
+void test(void *value) {
+  c(value);
+  c(value); // expected-error{{no matching function for call to 'c'}}
+}
+
+template
+void test_templated_arguments() {
+  T array[ArraySize]; // expected-error{{variable has incomplete type 'fwddecl'}}
+  static_assert(__is_same(decltype(__builtin_align_up(array, Alignment)), T*), // expected-error{{requested alignment is not a power of 2}}
+  "return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_align_down(array, Alignment)), T*),
+  "return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_is_aligned(array, 

[clang] 2a789dd - [OpenMP][Docs] Claim loop tiling.

2019-12-13 Thread Michael Kruse via cfe-commits

Author: Michael Kruse
Date: 2019-12-13T18:42:52-06:00
New Revision: 2a789dd0ad884cbd73b962b6b07cf48e2178d2c9

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

LOG: [OpenMP][Docs] Claim loop tiling.

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 7a70d05ec7ff..faeb831cf10c 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -250,3 +250,5 @@ want to help with the implementation.
 
+==+==+==+===+
 | misc extension   | user-defined function variants with #ifdef 
protection| :part:`worked on`| D71179   
 |
 
+--+--+--+---+
+| loop extension   | Loop tiling transformation
   | :part:`claimed`  | 
  |
++--+--+--+---+



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


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:444
 
+def warn_drv_experimental_fp_control_incomplete_opt : Warning<
+  "Support for floating point control option %0 is incomplete and 
experimental">,

rupprecht wrote:
> andrew.w.kaylor wrote:
> > rupprecht wrote:
> > > mibintc wrote:
> > > > @kpn thought it would be a good idea to add a Warning that the 
> > > > implementation of float control is experimental and partially 
> > > > implemented.  That's what this is for.
> > > Instead of adding a warning, I'd like to propose `-frounding-math` not be 
> > > enabled unless an additional flag (e.g. `-fexperimental-float-control`) 
> > > is passed. Or maybe this feature should be called 
> > > `-f[no-]experimental-rounding-math` instead.
> > > 
> > > There are plenty of builds that are already specifying `-frounding-math` 
> > > (e.g. they also support building w/ a compiler such as gcc that 
> > > implements this), and adding this experimental/incomplete implementation 
> > > is a surprise to those builds.
> > > 
> > > If I'm wrong and it's completely safe to ignore the warning (maybe it's 
> > > incomplete but not in any unsafe way), we should just not have it at all.
> > You raise an interesting point about people who might be using 
> > -frounding-math already. However, if they are using this flag because they 
> > also sometimes build with a compiler such as gcc that supports the flag, 
> > they are currently getting incorrect behavior from clang. Without this 
> > patch, clang silently ignores the option and the optimizer silently ignores 
> > the fact that the program may be changing the rounding mode dynamically. 
> > The user may or may not be aware of this.
> > 
> > With this patch such a user is likely to observe two effects: (1) their 
> > code will suddenly get slower, and (2) it will probably start behaving 
> > correctly with regard to rounding mode changes. The rounding behavior will 
> > definitely not get worse. I think the warning is useful as an indication 
> > that something has changed. I don't think requiring an additional option 
> > should be necessary.
> > However, if they are using this flag because they also sometimes build with 
> > a compiler such as gcc that supports the flag, they are currently getting 
> > incorrect behavior from clang
> 
> Incorrect, yes, but also likely valid behavior. "experimental" seems to imply 
> a miscompile when using this option should not be unexpected.
> 
> As I suggested before: if I'm wrong, and this behavior is only going to make 
> the code more correct (as you suggest), can we remove the warning that this 
> must be ack'd explicitly by adding `-Wno-experimental-float-control` to 
> builds? I don't understand the motivation for the warning.
The "experimental" code won't be incorrect in any way that the code generated 
when we ignore the option is. The things that have been implemented will work 
correctly. The things that are not implemented will have the potential to 
disregard runtime changes to the rounding mode. Currently, dynamic changes to 
the rounding mode always have the potential of being ignored.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[PATCH] D69876: Allow output constraints on "asm goto"

2019-12-13 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

Note to reviewers: I would *really* like to get this feature into the 10.0.0 
release. That's coming up in January. Do you think you'll have your reviews 
finished by then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69876



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


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added a comment.

In D62731#1784225 , @rjmccall wrote:

> ... The big problem is that intrinsic calls are not arbitrary code: the vast 
> majority of intrinsics (e.g. all the ARM vector intrinsics, many of which can 
> be floating-point) are marked `IntrNoMem` (which I believe corresponds to 
> `readnone`), which means calls to those intrinsics can be reordered with 
> other code whether or not that code has arbitrary side-effects.


Oh, you're right. With the constrained intrinsics we are currently handling 
that by using IntrInaccessibleMemOnly as a proxy for access to the FP 
environment, but that's stronger than we'd want for architecture-specific 
intrinsics in the default case. We have talked about an fpenv-specific 
attribute, but nothing has been done. So, I guess that does leave us in the 
situation where rounding controls might not be correctly respected if 
target-specific intrinsics are used.

> It's good that people are looking at achieving better modeling for the x86 
> backend, but we need to have a plan that doesn't require heroic effort just 
> to get basic correctness.

Do you mean in the backend? If so, I don't think that's possible. The backends 
just don't have any sort of feature that could be used to get conservatively 
correct behavior for cheap the way intrinsics give it to us in the middle end. 
Once you go into instruction selection things get very low level in a hurry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[PATCH] D71467: [FPEnv] Generate constrained FP comparisons from clang

2019-12-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D71467#1784338 , @craig.topper 
wrote:

> In D71467#1784286 , @rjmccall wrote:
>
> > The bug with `__builtin_isless` should be a really easy fix; the builtin 
> > just needs to be flagged as having custom type-checking, and then we need 
> > to make sure we do appropriate promotions on the arguments (but we probably 
> > do).
>
>
> I think I convinced @erichkeane to look at it on Monday.


Everything but fpclassify is pretty trivial, I just needed to write a test but 
needed to go home. I'll commit that Monday when I get to it. Fpclassify will 
take a touch longer since the int arguments need to be dealt with, but that 
shouldn't be more than a little work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71467



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


[PATCH] D71397: [clang] Improve LLVM-style RTTI support in ExternalASTSource/ExternalSemaSource

2019-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

If we decide as a community that D39111  is 
better, we can go back and adopt it at any point; I don't see that as a reason 
to reject modest refinements, especially given that there is no sign whatsoever 
of movement on D39111 .


Repository:
  rC Clang

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

https://reviews.llvm.org/D71397



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


[PATCH] D71167: [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D71167#1784272 , @efriedma wrote:

> If I'm understanding correctly, this does nothing without D71168 
> ?  And together with D71168 
> , the net change for clang is that 
> "-mno-omit-leaf-frame-pointer" works correctly, but everything else stays the 
> same?


Yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71167



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


[PATCH] D71467: [FPEnv] Generate constrained FP comparisons from clang

2019-12-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a subscriber: erichkeane.
craig.topper added a comment.

In D71467#1784286 , @rjmccall wrote:

> The bug with `__builtin_isless` should be a really easy fix; the builtin just 
> needs to be flagged as having custom type-checking, and then we need to make 
> sure we do appropriate promotions on the arguments (but we probably do).


I think I convinced @erichkeane to look at it on Monday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71467



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


[PATCH] D70048: [LLD] Add NetBSD support as a new flavor of LLD (nb.lld)

2019-12-13 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

@joerg works on the ELF loader and we just need to wait for him. We wrote our 
temporary patch, but it was not ideal as the long term solution.

compiler-rt is nicely maintained from our perspective and we have almost 
feature parity with Linux.

We maintain and develop around 4000 NetBSD specific LOC in LLDB. That number 
grows, especially with each CPU architecture gaining upstream support.

> it seems NetBSD just needs

This is not everything, but I don't want to derail yet another review into 
offtopic or generic discussion. Getting lld functional standalone is merely a 
starting point for us.

We need a linker that is a GNU ld drop-in replacement. As we have no interest 
in fixing it for Linux, we want this property for NetBSD.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70048



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


[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

2019-12-13 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Here is the fix:

  diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
  index e02c1c5..5ce81b0 100644
  --- a/clang/lib/Sema/SemaOpenMP.cpp
  +++ b/clang/lib/Sema/SemaOpenMP.cpp
  @@ -3830,6 +3830,9 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
 MarkDeclarationsReferencedInExpr(E);
   }
 }
  +  if (auto *LC = dyn_cast(Clause))
  +if (Expr *E = LC->getStep())
  +  MarkDeclarationsReferencedInExpr(E);
 DSAStack->setForceVarCapturing(/*V=*/false);
   } else if (CaptureRegions.size() > 1 ||
  CaptureRegions.back() != OMPD_unknown) {


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71475



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


[PATCH] D71397: [clang] Improve LLVM-style RTTI support in ExternalASTSource/ExternalSemaSource

2019-12-13 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor marked an inline comment as done.
teemperor added a comment.

In D71397#1782537 , @lhames wrote:

> Side note: This https://reviews.llvm.org/D39111 seems related. The patch has 
> languished as I have been busy with other work, but if it would be useful for 
> you guys I'd be happy to try to land it.


Moving ExternalASTSource to that system would also work, but that would add yet 
another dependency to D71398  (which is 
removing really gnarly code). But otherwise this seems like something we could 
use here (and also in LLDB).

I would prefer landing this as-is because it is just doing the same we do in 
other places in LLVM. Afterwards migrating the whole RTTI system in LLVM to a 
new system (whether that will be D39111  or 
just a ClassID type) sounds good to me.


Repository:
  rC Clang

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

https://reviews.llvm.org/D71397



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


[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

2019-12-13 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen marked an inline comment as done.
cchen added a comment.

In D71475#1784284 , @jdoerfert wrote:

> What is the output when you run the example with `k` in `lastprivate` or 
> `reduction`?


I actually got the same result (return value) changing from firstprivate to 
lastprivate. Not so sure how to make linear work with reduction.

> In D71475#1784173 , @cchen wrote:
> 
>> Doing this still fail the assertion since we still don't have the variable 
>> inside
>>  CapturedStmt.
> 
> 
> So we need to mark it as captured as well.

I've tried to use the `buildCapture` function before, but seems not work for 
me, can you point out where to look at in the source code? Thanks




Comment at: clang/lib/Sema/SemaOpenMP.cpp:4512
   }
 }
 int ClauseKindCnt = -1;

jdoerfert wrote:
> Is this "ErrorFound" here set when you run the example?
ErrorFound does not set. The firstprivate node is correctly set by checking 
ast-dump


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71475



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


[PATCH] D71493: [WebAssembly] Setting export_name implies no_dead_strip

2019-12-13 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 created this revision.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, aheejin, 
hiraditya, jgravelle-google, dschuff.
Herald added projects: clang, LLVM.
sbc100 added reviewers: dschuff, sunfish.

This change updates the clang front end to add symbols to llvm.used
when they have explicit export_name attribute.

In also causes the `.export_name` assempler directive to imply the
MCSA_NoDeadStrip symbol attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71493

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/wasm-export-name.c
  llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  llvm/test/MC/WebAssembly/export-name.s


Index: llvm/test/MC/WebAssembly/export-name.s
===
--- llvm/test/MC/WebAssembly/export-name.s
+++ llvm/test/MC/WebAssembly/export-name.s
@@ -22,5 +22,5 @@
 # CHECK-OBJ-NEXT:   - Index:   0
 # CHECK-OBJ-NEXT: Kind:FUNCTION
 # CHECK-OBJ-NEXT: Name:foo
-# CHECK-OBJ-NEXT: Flags:   [ EXPORTED ]
+# CHECK-OBJ-NEXT: Flags:   [ EXPORTED, NO_STRIP ]
 # CHECK-OBJ-NEXT: Function:0
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -722,6 +722,7 @@
   auto WasmSym = cast(Ctx.getOrCreateSymbol(SymName));
   WasmSym->setExportName(ExportName);
   TOut.emitExportName(WasmSym, ExportName);
+  Out.EmitSymbolAttribute(WasmSym, MCSA_NoDeadStrip);
 }
 
 if (DirectiveID.getString() == ".import_module") {
Index: clang/test/CodeGen/wasm-export-name.c
===
--- clang/test/CodeGen/wasm-export-name.c
+++ clang/test/CodeGen/wasm-export-name.c
@@ -6,6 +6,8 @@
   return 43;
 }
 
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo 
to i8*)]
+
 // CHECK: define i32 @foo() [[A:#[0-9]+]]
 
 // CHECK: attributes [[A]] = {{{.*}} "wasm-export-name"="bar" {{.*}}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5772,8 +5772,8 @@
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, ))
 return;
 
-  FD->addAttr(::new (S.Context)
-  WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(::new (S.Context) WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleWebAssemblyImportModuleAttr(Sema , Decl *D, const 
ParsedAttr ) {


Index: llvm/test/MC/WebAssembly/export-name.s
===
--- llvm/test/MC/WebAssembly/export-name.s
+++ llvm/test/MC/WebAssembly/export-name.s
@@ -22,5 +22,5 @@
 # CHECK-OBJ-NEXT:   - Index:   0
 # CHECK-OBJ-NEXT: Kind:FUNCTION
 # CHECK-OBJ-NEXT: Name:foo
-# CHECK-OBJ-NEXT: Flags:   [ EXPORTED ]
+# CHECK-OBJ-NEXT: Flags:   [ EXPORTED, NO_STRIP ]
 # CHECK-OBJ-NEXT: Function:0
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -722,6 +722,7 @@
   auto WasmSym = cast(Ctx.getOrCreateSymbol(SymName));
   WasmSym->setExportName(ExportName);
   TOut.emitExportName(WasmSym, ExportName);
+  Out.EmitSymbolAttribute(WasmSym, MCSA_NoDeadStrip);
 }
 
 if (DirectiveID.getString() == ".import_module") {
Index: clang/test/CodeGen/wasm-export-name.c
===
--- clang/test/CodeGen/wasm-export-name.c
+++ clang/test/CodeGen/wasm-export-name.c
@@ -6,6 +6,8 @@
   return 43;
 }
 
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)]
+
 // CHECK: define i32 @foo() [[A:#[0-9]+]]
 
 // CHECK: attributes [[A]] = {{{.*}} "wasm-export-name"="bar" {{.*}}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5772,8 +5772,8 @@
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, ))
 return;
 
-  FD->addAttr(::new (S.Context)
-  WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(::new (S.Context) WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleWebAssemblyImportModuleAttr(Sema , Decl *D, const ParsedAttr ) {

[PATCH] D71397: [clang] Improve LLVM-style RTTI support in ExternalASTSource/ExternalSemaSource

2019-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

If this is commonly used, it would make sense to introduce those types into 
some common header in LLVM.


Repository:
  rC Clang

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

https://reviews.llvm.org/D71397



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


[PATCH] D71201: [ObjC][DWARF] Emit DW_AT_APPLE_objc_direct for methods marked as __attribute__((objc_direct))

2019-12-13 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Thanks!

It would be nice to further manually reduce the IR testcase by stripping out 
any metadata that isn't needed. Otherwise this LGTM


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

https://reviews.llvm.org/D71201



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


[PATCH] D71397: [clang] Improve LLVM-style RTTI support in ExternalASTSource/ExternalSemaSource

2019-12-13 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/include/clang/AST/ExternalASTSource.h:69
 
-  /// Whether this AST source also provides information for
-  /// semantic analysis.
-  bool SemaSource = false;
+  // LLVM-style RTTI.
+  static char ID;

rjmccall wrote:
> aprantl wrote:
> > /// LLVM-style RTTI.
> It would be better if this had a dedicated type instead of using `char` and 
> then `void*` as the parameter, just to prevent simple bugs where somebody 
> passes in the wrong pointer.  Maybe you could have a non-copyable `ClassID` 
> type and a `ClassRef` type with the sole constructor `ClassRef(const ClassID 
> &)`?
> 
> The virtual method name is trying too hard to be succinct, and it doesn't 
> matter because it's rarely used; I would recommend borrowing the name 
> `isKindOf` from Objective-C.
This is a pattern that is used all over in LLDB. However, these are good 
suggestions, and we might want to make those improvements there as well.


Repository:
  rC Clang

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

https://reviews.llvm.org/D71397



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


[PATCH] D69732: [WIP][LTO] Apply SamplePGO pipeline tunes for ThinLTO pre-link to full LTO

2019-12-13 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

//Ping// @tejohnson


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69732



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


[PATCH] D71467: [FPEnv] Generate constrained FP comparisons from clang

2019-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The bug with `__builtin_isless` should be a really easy fix; the builtin just 
needs to be flagged as having custom type-checking, and then we need to make 
sure we do appropriate promotions on the arguments (but we probably do).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71467



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


[PATCH] D71167: [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

If I'm understanding correctly, this does nothing without D71168 
?  And together with D71168 
, the net change for clang is that 
"-mno-omit-leaf-frame-pointer" works correctly, but everything else stays the 
same?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71167



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


[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

2019-12-13 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

What is the output when you run the example with `k` in `lastprivate` or 
`reduction`?

In D71475#1784173 , @cchen wrote:

> Doing this still fail the assertion since we still don't have the variable 
> inside
>  CapturedStmt.


So we need to mark it as captured as well.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:4512
   }
 }
 int ClauseKindCnt = -1;

Is this "ErrorFound" here set when you run the example?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71475



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


[PATCH] D71491: [ubsan] Check implicit casts in ObjC for-in statements

2019-12-13 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.
vsk added reviewers: rjmccall, jfb, arphaman, delcypher.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

Check that the implicit cast from `id` used to construct the element
variable in an ObjC for-in statement is valid.

This check is included as part of a new `objc-cast` sanitizer, outside
of the main 'undefined' group, as (IIUC) the behavior it's checking for
is not technically UB.

The check can be extended to cover other kinds of invalid casts in ObjC.

Partially addresses: rdar://12903059, rdar://9542496


https://reviews.llvm.org/D71491

Files:
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/include/clang/Basic/Sanitizers.def
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/test/CodeGenObjC/for-in.m
  compiler-rt/lib/ubsan/ubsan_checks.inc
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.h
  compiler-rt/lib/ubsan/ubsan_value.cpp
  compiler-rt/lib/ubsan/ubsan_value.h
  compiler-rt/test/ubsan/TestCases/Misc/objc-cast.m

Index: compiler-rt/test/ubsan/TestCases/Misc/objc-cast.m
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/Misc/objc-cast.m
@@ -0,0 +1,18 @@
+// REQUIRES: darwin
+//
+// RUN: %clang -framework Foundation -fsanitize=objc-cast %s -O1 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+//
+// RUN: %clang -framework Foundation -fsanitize=objc-cast -fno-sanitize-recover=objc-cast %s -O1 -o %t.trap
+// RUN: not %run %t.trap 2>&1 | FileCheck %s
+
+#include 
+
+int main() {
+  NSArray *array = [NSArray arrayWithObjects: @1, @2, @3, (void *)0];
+  // CHECK: objc-cast.m:[[@LINE+1]]:{{.*}}: runtime error: invalid ObjC cast, object is a '__NSCFNumber', but expected a 'NSString'
+  for (NSString *str in array) {
+NSLog(@"%@", str);
+  }
+  return 0;
+}
Index: compiler-rt/lib/ubsan/ubsan_value.h
===
--- compiler-rt/lib/ubsan/ubsan_value.h
+++ compiler-rt/lib/ubsan/ubsan_value.h
@@ -135,6 +135,9 @@
 /// \brief An opaque handle to a value.
 typedef uptr ValueHandle;
 
+/// Returns the class name of the given ObjC object, or null if the name
+/// cannot be found.
+const char *getObjCClassName(ValueHandle Pointer);
 
 /// \brief Representation of an operand value provided by the instrumented code.
 ///
Index: compiler-rt/lib/ubsan/ubsan_value.cpp
===
--- compiler-rt/lib/ubsan/ubsan_value.cpp
+++ compiler-rt/lib/ubsan/ubsan_value.cpp
@@ -17,8 +17,46 @@
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
+#if defined(__APPLE__)
+#include 
+#endif
+
 using namespace __ubsan;
 
+typedef const char *(*ObjCGetClassNameTy)(void *);
+
+const char *__ubsan::getObjCClassName(ValueHandle Pointer) {
+#if defined(__APPLE__)
+  // We need to query the ObjC runtime for some information, but do not want
+  // to introduce a static dependency from the ubsan runtime onto ObjC. Try to
+  // grab a handle to the ObjC runtime used by the process.
+  static bool AttemptedDlopen = false;
+  static void *ObjCHandle = nullptr;
+  static void *ObjCObjectGetClassName = nullptr;
+
+  if (!AttemptedDlopen) {
+ObjCHandle = dlopen(
+"/usr/lib/libobjc.A.dylib",
+RTLD_LAZY /* Only bind symbols when used. */
+| RTLD_LOCAL  /* Only make symbols available via the handle. */
+| RTLD_NOLOAD /* Do not load the dylib, just grab a handle if the
+ image is already loaded. */
+| RTLD_FIRST /* Only search the image pointed-to by the handle. */);
+AttemptedDlopen = true;
+if (!ObjCHandle)
+  return nullptr;
+ObjCObjectGetClassName = dlsym(ObjCHandle, "object_getClassName");
+  }
+
+  if (!ObjCObjectGetClassName)
+return nullptr;
+
+  return ObjCGetClassNameTy(ObjCObjectGetClassName)((void *)Pointer);
+#else
+  return nullptr;
+#endif
+}
+
 SIntMax Value::getSIntValue() const {
   CHECK(getType().isSignedIntegerTy());
   if (isInlineInt()) {
Index: compiler-rt/lib/ubsan/ubsan_handlers.h
===
--- compiler-rt/lib/ubsan/ubsan_handlers.h
+++ compiler-rt/lib/ubsan/ubsan_handlers.h
@@ -168,6 +168,14 @@
 /// Handle a builtin called in an invalid way.
 RECOVERABLE(invalid_builtin, InvalidBuiltinData *Data)
 
+struct InvalidObjCCast {
+  SourceLocation Loc;
+  const TypeDescriptor 
+};
+
+/// Handle an invalid ObjC cast.
+RECOVERABLE(invalid_objc_cast, InvalidObjCCast *Data, ValueHandle Pointer)
+
 struct NonNullReturnData {
   SourceLocation AttrLoc;
 };
Index: compiler-rt/lib/ubsan/ubsan_handlers.cpp
===
--- compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ compiler-rt/lib/ubsan/ubsan_handlers.cpp

[PATCH] D71434: [Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe4fce659a759: [Driver] Use .init_array for all gcc 
installations and simplify Generic_ELF… (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D71434?vs=233721=233882#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71434

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/constructors.c


Index: clang/test/Driver/constructors.c
===
--- clang/test/Driver/constructors.c
+++ clang/test/Driver/constructors.c
@@ -34,7 +34,7 @@
 // RUN: -target i386-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
+// RUN:   | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
 //
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1   \
 // RUN: -fuse-init-array \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2782,23 +2782,7 @@
 void Generic_ELF::addClangTargetOptions(const ArgList ,
 ArgStringList ,
 Action::OffloadKind) const {
-  const Generic_GCC::GCCVersion  = GCCInstallation.getVersion();
-  bool UseInitArrayDefault =
-  getTriple().getArch() == llvm::Triple::aarch64 ||
-  getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().isOSFreeBSD() &&
-   getTriple().getOSMajorVersion() >= 12) ||
-  (getTriple().getOS() == llvm::Triple::Linux &&
-   ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
-getTriple().isAndroid())) ||
-  getTriple().getOS() == llvm::Triple::NaCl ||
-  (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
-   !getTriple().hasEnvironment()) ||
-  getTriple().getOS() == llvm::Triple::Solaris ||
-  getTriple().getArch() == llvm::Triple::riscv32 ||
-  getTriple().getArch() == llvm::Triple::riscv64;
-
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
-  options::OPT_fno_use_init_array, 
UseInitArrayDefault))
+  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fno-use-init-array");
 }
Index: clang/lib/Driver/ToolChains/FreeBSD.h
===
--- clang/lib/Driver/ToolChains/FreeBSD.h
+++ clang/lib/Driver/ToolChains/FreeBSD.h
@@ -76,6 +76,10 @@
   // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
   // FreeBSD defaults to standalone/full debug info.
   bool GetDefaultStandaloneDebug() const override { return true; }
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
 
 protected:
   Tool *buildAssembler() const override;
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -467,3 +467,12 @@
 Res |= SanitizerKind::Memory;
   return Res;
 }
+
+void FreeBSD::addClangTargetOptions(const ArgList ,
+ArgStringList ,
+Action::OffloadKind) const {
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array,
+  getTriple().getOSMajorVersion() >= 12))
+CC1Args.push_back("-fno-use-init-array");
+}
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -89,6 +89,10 @@
   to run at a lower frequency which can impact performance. This behavior can 
be
   changed by passing -mprefer-vector-width=512 on the command line.
 
+* clang now defaults to ``.init_array`` on Linux. It used to use ``.ctors`` if
+  the found gcc installation is older than 4.7.0. Add ``-fno-use-init-array`` 
to
+  get the old behavior (``.ctors``).
+
 New Compiler Flags
 --
 


Index: clang/test/Driver/constructors.c
===
--- clang/test/Driver/constructors.c
+++ clang/test/Driver/constructors.c
@@ -34,7 +34,7 @@
 // RUN: -target i386-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
+// RUN:   | FileCheck 

[clang] e4fce65 - [Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules

2019-12-13 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2019-12-13T14:06:51-08:00
New Revision: e4fce659a759ecdd59ceee750f1ff9b44f9de3f3

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

LOG: [Driver] Use .init_array for all gcc installations and simplify 
Generic_ELF -fno-use-init-array rules

D39317 made clang use .init_array when no gcc installations is found.
This change changes all gcc installations to use .init_array .

GCC 4.7 by default stopped providing .ctors/.dtors compatible crt files,
and stopped emitting .ctors for __attribute__((constructor)).
.init_array should always work.

FreeBSD rules are moved to FreeBSD.cpp to make Generic_ELF rules clean.

Reviewed By: rnk

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/FreeBSD.h
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/constructors.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37a8f30e0bc9..eee63c8e9239 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -89,6 +89,10 @@ Non-comprehensive list of changes in this release
   to run at a lower frequency which can impact performance. This behavior can 
be
   changed by passing -mprefer-vector-width=512 on the command line.
 
+* clang now defaults to ``.init_array`` on Linux. It used to use ``.ctors`` if
+  the found gcc installation is older than 4.7.0. Add ``-fno-use-init-array`` 
to
+  get the old behavior (``.ctors``).
+
 New Compiler Flags
 --
 

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 85e94fe018e6..c10d991845d1 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -467,3 +467,12 @@ SanitizerMask FreeBSD::getSupportedSanitizers() const {
 Res |= SanitizerKind::Memory;
   return Res;
 }
+
+void FreeBSD::addClangTargetOptions(const ArgList ,
+ArgStringList ,
+Action::OffloadKind) const {
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array,
+  getTriple().getOSMajorVersion() >= 12))
+CC1Args.push_back("-fno-use-init-array");
+}

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.h 
b/clang/lib/Driver/ToolChains/FreeBSD.h
index 53bc5265c9e2..84bdbfd9a312 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.h
+++ b/clang/lib/Driver/ToolChains/FreeBSD.h
@@ -76,6 +76,10 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
   // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
   // FreeBSD defaults to standalone/full debug info.
   bool GetDefaultStandaloneDebug() const override { return true; }
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
 
 protected:
   Tool *buildAssembler() const override;

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 0d950852bacf..250e924fb84c 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2782,23 +2782,7 @@ void Generic_ELF::anchor() {}
 void Generic_ELF::addClangTargetOptions(const ArgList ,
 ArgStringList ,
 Action::OffloadKind) const {
-  const Generic_GCC::GCCVersion  = GCCInstallation.getVersion();
-  bool UseInitArrayDefault =
-  getTriple().getArch() == llvm::Triple::aarch64 ||
-  getTriple().getArch() == llvm::Triple::aarch64_be ||
-  (getTriple().isOSFreeBSD() &&
-   getTriple().getOSMajorVersion() >= 12) ||
-  (getTriple().getOS() == llvm::Triple::Linux &&
-   ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
-getTriple().isAndroid())) ||
-  getTriple().getOS() == llvm::Triple::NaCl ||
-  (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
-   !getTriple().hasEnvironment()) ||
-  getTriple().getOS() == llvm::Triple::Solaris ||
-  getTriple().getArch() == llvm::Triple::riscv32 ||
-  getTriple().getArch() == llvm::Triple::riscv64;
-
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
-  options::OPT_fno_use_init_array, 
UseInitArrayDefault))
+  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fno-use-init-array");
 }

diff  --git a/clang/test/Driver/constructors.c 
b/clang/test/Driver/constructors.c
index bda421a84065..e5d453d1bed9 100644
--- 

[PATCH] D71433: [analyzer] CERT: POS34-C

2019-12-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thanks! This looks like a simple and efficient check. I have one overall 
suggestion.

Currently the check may warn on non-bugs of the following kind:

  void foo() {
char env[] = "NAME=value";
putenv(env);
doStuff();
putenv("NAME=anothervalue");
  }

I.e., it's obviously harmless if the local variable pointer is removed from the 
environment before it goes out of scope. Can we instead warn when the *last* 
`putenv()` on the execution path through the current stack frame is a local 
variable (that goes out of scope at the end of the stack frame)?

That'd allow the checker to be enabled by default, which will give a lot more 
users access to it. Otherwise we'll have to treat it as an opt-in check and 
users will only enable it when they know about it, which is much less 
usefulness.




Comment at: clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:27
+class PutenvWithAutoChecker : public Checker {
+  mutable std::unique_ptr BT;
+

The modern idiom is `BugType BT{this, "Bug kind", "Bug category"};` - and drop 
the lazy initialization as well.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:35-37
+  if (const IdentifierInfo *II = Call.getCalleeIdentifier())
+if (!II->isStr("putenv"))
+  return;

The modern idiom here is `CallDescription`.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:42-43
+  const Expr *ArgExpr = Call.getArgExpr(0);
+  const MemSpaceRegion *MSR =
+  ArgV.getAsRegion()->getBaseRegion()->getMemorySpace();
+

You can call `getMemorySpace()` directly on any region.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:45-52
+  if (const auto *DRE = dyn_cast(ArgExpr->IgnoreImpCasts()))
+if (const auto *VD = dyn_cast(DRE->getDecl()))
+  IsPossiblyAutoVar = isa(VD) && isa(MSR);
+
+  if (!IsPossiblyAutoVar &&
+  (isa(MSR) || isa(MSR) ||
+   isa(MSR) ||

Simply check whether the memory space is a stack memory space. This should be a 
one-liner.



Comment at: clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:58
+this, "'putenv' function should not be called with auto variables",
+categories::SecurityError));
+  ExplodedNode *N = C.generateErrorNode();

Charusso wrote:
> @NoQ, it is from your documentation. Would we prefer that or the 
> `registerChecker(CheckerManager &)` is the new way to construct the 
> `BugType`? I believe the latter is more appropriate.
Replied above^^



Comment at: clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:60
+  ExplodedNode *N = C.generateErrorNode();
+  auto Report = llvm::make_unique(*BT, BT->getName(), N);
+  C.emitReport(std::move(Report));

Charusso wrote:
> We would like to point out the allocation's site, where it comes from.
> We have two facilities to do so: `MallocBugVisitor` to track dynamic 
> allocation and `trackExpressionValue()` to track any kind of an expression.
> 
> You could find examples from my CERT-checker: D70411. The rough idea is that:
> ```lang=c
> // Track the argument.
> if (isa(MSR)) {
>   bugreporter::trackExpressionValue(C.getPredecessor(), ArgExpr, *Report);
> } else if (const SymbolRef Sym = ArgV.getAsSymbol()) { // It is a 
> `HeapSpaceRegion`
>   Report->addVisitor(allocation_state::getMallocBRVisitor(Sym));
> }
> ```
> ~ here you need to copy-paste the `getMallocBRVisitor()` from my review. 
> Sorry!
I'm not sure it's valid to use `C.getPredecessor()` for tracking; it might get 
you into trouble for the same reason that using `C.getPredecessor()` as error 
node will get you into trouble. Please use the error node itself instead.


Repository:
  rC Clang

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

https://reviews.llvm.org/D71433



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


[PATCH] D70048: [LLD] Add NetBSD support as a new flavor of LLD (nb.lld)

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D58892#1784119 , @mgorny wrote:

> In D58892#1783042 , @MaskRay wrote:
>
> > In D58892#1783029 , @mgorny wrote:
> >
> > > I know I'm late to the party but this change thoroughly destroyed NetBSD 
> > > support. The NetBSD loader doesn't support having more than two PT_LOAD 
> > > sections. `-z norosegment` helped with that so far but after this change 
> > > practically everything fails to run.
> >
> >
> > This seems to be a very serious limitation. I have difficult to understand 
> > how such limitation could exist at all, but I think this should be 
> > straightforward to fix.
>
>
> Yes, it is a serious limitation, and no, it's not straightforward to fix. The 
> loader has making a lot of assumptions, especially what PT_LOAD segments to 
> expect and in which order. I've previously made a patch that allowed third 
> segment but it was rejected as apparently 'not doing it the right way'. 
> Almost a year has passed, and I am entirely powerless to fix it.


@mgorny told me that NetBSD ld.so has a limitation that it can only handle 2 
PT_LOAD segments.

I think the NetBSD toolchain team's attitude toward certain ELF things should 
probably be made more flexible. For that particular PT_LOAD limitation issue 
(a.out heritage?), if @mgorny don't mind giving me a pointer, I'd like to help 
argue fixing the limitation.

> If 200 LOC for NetBSD is a show stopper, please see e.g. compiler-rt where we 
> maintain 2 orders of magnitude more NetBSD-only LOC.

I am not sure compiler-rt is a good example here. The "2 orders of magnitude 
more" OS specific things make compiler-rt difficult to maintain. Innovations 
can be easily constrained by the numerous OS specific customization. I am glad 
that lld hasn't entered that situation.

I feel that NetBSD's stubborn attitude is adding complexity to many other 
projects.

> I try to avoid forking LLD for downstream and this shall be appreciated.

If you can accept `DT_RUNPATH` and fix the PT_LOAD limitation, then it seems 
NetBSD just needs its own ld wrapper that adds -L, and probably -znognustack 
which saves you 56 bytes. I don't understand why such customization should 
still be upstreamed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70048



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


[PATCH] D71434: [Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules

2019-12-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm

shipit 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71434



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


Re: [PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Eric Christopher via cfe-commits
On Fri, Dec 13, 2019 at 1:18 PM Dávid Bolvanský via Phabricator <
revi...@reviews.llvm.org> wrote:

> xbolva00 added a comment.
>
> In D71486#1784079 , @sammccall
> wrote:
>
> > It should be possible to test this by adapting a test case from the
> original ed8dadb <
> https://reviews.llvm.org/rGed8dadb37c7e1a7f4889d868ac9b19bfe7762237>, but
> I'm not certain...
>

> This concern was not addressed/answered.


> The commit
> https://reviews.llvm.org/rG5623bd52acd34db2e9cfc11d1510407610a14db0
> claims that this was reviewed by rsmith, but I don't see rsmith's LGTM
> here..
>
>
Both of these were handled offline: Sam mentioned just getting something in
to stop the Werror breakage in #clang on Discord and Richard was looking
over my shoulder as I was fixing up the patch.

Apologies for not following up with an email to this effect.


>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D71486/new/
>
> https://reviews.llvm.org/D71486
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I believe your analysis on the second point is unfortunately missing half the 
problem.  Functions like `fesetround` will be treated as having arbitrary 
side-effects by default, which mean arbitrary code can't be reordered with 
calls to them.  It'd be good to model that more precisely — to flag that the 
*only* side-effect they have is changing the FP state — but that's not really 
the big problem; that's just enabling better optimization by e.g. allowing them 
to be reordered with non-FP code.  The big problem is that intrinsic calls are 
not arbitrary code: the vast majority of intrinsics (e.g. all the ARM vector 
intrinsics, many of which can be floating-point) are marked `IntrNoMem` (which 
I believe corresponds to `readnone`), which means calls to those intrinsics can 
be reordered with other code whether or not that code has arbitrary 
side-effects.  It's good that people are looking at achieving better modeling 
for the x86 backend, but we need to have a plan that doesn't require heroic 
effort just to get basic correctness.

I would suggest that we need a function/call attribute roughly on the level of 
`readonly` / `readnone`, maybe `readfponly`, that says that a function has no 
side-effects and no dependencies on anything *except* the FP state.  Basic 
queries like `Instruction::mayReadMemory()` that are supposed to be used 
generically in code-motion transforms would then return true for calls marked 
that way only if they're FP-constrained functions.  So outside of an 
FP-constrained function we'd preserve optimizability, and inside one we'd be 
appropriately conservative.  The generic backend could similarly just default 
to treating those intrinsic calls as having side-effects in FP-constrained 
functions, and there'd just be some way for a backend to opt out of that when 
it provides precise modeling of FP state.  It'd then be a fairly 
straightforward change to go through the target intrinsic tables and mark which 
ones have dependencies on FP state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[clang] 8035bb4 - [OPENMP]Fix skipping of functions body.

2019-12-13 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2019-12-13T16:51:46-05:00
New Revision: 8035bb4a6573f7d20f17044a68a1405691000525

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

LOG: [OPENMP]Fix skipping of functions body.

When parsing the code with OpenMP and the function's body must be
skipped, need to skip also OpenMP annotation tokens. Otherwise the
counters for braces/parens are unbalanced and parsing fails.

Added: 
clang/test/OpenMP/crash-skipped-bodies-template-inst.cpp

Modified: 
clang/include/clang/Parse/Parser.h
clang/include/clang/Parse/RAIIObjectsForParser.h
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Parse/Parser.cpp
clang/test/OpenMP/openmp_check.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index a1e7bbba9b8e..7d13a4b597c1 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -56,6 +56,7 @@ namespace clang {
 ///
 class Parser : public CodeCompletionHandler {
   friend class ColonProtectionRAIIObject;
+  friend class ParsingOpenMPDirectiveRAII;
   friend class InMessageExpressionRAIIObject;
   friend class PoisonSEHIdentifiersRAIIObject;
   friend class ObjCDeclContextSwitch;
@@ -215,6 +216,9 @@ class Parser : public CodeCompletionHandler {
   /// ColonProtectionRAIIObject RAII object.
   bool ColonIsSacred;
 
+  /// Parsing OpenMP directive mode.
+  bool OpenMPDirectiveParsing = false;
+
   /// When true, we are directly inside an Objective-C message
   /// send expression.
   ///

diff  --git a/clang/include/clang/Parse/RAIIObjectsForParser.h 
b/clang/include/clang/Parse/RAIIObjectsForParser.h
index 558106eb684d..fb092c050783 100644
--- a/clang/include/clang/Parse/RAIIObjectsForParser.h
+++ b/clang/include/clang/Parse/RAIIObjectsForParser.h
@@ -287,6 +287,25 @@ namespace clang {
 }
   };
 
+  /// Activates OpenMP parsing mode to preseve OpenMP specific annotation
+  /// tokens.
+  class ParsingOpenMPDirectiveRAII {
+Parser 
+bool OldVal;
+
+  public:
+ParsingOpenMPDirectiveRAII(Parser )
+: P(P), OldVal(P.OpenMPDirectiveParsing) {
+  P.OpenMPDirectiveParsing = true;
+}
+
+/// This can be used to restore the state early, before the dtor
+/// is run.
+void restore() { P.OpenMPDirectiveParsing = OldVal; }
+
+~ParsingOpenMPDirectiveRAII() { restore(); }
+  };
+
   /// RAII object that makes '>' behave either as an operator
   /// or as the closing angle bracket for a template argument list.
   class GreaterThanIsOperatorScope {

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 442d2ce0e0f5..9dbbcc08db86 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1332,6 +1332,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 AccessSpecifier , ParsedAttributesWithRange ,
 DeclSpec::TST TagType, Decl *Tag) {
   assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
+  ParsingOpenMPDirectiveRAII DirScope(*this);
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
 
   SourceLocation Loc = ConsumeAnnotationToken();
@@ -1667,6 +1668,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 StmtResult
 Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) 
{
   assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
+  ParsingOpenMPDirectiveRAII DirScope(*this);
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
   SmallVector Clauses;
   SmallVector, OMPC_unknown + 1>

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 2645f27e656f..ed4e6ff0fc53 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -278,6 +278,10 @@ bool Parser::SkipUntil(ArrayRef Toks, 
SkipUntilFlags Flags) {
 case tok::annot_pragma_openmp:
 case tok::annot_pragma_openmp_end:
   // Stop before an OpenMP pragma boundary.
+  if (OpenMPDirectiveParsing)
+return false;
+  ConsumeAnnotationToken();
+  break;
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:

diff  --git a/clang/test/OpenMP/crash-skipped-bodies-template-inst.cpp 
b/clang/test/OpenMP/crash-skipped-bodies-template-inst.cpp
new file mode 100644
index ..c7ba432d5090
--- /dev/null
+++ b/clang/test/OpenMP/crash-skipped-bodies-template-inst.cpp
@@ -0,0 +1,30 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:28:5 
-fopenmp %s -o - 2>&1 | FileCheck %s
+template 
+auto make_func() {
+  struct impl {
+impl* func() {
+  int x;
+  if (x = 10) {
+  #pragma omp parallel
+;
+  }
+  // Check that body of this function is actually 

[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

2019-12-13 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen updated this revision to Diff 233869.
cchen added a comment.

Remove debug code and some redundancy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71475

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/parallel_for_linear_codegen.cpp


Index: clang/test/OpenMP/parallel_for_linear_codegen.cpp
===
--- clang/test/OpenMP/parallel_for_linear_codegen.cpp
+++ clang/test/OpenMP/parallel_for_linear_codegen.cpp
@@ -28,6 +28,19 @@
 float f;
 char cnt;
 
+int a[100];
+
+int foo (int i, int k)
+{
+#pragma omp parallel for linear (i: k + 1)
+  for (int j = 16; j < 64; j++)
+  {
+a[i] = j;
+i += 4;
+  }
+  return i;
+}
+
 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
 // CHECK-DAG: [[F:@.+]] = global float 0.0
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4404,6 +4404,32 @@
   }
 }
 
+namespace {
+class LinearStepVarChecker : public StmtVisitor {
+  llvm::SmallVector ImplicitFirstprivate;
+public:
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+if (auto *VD = dyn_cast(E->getDecl())) {
+  ImplicitFirstprivate.push_back(cast(E));
+  return true;
+}
+return false;
+  }
+  bool VisitStmt(Stmt *S) {
+for (Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+  ArrayRef getImplicitFirstprivate() const {
+return ImplicitFirstprivate;
+  }
+
+  explicit LinearStepVarChecker() {}
+};
+} // namespace
+
 StmtResult Sema::ActOnOpenMPExecutableDirective(
 OpenMPDirectiveKind Kind, const DeclarationNameInfo ,
 OpenMPDirectiveKind CancelRegion, ArrayRef Clauses,
@@ -4460,6 +4486,17 @@
 for (Expr *E : IRC->taskgroup_descriptors())
   if (E)
 ImplicitFirstprivates.emplace_back(E);
+  } else if (auto *LC = dyn_cast(C)) {
+Expr *E = LC->getStep();
+if (E) {
+  LinearStepVarChecker LSVChecker;
+  LSVChecker.Visit(E);
+  ArrayRef LinearVars = LSVChecker.getImplicitFirstprivate();
+  ImplicitFirstprivates.insert(
+  ImplicitFirstprivates.end(),
+  std::make_move_iterator(LinearVars.begin()),
+  std::make_move_iterator(LinearVars.end()));
+}
   }
 }
 if (!ImplicitFirstprivates.empty()) {


Index: clang/test/OpenMP/parallel_for_linear_codegen.cpp
===
--- clang/test/OpenMP/parallel_for_linear_codegen.cpp
+++ clang/test/OpenMP/parallel_for_linear_codegen.cpp
@@ -28,6 +28,19 @@
 float f;
 char cnt;
 
+int a[100];
+
+int foo (int i, int k)
+{
+#pragma omp parallel for linear (i: k + 1)
+  for (int j = 16; j < 64; j++)
+  {
+a[i] = j;
+i += 4;
+  }
+  return i;
+}
+
 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
 // CHECK-DAG: [[F:@.+]] = global float 0.0
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4404,6 +4404,32 @@
   }
 }
 
+namespace {
+class LinearStepVarChecker : public StmtVisitor {
+  llvm::SmallVector ImplicitFirstprivate;
+public:
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+if (auto *VD = dyn_cast(E->getDecl())) {
+  ImplicitFirstprivate.push_back(cast(E));
+  return true;
+}
+return false;
+  }
+  bool VisitStmt(Stmt *S) {
+for (Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+  ArrayRef getImplicitFirstprivate() const {
+return ImplicitFirstprivate;
+  }
+
+  explicit LinearStepVarChecker() {}
+};
+} // namespace
+
 StmtResult Sema::ActOnOpenMPExecutableDirective(
 OpenMPDirectiveKind Kind, const DeclarationNameInfo ,
 OpenMPDirectiveKind CancelRegion, ArrayRef Clauses,
@@ -4460,6 +4486,17 @@
 for (Expr *E : IRC->taskgroup_descriptors())
   if (E)
 ImplicitFirstprivates.emplace_back(E);
+  } else if (auto *LC = dyn_cast(C)) {
+Expr *E = LC->getStep();
+if (E) {
+  LinearStepVarChecker LSVChecker;
+  LSVChecker.Visit(E);
+  ArrayRef LinearVars = LSVChecker.getImplicitFirstprivate();
+  ImplicitFirstprivates.insert(
+  ImplicitFirstprivates.end(),
+  std::make_move_iterator(LinearVars.begin()),
+  std::make_move_iterator(LinearVars.end()));
+}
   }
 }
 if (!ImplicitFirstprivates.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] f978ea4 - [clang][clang-scan-deps] Aggregate the full dependency information.

2019-12-13 Thread Michael Spencer via cfe-commits
On Thu, Dec 12, 2019 at 4:23 AM Nemanja Ivanovic 
wrote:

> Hi Michael,
> We are happy to help troubleshoot the issue this caused on our bot.
> Unfortunately, this bot is not one where we can give you access so we'll
> have to try and work together to debug this.
> Can you provide the link to the failing build so we can see which test
> case it was that caused the problem and we can start debugging from there?
>

Here's one of the failures:
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/21884

It looks like it failed on every ppc64 linux bot (both be and le), but no
other bots.

- Michael Spencer


>
> Nemanja Ivanovic
> LLVM PPC Backend Development
> IBM Toronto Lab
> Email: neman...@ca.ibm.com
> Phone: 905-413-3388
>
>
>
> - Original message -
> From: Michael Spencer 
> To: powerl...@ca.ibm.com
> Cc: cfe-commits@lists.llvm.org
> Subject: [EXTERNAL] Re: [clang] f978ea4 - [clang][clang-scan-deps]
> Aggregate the full dependency information.
> Date: Wed, Dec 11, 2019 7:34 PM
>
> On Wed, Dec 11, 2019 at 2:41 PM Michael Spencer via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>
> Author: Michael Spencer
> Date: 2019-12-11T14:40:51-08:00
> New Revision: f978ea498309adaebab8fbf1cd6e520e7e0e11f1
>
> URL:
> https://github.com/llvm/llvm-project/commit/f978ea498309adaebab8fbf1cd6e520e7e0e11f1
> DIFF:
> https://github.com/llvm/llvm-project/commit/f978ea498309adaebab8fbf1cd6e520e7e0e11f1.diff
>
> LOG: [clang][clang-scan-deps] Aggregate the full dependency information.
>
> Differential Revision: https://reviews.llvm.org/D70268
>
> Added:
>
>
> Modified:
> clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
> clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
> clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
> clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
> clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
> clang/test/ClangScanDeps/Inputs/modules_cdb.json
> clang/test/ClangScanDeps/modules-full.cpp
> clang/tools/clang-scan-deps/ClangScanDeps.cpp
>
>
>
> Looks like this broke clang-ppc64be-linux. Is there a good way to debug
> this? It's not failing anywhere else, and none of the code should care
> about endianness.
>
> I'll revert for now.
>
> - Michael Spencer
>
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71475: [WIP][OPENMP] Try to fix linear clause crash by emitting alloca for step

2019-12-13 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen updated this revision to Diff 233866.
cchen added a comment.

Add linear step var into Implicitfirstprivate

Doing this still fail the assertion since we still don't have the variable 
inside
CapturedStmt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71475

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/parallel_for_linear_codegen.cpp


Index: clang/test/OpenMP/parallel_for_linear_codegen.cpp
===
--- clang/test/OpenMP/parallel_for_linear_codegen.cpp
+++ clang/test/OpenMP/parallel_for_linear_codegen.cpp
@@ -28,6 +28,19 @@
 float f;
 char cnt;
 
+int a[100];
+
+int foo (int i, int k)
+{
+#pragma omp parallel for linear (i: k + 1)
+  for (int j = 16; j < 64; j++)
+  {
+a[i] = j;
+i += 4;
+  }
+  return i;
+}
+
 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
 // CHECK-DAG: [[F:@.+]] = global float 0.0
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4404,6 +4404,34 @@
   }
 }
 
+namespace {
+class LinearStepVarChecker : public StmtVisitor {
+  llvm::SmallVector ImplicitFirstprivate;
+public:
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+if (auto *VD = dyn_cast(E->getDecl())) {
+  llvm::errs() << "VisitDeclRefExpr: \n";
+  VD->dump();
+  ImplicitFirstprivate.push_back(cast(E));
+  return true;
+}
+return false;
+  }
+  bool VisitStmt(Stmt *S) {
+for (Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+  ArrayRef getImplicitFirstprivate() const {
+return ImplicitFirstprivate;
+  }
+
+  explicit LinearStepVarChecker() {}
+};
+} // namespace
+
 StmtResult Sema::ActOnOpenMPExecutableDirective(
 OpenMPDirectiveKind Kind, const DeclarationNameInfo ,
 OpenMPDirectiveKind CancelRegion, ArrayRef Clauses,
@@ -4460,6 +4488,17 @@
 for (Expr *E : IRC->taskgroup_descriptors())
   if (E)
 ImplicitFirstprivates.emplace_back(E);
+  } else if (auto *LC = dyn_cast(C)) {
+Expr *E = LC->getStep();
+if (E) {
+  LinearStepVarChecker LSVChecker;
+  LSVChecker.Visit(E);
+  ArrayRef LinearVars = LSVChecker.getImplicitFirstprivate();
+  ImplicitFirstprivates.insert(
+  ImplicitFirstprivates.end(),
+  std::make_move_iterator(LinearVars.begin()),
+  std::make_move_iterator(LinearVars.end()));
+}
   }
 }
 if (!ImplicitFirstprivates.empty()) {
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/Basic/PrettyStackTrace.h"
+#include 
 using namespace clang;
 using namespace CodeGen;
 using namespace llvm::omp;


Index: clang/test/OpenMP/parallel_for_linear_codegen.cpp
===
--- clang/test/OpenMP/parallel_for_linear_codegen.cpp
+++ clang/test/OpenMP/parallel_for_linear_codegen.cpp
@@ -28,6 +28,19 @@
 float f;
 char cnt;
 
+int a[100];
+
+int foo (int i, int k)
+{
+#pragma omp parallel for linear (i: k + 1)
+  for (int j = 16; j < 64; j++)
+  {
+a[i] = j;
+i += 4;
+  }
+  return i;
+}
+
 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
 // CHECK-DAG: [[F:@.+]] = global float 0.0
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4404,6 +4404,34 @@
   }
 }
 
+namespace {
+class LinearStepVarChecker : public StmtVisitor {
+  llvm::SmallVector ImplicitFirstprivate;
+public:
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+if (auto *VD = dyn_cast(E->getDecl())) {
+  llvm::errs() << "VisitDeclRefExpr: \n";
+  VD->dump();
+  ImplicitFirstprivate.push_back(cast(E));
+  return true;
+}
+return false;
+  }
+  bool VisitStmt(Stmt *S) {
+for (Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+  ArrayRef getImplicitFirstprivate() const {
+return ImplicitFirstprivate;
+  }
+
+  explicit LinearStepVarChecker() {}
+};
+} // namespace
+
 StmtResult Sema::ActOnOpenMPExecutableDirective(
 OpenMPDirectiveKind Kind, const DeclarationNameInfo ,
 OpenMPDirectiveKind CancelRegion, ArrayRef Clauses,
@@ -4460,6 +4488,17 @@
 for (Expr *E : IRC->taskgroup_descriptors())
   if (E)
 ImplicitFirstprivates.emplace_back(E);
+  } else if (auto *LC = dyn_cast(C)) 

[PATCH] D71167: [Driver] Default to -momit-leaf-frame-pointer for AArch64

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

(I got confused over the last weekend.)

@efriedma We still need this driver change, otherwise D71168 
 will cause a functional difference when 
neither -m(no-)omit-leaf-frame-pointer is specified.

https://godbolt.org/z/653p3q


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71167



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


[PATCH] D70919: [Hexagon] Avoid passing unsupported options to lld when -fuse-ld=lld is used

2019-12-13 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70919



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


[PATCH] D71082: Allow system header to provide their own implementation of some builtin

2019-12-13 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked an inline comment as done.
serge-sans-paille added inline comments.



Comment at: clang/lib/AST/Decl.cpp:3019
+if (SL.isValid())
+  return SM.isInSystemHeader(SL);
+  }

efriedma wrote:
> I'm a little concerned about this; we're subtly changing our generated code 
> based on the "system-headerness" of the definition.  We generally avoid 
> depending on this for anything other than warnings. It could lead to weird 
> results with preprocessed source, or if someone specifies their include paths 
> incorrectly.
With the extra check on builtin status, it may no longer be necessary, let me 
check that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71082



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


[PATCH] D70919: [Hexagon] Avoid passing unsupported options to lld when -fuse-ld=lld is used

2019-12-13 Thread Sid Manning via Phabricator via cfe-commits
sidneym updated this revision to Diff 233864.
sidneym added a comment.

OK, Yes Fuchsia is a good example.  Using that pattern


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70919

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-elf.c


Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -536,3 +536,25 @@
 // RUN:   | FileCheck -check-prefix=CHECK080 %s
 // CHECK080:  "-cc1"
 // CHECK080:  "-Wreturn-type"
+
+// 
-
+// Default, not passing -fuse-ld
+// 
-
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK081 %s
+// CHECK081:  "-march=hexagon"
+// CHECK081:  "-mcpu=hexagonv60"
+// 
-
+// Passing -fuse-ld=lld
+// 
-
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK082 %s
+// CHECK082-NOT:  "-march="
+// CHECK082-NOT:  "-mcpu="
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -209,7 +209,11 @@
   bool IncStartFiles = !Args.hasArg(options::OPT_nostartfiles);
   bool IncDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
   bool UseG0 = false;
+  const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
+  bool UseLLD = (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
+ llvm::sys::path::stem(Exec).equals_lower("ld.lld"));
   bool UseShared = IsShared && !IsStatic;
+  StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
 
   
//
   // Silence warnings for various options
@@ -232,9 +236,10 @@
   for (const auto  : HTC.ExtraOpts)
 CmdArgs.push_back(Opt.c_str());
 
-  CmdArgs.push_back("-march=hexagon");
-  StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
-  CmdArgs.push_back(Args.MakeArgString("-mcpu=hexagon" + CpuVer));
+  if (!UseLLD) {
+CmdArgs.push_back("-march=hexagon");
+CmdArgs.push_back(Args.MakeArgString("-mcpu=hexagon" + CpuVer));
+  }
 
   if (IsShared) {
 CmdArgs.push_back("-shared");


Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -536,3 +536,25 @@
 // RUN:   | FileCheck -check-prefix=CHECK080 %s
 // CHECK080:  "-cc1"
 // CHECK080:  "-Wreturn-type"
+
+// -
+// Default, not passing -fuse-ld
+// -
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK081 %s
+// CHECK081:  "-march=hexagon"
+// CHECK081:  "-mcpu=hexagonv60"
+// -
+// Passing -fuse-ld=lld
+// -
+// RUN: %clang -### -target hexagon-unknown-elf \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK082 %s
+// CHECK082-NOT:  "-march="
+// CHECK082-NOT:  "-mcpu="
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -209,7 +209,11 @@
   bool IncStartFiles = !Args.hasArg(options::OPT_nostartfiles);
   bool IncDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
   bool UseG0 = false;
+  const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
+  bool UseLLD = (llvm::sys::path::filename(Exec).equals_lower("ld.lld") ||
+ llvm::sys::path::stem(Exec).equals_lower("ld.lld"));
   bool UseShared = IsShared && !IsStatic;
+  StringRef CpuVer = 

[PATCH] D71400: [RFC] [MinGW] Implicitly add .exe suffix if not provided

2019-12-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 233863.
mstorsjo marked 2 inline comments as done.
mstorsjo added a comment.

Added a code comment, using `llvm::path::has_extension`, added testcases.


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

https://reviews.llvm.org/D71400

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/mingw-implicit-extension-cross.c
  clang/test/Driver/mingw-implicit-extension-windows.c


Index: clang/test/Driver/mingw-implicit-extension-windows.c
===
--- /dev/null
+++ clang/test/Driver/mingw-implicit-extension-windows.c
@@ -0,0 +1,14 @@
+// Test how an implicit .exe extension is added. If running the compiler
+// on windows, an implicit extension is added if none is provided in the
+// given name. (Therefore, this test is skipped when not running on windows.)
+
+// REQUIRES: system-windows
+
+// RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck 
%s --check-prefix=CHECK-OUTPUTNAME-EXE
+
+// RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname.exe 2>&1 | 
FileCheck %s --check-prefix=CHECK-OUTPUTNAME-EXE
+
+// RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname.q 2>&1 | 
FileCheck %s --check-prefix=CHECK-OUTPUTNAME-Q
+
+// CHECK-OUTPUTNAME-EXE: "-o" "outputname.exe"
+// CHECK-OUTPUTNAME-Q: "-o" "outputname.q"
Index: clang/test/Driver/mingw-implicit-extension-cross.c
===
--- /dev/null
+++ clang/test/Driver/mingw-implicit-extension-cross.c
@@ -0,0 +1,9 @@
+// Test how an implicit .exe extension is added. If not running the compiler
+// on windows, no implicit extension is added. (Therefore, this test is skipped
+// when running on windows.)
+
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck 
%s
+
+// CHECK: "-o" "outputname"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -160,7 +160,19 @@
   }
 
   CmdArgs.push_back("-o");
-  CmdArgs.push_back(Output.getFilename());
+  const char *OutputFile = Output.getFilename();
+  // GCC implicitly adds an .exe extension if it is given an output file name
+  // that lacks an extension. However, GCC only does this when actually
+  // running on windows, not when operating as a cross compiler. As some users
+  // have come to rely on this behaviour, try to replicate it.
+#ifdef _WIN32
+  if (!llvm::sys::path::has_extension(OutputFile))
+CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
+  else
+CmdArgs.push_back(OutputFile);
+#else
+  CmdArgs.push_back(OutputFile);
+#endif
 
   Args.AddAllArgs(CmdArgs, options::OPT_e);
   // FIXME: add -N, -n flags


Index: clang/test/Driver/mingw-implicit-extension-windows.c
===
--- /dev/null
+++ clang/test/Driver/mingw-implicit-extension-windows.c
@@ -0,0 +1,14 @@
+// Test how an implicit .exe extension is added. If running the compiler
+// on windows, an implicit extension is added if none is provided in the
+// given name. (Therefore, this test is skipped when not running on windows.)
+
+// REQUIRES: system-windows
+
+// RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUTNAME-EXE
+
+// RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname.exe 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUTNAME-EXE
+
+// RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname.q 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUTNAME-Q
+
+// CHECK-OUTPUTNAME-EXE: "-o" "outputname.exe"
+// CHECK-OUTPUTNAME-Q: "-o" "outputname.q"
Index: clang/test/Driver/mingw-implicit-extension-cross.c
===
--- /dev/null
+++ clang/test/Driver/mingw-implicit-extension-cross.c
@@ -0,0 +1,9 @@
+// Test how an implicit .exe extension is added. If not running the compiler
+// on windows, no implicit extension is added. (Therefore, this test is skipped
+// when running on windows.)
+
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck %s
+
+// CHECK: "-o" "outputname"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -160,7 +160,19 @@
   }
 
   CmdArgs.push_back("-o");
-  

[PATCH] D71431: Call objc_retainBlock before passing a block as a variadic argument

2019-12-13 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0a670614a36: Call objc_retainBlock before passing a block 
as a variadic argument (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D71431?vs=233851=233862#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71431

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenObjC/arc-blocks.m


Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@
   test20_callee(^{ (void)x; });
 }
 
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+  test21_callee(1, ^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@
   for (Expr *A : Args.slice(ArgIx)) {
 ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
 Invalid |= Arg.isInvalid();
+// Copy blocks to the heap.
+if (A->getType()->isBlockPointerType())
+  maybeExtendBlockObject(Arg);
 AllArgs.push_back(Arg.get());
   }
 }
Index: clang/docs/AutomaticReferenceCounting.rst
===
--- clang/docs/AutomaticReferenceCounting.rst
+++ clang/docs/AutomaticReferenceCounting.rst
@@ -1863,6 +1863,12 @@
 ``Block_copy``.  The optimizer may remove such copies when it sees that the
 result is used only as an argument to a call.
 
+When a block pointer type is converted to a non-block pointer type (such as
+``id``), ``Block_copy`` is called. This is necessary because a block allocated
+on the stack won't get copied to the heap when the non-block pointer escapes.
+A block pointer is implicitly converted to ``id`` when it is passed to a
+function as a variadic argument.
+
 .. _arc.misc.exceptions:
 
 Exceptions


Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@
   test20_callee(^{ (void)x; });
 }
 
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+  test21_callee(1, ^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@
   for (Expr *A : Args.slice(ArgIx)) {
 ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
 Invalid |= Arg.isInvalid();
+// Copy blocks to the heap.
+if (A->getType()->isBlockPointerType())
+  maybeExtendBlockObject(Arg);
 AllArgs.push_back(Arg.get());
   }
 }
Index: clang/docs/AutomaticReferenceCounting.rst
===
--- clang/docs/AutomaticReferenceCounting.rst
+++ clang/docs/AutomaticReferenceCounting.rst
@@ -1863,6 +1863,12 @@
 ``Block_copy``.  The optimizer may remove such copies when it sees that the
 result is used only as an argument to a call.
 
+When a block pointer type is converted to a non-block pointer type (such as
+``id``), ``Block_copy`` is called. This is necessary because a block allocated
+on the stack won't get copied to the heap when the non-block pointer escapes.
+A block pointer is implicitly converted to ``id`` when it is passed to a
+function as a variadic argument.
+
 .. _arc.misc.exceptions:
 
 Exceptions
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71463: Implement VectorType conditional operator GNU extension.

2019-12-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 233861.
erichkeane marked 2 inline comments as done.
erichkeane added a comment.

Rebase + @eli.friedman s comments.


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

https://reviews.llvm.org/D71463

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCXX/vector-conditional.cpp
  clang/test/Sema/vector-gcc-compat.cpp
  clang/test/SemaCXX/vector-conditional.cpp

Index: clang/test/SemaCXX/vector-conditional.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/vector-conditional.cpp
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++17
+// Note that this test depends on the size of long-long to be different from
+// int, so it specifies a triple.
+
+using FourShorts = short __attribute__((__vector_size__(8)));
+using TwoInts = int __attribute__((__vector_size__(8)));
+using TwoUInts = unsigned __attribute__((__vector_size__(8)));
+using FourInts = int __attribute__((__vector_size__(16)));
+using FourUInts = unsigned __attribute__((__vector_size__(16)));
+using TwoLongLong = long long __attribute__((__vector_size__(16)));
+using FourLongLong = long long __attribute__((__vector_size__(32)));
+using TwoFloats = float __attribute__((__vector_size__(8)));
+using FourFloats = float __attribute__((__vector_size__(16)));
+using TwoDoubles = double __attribute__((__vector_size__(16)));
+using FourDoubles = double __attribute__((__vector_size__(32)));
+
+FourShorts four_shorts;
+TwoInts two_ints;
+TwoUInts two_uints;
+FourInts four_ints;
+FourUInts four_uints;
+TwoLongLong two_ll;
+FourLongLong four_ll;
+TwoFloats two_floats;
+FourFloats four_floats;
+TwoDoubles two_doubles;
+FourDoubles four_doubles;
+
+enum E {};
+enum class SE {};
+E e;
+SE se;
+
+// Check the rules of the condition of the conditional operator.
+void Condition() {
+  // Only int types are allowed here, the rest should fail to convert to bool.
+  (void)(four_floats ? 1 : 1); // expected-error {{is not contextually convertible to 'bool'}}}
+  (void)(two_doubles ? 1 : 1); // expected-error {{is not contextually convertible to 'bool'}}}
+}
+
+// Check the rules of the LHS/RHS of the conditional operator.
+void Operands() {
+  (void)(four_ints ? four_ints : throw 1); // expected-error {{GNU vector conditional operand cannot be a throw expression}}
+  (void)(four_ints ? throw 1 : four_ints); // expected-error {{GNU vector conditional operand cannot be a throw expression}}
+  (void)(four_ints ?: throw 1);// expected-error {{GNU vector conditional operand cannot be a throw expression}}
+  (void)(four_ints ? (void)1 : four_ints); // expected-error {{GNU vector conditional operand cannot be void}}
+  (void)(four_ints ?: (void)1);// expected-error {{GNU vector conditional operand cannot be void}}
+
+  // Vector types must be the same element size as the condition.
+  (void)(four_ints ? two_ll : two_ll); // expected-error {{vector condition type 'FourInts' (vector of 4 'int' values) and result type 'TwoLongLong' (vector of 2 'long long' values) do not have the same number of elements}}
+  (void)(four_ints ? four_ll : four_ll);   // expected-error {{vector condition type 'FourInts' (vector of 4 'int' values) and result type 'FourLongLong' (vector of 4 'long long' values) do not have elements of the same size}}
+  (void)(four_ints ? two_doubles : two_doubles);   // expected-error {{vector condition type 'FourInts' (vector of 4 'int' values) and result type 'TwoDoubles' (vector of 2 'double' values) do not have the same number of elements}}
+  (void)(four_ints ? four_doubles : four_doubles); // expected-error {{vector condition type 'FourInts' (vector of 4 'int' values) and result type 'FourDoubles' (vector of 4 'double' values) do not have elements of the same size}}
+  (void)(four_ints ?: two_ints);   // expected-error {{vector operands to the vector conditional must be the same type ('FourInts' (vector of 4 'int' values) and 'TwoInts' (vector of 2 'int' values)}}
+  (void)(four_ints ?: four_doubles);   // expected-error {{vector operands to the vector conditional must be the same type ('FourInts' (vector of 4 'int' values) and 'FourDoubles' (vector of 4 'double' values)}}
+
+  // Scalars are promoted, but must be the same element size.
+  (void)(four_ints ? 3.0f : 3.0); // expected-error {{vector condition type 'FourInts' (vector of 4 'int' values) and result type '__attribute__((__vector_size__(4 * sizeof(double double' (vector of 4 'double' values) do not have elements of the same size}}
+  (void)(four_ints ? 5ll : 5);// expected-error {{vector condition type 

[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D71486#1784079 , @sammccall wrote:

> It should be possible to test this by adapting a test case from the original 
> ed8dadb 
> , but 
> I'm not certain...


This concern was not addressed/answered.

The commit https://reviews.llvm.org/rG5623bd52acd34db2e9cfc11d1510407610a14db0 
claims that this was reviewed by rsmith, but I don't see rsmith's LGTM here..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486



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


[PATCH] D71463: Implement VectorType conditional operator GNU extension.

2019-12-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 5 inline comments as done.
erichkeane added a comment.

In D71463#1783953 , @efriedma wrote:

> Can you update 
> https://clang.llvm.org/docs/LanguageExtensions.html#langext-vectors with a 
> description of the interaction between the different language features here?


Done, see the next patch.

> It's unfortunate that the gcc extension is explicitly incompatible with 
> OpenCL, but I guess we're stuck with it.

I think it is the other way around actually.  The GCC extension predates the 
OpenCL one from what I can tell.




Comment at: clang/include/clang/AST/Expr.h:3738
+// implementation of this that the standard implies that this
+// could be true in the C++ standard as well.
+(cond->isTypeDependent() || lhs->isTypeDependent() ||

efriedma wrote:
> You can just refer to [temp.dep.expr] here; the type does in fact "depend" on 
> the type of the condition.  I'm a little concerned that the C++ standard 
> might not preserve this guarantee in the future.
I wasn't able to find a bug report in the core issues list, and this has been 
known about by Doug for ~15 years now.  I'm somewhat less concerned, 
particularly since GCC has this issue as well.



Comment at: clang/lib/Sema/SemaExpr.cpp:8981
+else
+  return true;
   } else if (VectorEltTy->isRealFloatingType()) {

efriedma wrote:
> Can you separate this out into an independent patch?
348f22eac83d9a3ee946e41be43fe507f04a89b6



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5826
+else
+  ResultElementTy = UsualArithmeticConversions(LHS, RHS);
+

efriedma wrote:
> I'm not completely sure this works the way you want it to... in particular, 
> if the types don't match, and both operands can be promoted to int, you end 
> up with an int vector.
I think I'm OK with that... GCC does allow some promotions here (a short and a 
ushort act as an int).  I tried a bunch of cases and couldn't come up with a 
case where this didn't work in the 2 scalar versions.  You wouldn't happen to 
have something in mind, would you?


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

https://reviews.llvm.org/D71463



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


[clang] a0a6706 - Call objc_retainBlock before passing a block as a variadic argument

2019-12-13 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2019-12-13T13:10:07-08:00
New Revision: a0a670614a36f1686c5086033bef85800128cf66

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

LOG: Call objc_retainBlock before passing a block as a variadic argument

Copy the block to the heap before passing it to the callee in case the
block escapes in the callee.

rdar://problem/55683462

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

Added: 


Modified: 
clang/docs/AutomaticReferenceCounting.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenObjC/arc-blocks.m

Removed: 




diff  --git a/clang/docs/AutomaticReferenceCounting.rst 
b/clang/docs/AutomaticReferenceCounting.rst
index 9e4456085b6e..9d61f58ed4d1 100644
--- a/clang/docs/AutomaticReferenceCounting.rst
+++ b/clang/docs/AutomaticReferenceCounting.rst
@@ -1863,6 +1863,12 @@ call for retaining a value of block-pointer type, it has 
the effect of a
 ``Block_copy``.  The optimizer may remove such copies when it sees that the
 result is used only as an argument to a call.
 
+When a block pointer type is converted to a non-block pointer type (such as
+``id``), ``Block_copy`` is called. This is necessary because a block allocated
+on the stack won't get copied to the heap when the non-block pointer escapes.
+A block pointer is implicitly converted to ``id`` when it is passed to a
+function as a variadic argument.
+
 .. _arc.misc.exceptions:
 
 Exceptions

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 620ec30b1285..36eef4f425e5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, 
FunctionDecl *FDecl,
   for (Expr *A : Args.slice(ArgIx)) {
 ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
 Invalid |= Arg.isInvalid();
+// Copy blocks to the heap.
+if (A->getType()->isBlockPointerType())
+  maybeExtendBlockObject(Arg);
 AllArgs.push_back(Arg.get());
   }
 }

diff  --git a/clang/test/CodeGenObjC/arc-blocks.m 
b/clang/test/CodeGenObjC/arc-blocks.m
index cabe552ba85c..85c22a1b9564 100644
--- a/clang/test/CodeGenObjC/arc-blocks.m
+++ b/clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@ void test20(const id x) {
   test20_callee(^{ (void)x; });
 }
 
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+  test21_callee(1, ^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }



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


[PATCH] D62731: Add support for options -frounding-math, -ftrapping-math, -ffp-model=, and -ffp-exception-behavior=, : Specify floating point behavior

2019-12-13 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added a comment.

In D62731#1782912 , @rjmccall wrote:

> Hmm.  The target-specific intrinsics thing does concern me, since I assume 
> many targets have a bunch of vector intrinsics that may be sensitive to 
> rounding.  Do we have an idea of how we'd fix that?  If it's a short-term 
> incorrectness that we have a plan to fix, I don't mind the risk, but if we 
> don't know how we'd even start to address it...


I see two potential problem cases with the target-specific intrinsics:

1. Some optimization pass recognizes the intrinisic and uses its semantics to 
perform some optimization such as constant folding
2. Some optimization performs code motion that moves the intrinsic (or, in the 
backend, the instruction it represents) across an operation that changes the 
rounding mode

I don't know if there are any instances of the first case in the public 
repository. Downstream users could be doing it. Those will need special 
handling if they exist (checking for the the strictfp attribute).

The second case should be handled in IR by fesetround() or other such 
intrinsics being marked as having side effects. It's possible that there are 
target-specific intrinsics to change the rounding mode that aren't marked as 
having side effects, but if so that's simply a bug. The other part of this is 
that the intrinsic might be lowered to MC and the MC instructions in a way that 
neglects rounding mode. Many targets have instructions with forms that take an 
explicit rounding mode argument and the backends may be using that with the 
default rounding mode. I am not aware of any such case, but it's definitely 
possible.

Finally, our design for handling strict fp mode in the backends is that 
rounding mode control will be handled by explicitly modeling the dependency 
between the relevant control registers and instructions that implicitly use the 
rounding mode controled by those registers. X86 only recently started doing 
this. There may be other backends that have not implemented it. Some may never 
do so.

I don't have a strong preference about what to do with the warning. I have a 
slight preference for replacing the existing warning with a more specific 
warning saying that floating math support is a work in progress. Eventually we 
need a way for backends to indicate that they believe their support is complete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62731



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


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
console-log.txt 
,
 diff.json 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486



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


[PATCH] D71431: Call objc_retainBlock before passing a block as a variadic argument

2019-12-13 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: clang/docs/AutomaticReferenceCounting.rst:1866
 
+When a block pointer type is converted to type ``id``, ``Block_copy`` is 
called.
+This is necessary because a block allocated on the stack won't get copied to 
the

rjmccall wrote:
> "to a non-block pointer type (such as ``id``)", please.  Otherwise looks 
> good.  I didn't realize that this conversion behavior wasn't documented at 
> all, so thank you for adding it.
I thought it was documented too and searched for it, but couldn't find it 
anywhere in the ARC doc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71431



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


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Eric Christopher via Phabricator via cfe-commits
echristo updated this revision to Diff 233857.
echristo added a comment.

Fix for some slightly better API uses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,9 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << static_cast(Info.getRawArg(Index));
+  break;
 }
   }
 }


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,9 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << static_cast(Info.getRawArg(Index));
+  break;
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Eric Christopher via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5623bd52acd3: Fix -Wswitch-coverage warning in clang-tidy 
after ak_addrspace introduction. (authored by echristo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,9 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << static_cast(Info.getRawArg(Index));
+  break;
 }
   }
 }


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,9 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << static_cast(Info.getRawArg(Index));
+  break;
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 5623bd5 - Fix -Wswitch-coverage warning in clang-tidy after ak_addrspace introduction.

2019-12-13 Thread Eric Christopher via cfe-commits

Author: Eric Christopher
Date: 2019-12-13T12:57:48-08:00
New Revision: 5623bd52acd34db2e9cfc11d1510407610a14db0

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

LOG: Fix -Wswitch-coverage warning in clang-tidy after ak_addrspace 
introduction.

Differential Revision: https://reviews.llvm.org/D71486
Reviewed By: rsmith

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index a349789a64d1..a5b6834316f4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,9 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const 
Diagnostic ) {
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << static_cast(Info.getRawArg(Index));
+  break;
 }
   }
 }



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


[PATCH] D71431: Call objc_retainBlock before passing a block as a variadic argument

2019-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/docs/AutomaticReferenceCounting.rst:1866
 
+When a block pointer type is converted to type ``id``, ``Block_copy`` is 
called.
+This is necessary because a block allocated on the stack won't get copied to 
the

"to a non-block pointer type (such as ``id``)", please.  Otherwise looks good.  
I didn't realize that this conversion behavior wasn't documented at all, so 
thank you for adding it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71431



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


[PATCH] D71431: Call objc_retainBlock before passing a block as a variadic argument

2019-12-13 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 233851.
ahatanak added a comment.

Explain why this change is needed in ARC documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71431

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenObjC/arc-blocks.m


Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@
   test20_callee(^{ (void)x; });
 }
 
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+  test21_callee(1, ^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@
   for (Expr *A : Args.slice(ArgIx)) {
 ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
 Invalid |= Arg.isInvalid();
+// Copy blocks to the heap.
+if (A->getType()->isBlockPointerType())
+  maybeExtendBlockObject(Arg);
 AllArgs.push_back(Arg.get());
   }
 }
Index: clang/docs/AutomaticReferenceCounting.rst
===
--- clang/docs/AutomaticReferenceCounting.rst
+++ clang/docs/AutomaticReferenceCounting.rst
@@ -1863,6 +1863,12 @@
 ``Block_copy``.  The optimizer may remove such copies when it sees that the
 result is used only as an argument to a call.
 
+When a block pointer type is converted to type ``id``, ``Block_copy`` is 
called.
+This is necessary because a block allocated on the stack won't get copied to 
the
+heap when the pointer converted to ``id`` escapes. The conversion to ``id``
+implicitly takes place when a block is passed to a function as a variadic
+argument.
+
 .. _arc.misc.exceptions:
 
 Exceptions


Index: clang/test/CodeGenObjC/arc-blocks.m
===
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@
   test20_callee(^{ (void)x; });
 }
 
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+  test21_callee(1, ^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@
   for (Expr *A : Args.slice(ArgIx)) {
 ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
 Invalid |= Arg.isInvalid();
+// Copy blocks to the heap.
+if (A->getType()->isBlockPointerType())
+  maybeExtendBlockObject(Arg);
 AllArgs.push_back(Arg.get());
   }
 }
Index: clang/docs/AutomaticReferenceCounting.rst
===
--- clang/docs/AutomaticReferenceCounting.rst
+++ clang/docs/AutomaticReferenceCounting.rst
@@ -1863,6 +1863,12 @@
 ``Block_copy``.  The optimizer may remove such copies when it sees that the
 result is used only as an argument to a call.
 
+When a block pointer type is converted to type ``id``, ``Block_copy`` is called.
+This is necessary because a block allocated on the stack won't get copied to the
+heap when the pointer converted to ``id`` escapes. The conversion to ``id``
+implicitly takes place when a block is passed to a function as a variadic
+argument.
+
 .. _arc.misc.exceptions:
 
 Exceptions
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 60867 tests passed, 0 failed 
and 726 were skipped.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
console-log.txt 
,
 CMakeCache.txt 
,
 test-results.xml 
,
 diff.json 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486



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


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

It should be possible to test this by adapting a test case from the original 
ed8dadb , 
but I'm not certain...




Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:525
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << Qualifiers::getAddrSpaceAsString(
+  *reinterpret_cast(Info.getRawArg(Index)));

Not very familiar with this code, but it looks like this is feeding the arg 
back into a builder, and ed8dadb added support for sending LangAS itself to the 
builder.

So I don't think we should stringify it, but just send the LangAS



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:526
+  Builder << Qualifiers::getAddrSpaceAsString(
+  *reinterpret_cast(Info.getRawArg(Index)));
+  break;

I think the stored thing is a LangAS (an enum), rather than a pointer to one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71486



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


[clang] 348f22e - Correct gcc vector splat conversion from float to int-vector

2019-12-13 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2019-12-13T12:27:31-08:00
New Revision: 348f22eac83d9a3ee946e41be43fe507f04a89b6

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

LOG: Correct gcc vector splat conversion from float to int-vector

In looking into some other code, I came across this issue where a
float converted to a gcc integer vector via a splat causes it to miss
the float-to-integral cast, which causes some REALLY strange codegen
bugs.

The AST looked like:
`-ImplicitCastExpr 
'gcc_int_2':'__attribute__((__vector_size__(2 * sizeof(int int' 

`-ImplicitCastExpr  'float' 
  `-DeclRefExpr  'float' lvalue ParmVar
  0x556f16a5dc90 'f' 'float'

Despite the type of the VectorSplat cast as printed, it ended up
becoming a vector of float, which caused non-matching instructions. For
example, IntVector + a float constant resulted in:

add <2 x i32> %8, <2 x float> 

This patch corrects the conversion so that the float is first converted
to an integral, THEN splatted.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCXX/vector-splat-conversion.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a941d524b7f2..620ec30b1285 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8973,6 +8973,12 @@ static bool tryGCCVectorConvertAndSplat(Sema , 
ExprResult *Scalar,
   return true;
 
 ScalarCast = CK_IntegralCast;
+  } else if (VectorEltTy->isIntegralType(S.Context) &&
+ ScalarTy->isRealFloatingType()) {
+if (S.Context.getTypeSize(VectorEltTy) == S.Context.getTypeSize(ScalarTy))
+  ScalarCast = CK_FloatingToIntegral;
+else
+  return true;
   } else if (VectorEltTy->isRealFloatingType()) {
 if (ScalarTy->isRealFloatingType()) {
 

diff  --git a/clang/test/CodeGenCXX/vector-splat-conversion.cpp 
b/clang/test/CodeGenCXX/vector-splat-conversion.cpp
index 805f9f5bab15..618ad76ce691 100644
--- a/clang/test/CodeGenCXX/vector-splat-conversion.cpp
+++ b/clang/test/CodeGenCXX/vector-splat-conversion.cpp
@@ -49,3 +49,14 @@ void BoolConversion() {
   // CHECK: store <4 x i128> zeroinitializer
   constexpr bigint4 cBigintsF = (bigint4)false;
 }
+
+typedef __attribute__((vector_size(8))) int gcc_int_2;
+gcc_int_2 FloatToIntConversion(gcc_int_2 Int2, float f) {
+  return Int2 + f;
+  // CHECK: %[[LOAD_INT:.+]] = load <2 x i32>
+  // CHECK: %[[LOAD:.+]] = load float, float*
+  // CHECK: %[[CONV:.+]] = fptosi float %[[LOAD]] to i32
+  // CHECK: %[[INSERT:.+]] = insertelement <2 x i32> undef, i32 %[[CONV]], i32 0
+  // CHECK: %[[SPLAT:.+]] = shufflevector <2 x i32> %[[INSERT]], <2 x i32> 
undef, <2 x i32> zeroinitializer
+  // CHECK: add <2 x i32> %[[LOAD_INT]], %[[SPLAT]]
+}



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


[PATCH] D71486: [clang-tools-extra] Fix switch coverage warning

2019-12-13 Thread Eric Christopher via Phabricator via cfe-commits
echristo created this revision.
echristo added reviewers: Anastasia, sammccall.
echristo added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, mcrosier.
Herald added a project: clang.
echristo added a subscriber: rdhindsa.

... I think this is right?

Add support in the switch statement for addr spaces. I couldn't get a magical 
API combination to get just the address space off the top of my head, but 
wanted to get this out.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71486

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,10 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << Qualifiers::getAddrSpaceAsString(
+  *reinterpret_cast(Info.getRawArg(Index)));
+  break;
 }
   }
 }


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -521,6 +521,10 @@
 case clang::DiagnosticsEngine::ak_attr:
   Builder << reinterpret_cast(Info.getRawArg(Index));
   break;
+case clang::DiagnosticsEngine::ak_addrspace:
+  Builder << Qualifiers::getAddrSpaceAsString(
+  *reinterpret_cast(Info.getRawArg(Index)));
+  break;
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71026: Fix LLVM_ENABLE_MODULES=ON + BUILD_SHARED_LIBS=ON build

2019-12-13 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

In D71026#1769340 , @arphaman wrote:

> Is the `Tooling/Transformer` library used by clang-format? The problem might 
> be solved if the `Tooling/Transformer` library was its own module (just like 
> Clang_ToolingInclusions).


I just tried to create a separate module again. I managed to fix the recursive 
dep error. However, it still doesn't fix the linker error. There is certainly a 
better solution than this, but this is all I can come up with since I don't 
really understand the semantics of modules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71026



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


[PATCH] D71485: [profile] Fix a crash when -fprofile-remapping-file= triggers an error

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG193da743db63: [profile] Fix a crash when 
-fprofile-remapping-file= triggers an error (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71485

Files:
  clang/test/CodeGenCXX/Inputs/profile-remap-error.map
  clang/test/CodeGenCXX/profile-remap-error.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap-error.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 
'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create 
remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: 
Malformed sample profile data
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu -fprofile-sample-use=%S/Inputs/profile-remap.samples -fprofile-remapping-file=%S/Inputs/profile-remap-error.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: Malformed sample profile data
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71485: [profile] Fix a crash when -fprofile-remapping-file= triggers an error

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 233843.
MaskRay added a comment.

Delete unused declaration


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71485

Files:
  clang/test/CodeGenCXX/Inputs/profile-remap-error.map
  clang/test/CodeGenCXX/profile-remap-error.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap-error.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 
'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create 
remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: 
Malformed sample profile data
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu -fprofile-sample-use=%S/Inputs/profile-remap.samples -fprofile-remapping-file=%S/Inputs/profile-remap-error.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: Malformed sample profile data
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 193da74 - [profile] Fix a crash when -fprofile-remapping-file= triggers an error

2019-12-13 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2019-12-13T11:38:20-08:00
New Revision: 193da743db63bc7299717f583a63e68d55408731

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

LOG: [profile] Fix a crash when -fprofile-remapping-file= triggers an error

Reviewed By: wmi

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

Added: 
clang/test/CodeGenCXX/Inputs/profile-remap-error.map
clang/test/CodeGenCXX/profile-remap-error.cpp

Modified: 
llvm/lib/Transforms/IPO/SampleProfile.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/Inputs/profile-remap-error.map 
b/clang/test/CodeGenCXX/Inputs/profile-remap-error.map
new file mode 100644
index ..feb6ce75a5d4
--- /dev/null
+++ b/clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored

diff  --git a/clang/test/CodeGenCXX/profile-remap-error.cpp 
b/clang/test/CodeGenCXX/profile-remap-error.cpp
new file mode 100644
index ..0a04e85a20af
--- /dev/null
+++ b/clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap-error.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 
'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create 
remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: 
Malformed sample profile data

diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp 
b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 2b169638d409..a1fbb1adc412 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@ PreservedAnalyses SampleProfileLoaderPass::run(Module ,
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);



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


[PATCH] D67923: [TLI] Support for per-Function TLI that overrides available libfuncs

2019-12-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Please take a look. This is now updated to reflect the commit of D71193 
, which translated the options to the new 
attributes. I also removed some comments that I realized didn't make sense, as 
we need to keep a baseline availability array on the base TLII since that is 
set based on the architecture. We simply override this for no-builtin* 
attributes on the function. I removed the code from clang that was setting up 
the availability array based on the options, and all tests pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67923



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


[PATCH] D67923: [TLI] Support for per-Function TLI that overrides available libfuncs

2019-12-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 233841.
tejohnson added a comment.
Herald added subscribers: cfe-commits, hiraditya.
Herald added a project: clang.

Update after D71193  committed, converting 
-fno-builtin* options to attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67923

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp

Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1588,22 +1588,12 @@
   return I->ScalarFnName;
 }
 
-TargetLibraryInfo TargetLibraryAnalysis::run(Function ,
+TargetLibraryInfo TargetLibraryAnalysis::run(const Function ,
  FunctionAnalysisManager &) {
-  if (PresetInfoImpl)
-return TargetLibraryInfo(*PresetInfoImpl);
-
-  return TargetLibraryInfo(
-  lookupInfoImpl(Triple(F.getParent()->getTargetTriple(;
-}
-
-TargetLibraryInfoImpl ::lookupInfoImpl(const Triple ) {
-  std::unique_ptr  =
-  Impls[T.normalize()];
-  if (!Impl)
-Impl.reset(new TargetLibraryInfoImpl(T));
-
-  return *Impl;
+  if (!BaselineInfoImpl)
+BaselineInfoImpl =
+TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+  return TargetLibraryInfo(*BaselineInfoImpl, );
 }
 
 unsigned TargetLibraryInfoImpl::getWCharSize(const Module ) const {
@@ -1614,18 +1604,18 @@
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
-: ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple )
-: ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
 const TargetLibraryInfoImpl )
-: ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
+: ImmutablePass(ID), TLA(TLIImpl) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Triple.h"
@@ -48,6 +49,7 @@
   friend class TargetLibraryInfo;
 
   unsigned char AvailableArray[(NumLibFuncs+3)/4];
+
   llvm::DenseMap CustomNames;
   static StringLiteral const StandardNames[NumLibFuncs];
   bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param;
@@ -212,20 +214,52 @@
   friend class TargetLibraryAnalysis;
   friend class TargetLibraryInfoWrapperPass;
 
+  /// The global (module level) TLI info.
   const TargetLibraryInfoImpl *Impl;
 
+  /// Support for -fno-builtin* options as function attributes, overrides
+  /// information in global TargetLibraryInfoImpl.
+  BitVector OverrideAsUnavailable;
+
 public:
-  explicit TargetLibraryInfo(const TargetLibraryInfoImpl ) : Impl() {}
+  explicit TargetLibraryInfo(
+  const TargetLibraryInfoImpl ,
+  LLVM_ATTRIBUTE_UNUSED Optional F = None)
+  : Impl(), OverrideAsUnavailable(NumLibFuncs) {
+if (F) {
+  if ((*F)->hasFnAttribute("no-builtins"))
+disableAllFunctions();
+  else {
+// Disable individual libc/libm calls in TargetLibraryInfo.
+LibFunc LF;
+AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
+std::string Prefix = "no-builtin-";
+for (const Attribute  : FnAttrs) {
+  if (!Attr.isStringAttribute())
+continue;
+  auto AttrStr = Attr.getKindAsString();
+  if (!AttrStr.consume_front(Prefix))
+continue;
+  if (getLibFunc(AttrStr, LF))
+setUnavailable(LF);
+}
+  }
+}
+  }
 
   // Provide value semantics.
-  TargetLibraryInfo(const TargetLibraryInfo ) : Impl(TLI.Impl) {}
-  TargetLibraryInfo(TargetLibraryInfo &) : Impl(TLI.Impl) {}
+  TargetLibraryInfo(const TargetLibraryInfo )
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
+  TargetLibraryInfo(TargetLibraryInfo &)
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
   TargetLibraryInfo =(const TargetLibraryInfo ) {
 Impl = TLI.Impl;
+OverrideAsUnavailable = TLI.OverrideAsUnavailable;
 return *this;
   }
   

[PATCH] D71485: [profile] Fix a crash when -fprofile-remapping-file= triggers an error

2019-12-13 Thread Wei Mi via Phabricator via cfe-commits
wmi accepted this revision.
wmi added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71485



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


[PATCH] D70073: [ConstExprPreter] Implemented function calls and if statements

2019-12-13 Thread Nandor Licker via Phabricator via cfe-commits
nand added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70073



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


[PATCH] D71485: [profile] Fix a crash when -fprofile-remapping-file= triggers an error

2019-12-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: rsmith, wenlei, wmi.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71485

Files:
  clang/test/CodeGenCXX/Inputs/profile-remap-error.map
  clang/test/CodeGenCXX/profile-remap-error.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap-error.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 
'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create 
remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: 
Malformed sample profile data
+
+void foo();
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1973,7 +1973,8 @@
: ProfileRemappingFileName,
   IsThinLTOPreLink, GetAssumptionCache, GetTTI);
 
-  SampleLoader.doInitialization(M);
+  if (!SampleLoader.doInitialization(M))
+return PreservedAnalyses::all();
 
   ProfileSummaryInfo *PSI = (M);
   CallGraph  = AM.getResult(M);
Index: clang/test/CodeGenCXX/profile-remap-error.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/profile-remap-error.cpp
@@ -0,0 +1,9 @@
+// REQUIRES: x86-registered-target
+
+// RUN: not %clang_cc1 -triple x86_64-linux-gnu -fprofile-sample-use=%S/Inputs/profile-remap.samples -fprofile-remapping-file=%S/Inputs/profile-remap-error.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - 2>&1 | FileCheck %s
+
+// CHECK:  error: {{.*}}/profile-remap-error.map:1: Could not demangle 'unmangled' as a ; invalid mangling?
+// CHECK-NEXT: error: {{.*}}/profile-remap-error.map: Could not create remapper: Malformed sample profile data
+// CHECK-NEXT: error: {{.*}}/profile-remap.samples: Could not open profile: Malformed sample profile data
+
+void foo();
Index: clang/test/CodeGenCXX/Inputs/profile-remap-error.map
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/profile-remap-error.map
@@ -0,0 +1 @@
+name unmangled ignored
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >