[clang] b41b743 - [test] Improve weakref & weak_import tests

2021-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-01-09T23:56:55-08:00
New Revision: b41b743d461168300ae0121937b50e334563d307

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

LOG: [test] Improve weakref & weak_import tests

Added: 


Modified: 
clang/test/CodeGen/attr-weak-import.c
clang/test/CodeGen/attr-weakref.c
clang/test/CodeGen/attr-weakref2.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-weak-import.c 
b/clang/test/CodeGen/attr-weak-import.c
index 23d02c10dca1..85989f03a277 100644
--- a/clang/test/CodeGen/attr-weak-import.c
+++ b/clang/test/CodeGen/attr-weak-import.c
@@ -18,9 +18,9 @@ extern int E __attribute__((weak_import));
 int E;
 extern int E __attribute__((weak_import));
 
-// CHECK: @A ={{.*}} global i32
+// CHECK: @A = dso_local global i32
 // CHECK-NOT: @B =
-// CHECK: @C ={{.*}} global i32
-// CHECK: @D ={{.*}} global i32
-// CHECK: @E ={{.*}} global i32
+// CHECK: @C = dso_local global i32
+// CHECK: @D = dso_local global i32
+// CHECK: @E = dso_local global i32
 

diff  --git a/clang/test/CodeGen/attr-weakref.c 
b/clang/test/CodeGen/attr-weakref.c
index 0923cf33a6de..7ed4efdd2cb4 100644
--- a/clang/test/CodeGen/attr-weakref.c
+++ b/clang/test/CodeGen/attr-weakref.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s
-// RUN: FileCheck --input-file=%t %s
+// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o - %s | FileCheck %s
 
 // CHECK: declare extern_weak void @test1_f()
 void test1_f(void);
@@ -8,7 +7,7 @@ void test1_h(void) {
   test1_g();
 }
 
-// CHECK-LABEL: define{{.*}} void @test2_f()
+// CHECK-LABEL: define dso_local void @test2_f()
 void test2_f(void) {}
 static void test2_g(void) __attribute__((weakref("test2_f")));
 void test2_h(void) {
@@ -25,7 +24,7 @@ void test3_h(void) {
   test3_g();
 }
 
-// CHECK-LABEL: define{{.*}} void @test4_f()
+// CHECK-LABEL: define dso_local void @test4_f()
 void test4_f(void);
 static void test4_g(void) __attribute__((weakref("test4_f")));
 void test4_h(void) {

diff  --git a/clang/test/CodeGen/attr-weakref2.c 
b/clang/test/CodeGen/attr-weakref2.c
index 47c96fd5af41..2746819833b1 100644
--- a/clang/test/CodeGen/attr-weakref2.c
+++ b/clang/test/CodeGen/attr-weakref2.c
@@ -8,7 +8,7 @@ int test1_h(void) {
   return test1_g;
 }
 
-// CHECK: @test2_f ={{.*}} global i32 0, align 4
+// CHECK: @test2_f = dso_local global i32 0, align 4
 int test2_f;
 static int test2_g __attribute__((weakref("test2_f")));
 int test2_h(void) {
@@ -25,7 +25,7 @@ int test3_h(void) {
   return test3_g;
 }
 
-// CHECK: @test4_f ={{.*}} global i32 0, align 4
+// CHECK: @test4_f = dso_local global i32 0, align 4
 extern int test4_f;
 static int test4_g __attribute__((weakref("test4_f")));
 int test4_h(void) {



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


[PATCH] D93999: [clang] Fix message text for `-Wpointer-sign` to account for plain char

2021-01-09 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 315648.
hubert.reinterpretcast added a comment.

- Address review: Mention plain char only when it appears


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93999

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/incompatible-sign.c
  clang/test/Sema/incompatible-sign.cpp
  clang/test/SemaObjC/objc-cf-audited-warning.m

Index: clang/test/SemaObjC/objc-cf-audited-warning.m
===
--- clang/test/SemaObjC/objc-cf-audited-warning.m
+++ clang/test/SemaObjC/objc-cf-audited-warning.m
@@ -20,5 +20,5 @@
 
 void saveImageToJPG(const char *filename)
 {
-CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, filename, 10, 0); // expected-warning {{passing 'const char *' to parameter of type 'const UInt8 *' (aka 'const unsigned char *') converts between pointers to integer types with different sign}}
+CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, filename, 10, 0); // expected-warning {{passing 'const char *' to parameter of type 'const UInt8 *' (aka 'const unsigned char *') converts between pointers to integer types where one is of the unique plain char type and the other is not}}
 }
Index: clang/test/Sema/incompatible-sign.cpp
===
--- /dev/null
+++ clang/test/Sema/incompatible-sign.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
+
+void plainToSigned() {
+  extern char c;
+  signed char *p;
+  p =  // expected-error {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+}
+
+void unsignedToPlain() {
+  extern unsigned char uc;
+  char *p;
+  p =  // expected-error {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+}
Index: clang/test/Sema/incompatible-sign.c
===
--- clang/test/Sema/incompatible-sign.c
+++ clang/test/Sema/incompatible-sign.c
@@ -1,5 +1,23 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
 
 int a(int* x); // expected-note{{passing argument to parameter 'x' here}}
 int b(unsigned* y) { return a(y); } // expected-warning {{passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign}}
 
+signed char *plainCharToSignedChar(signed char *arg) { // expected-note{{passing argument to parameter}}
+  extern char c;
+  signed char *p =  // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  struct { signed char *p; } s = {  }; // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  p =  // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  plainCharToSignedChar(); // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  return  // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+}
+
+char *unsignedCharToPlainChar(char *arg) { // expected-note{{passing argument to parameter}}
+  extern unsigned char uc[];
+  char *p = uc; // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  (void) (char *[]){ [42] = uc }; // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  p = uc; // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  unsignedCharToPlainChar(uc); // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+  return uc; // expected-warning {{converts between pointers to integer types where one is of the unique plain char type and the other is not}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15962,6 +15962,16 @@
   else
 FDiag << FirstType << SecondType << Action << SrcExpr->getSourceRange();
 
+  if (DiagKind == diag::ext_typecheck_convert_incompatible_pointer_sign ||
+  DiagKind == diag::err_typecheck_convert_incompatible_pointer_sign) {
+const auto isPlainChar = [](const clang::Type *Type) {
+  return 

[PATCH] D94337: Add cuda header type for cuh files

2021-01-09 Thread Ryan Greenblatt via Phabricator via cfe-commits
rgreenblatt added a comment.

Just to be clear, this is currently a WIP - it would still be good if someone 
took a look at this because I don't know if
this approach makes any sense.

I made this change with the aim of allowing language servers and other tools to 
cleanly handle
.cuh files, but in theory it should also be possible to actually generate and 
use precompiled cuda headers.
Perhaps unsuprisingly, precompiled cuda headers don't actually work (crash) 
with the changes made so far.
However, everything does *seem* to be working in the language 
server/"-fsyntax-only" context
(aside from incorrectly issuing a warning for  '#pragma once").

I don't have any idea what would be required to actually get cuda precompiled 
headers working.
I will spend some time looking into this when I get a chance. Alternatively, we 
could just disable
generating precompiled cuda headers but allow for syntax checking 
(-fsyntax-only and associated front end functions).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94337

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


Re: [clang] 9c4b222 - Revert "Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis."""""

2021-01-09 Thread Artem Dergachev via cfe-commits

Hi,

Could you please point out the specific problem? I don't see any errors 
myself in a number of configurations that i tested locally (shared 
library builds and builds with modules) and all buildbots are silent. 
How do you even discover these issues? Is there a tool for that that i'm 
missing?


On 1/8/21 5:17 AM, Alexander Belyaev via cfe-commits wrote:

Author: Alexander Belyaev
Date: 2021-01-08T14:17:18+01:00
New Revision: 9c4b2225b24de07a728715ce20238803370413ea

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

LOG: Revert "Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer 
implementations to libAnalysis."

This reverts commit 6b0ee02747ed22d41e175d15f27025183341e6f8.

Circular dependency again.

Added:
 clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
 clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
 clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
 clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
 clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp

Modified:
 clang/include/clang/CrossTU/CrossTranslationUnit.h
 clang/include/clang/StaticAnalyzer/Core/Analyses.def
 clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
 clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
 clang/include/clang/module.modulemap
 clang/lib/Analysis/CMakeLists.txt
 clang/lib/CrossTU/CrossTranslationUnit.cpp
 clang/lib/Frontend/CompilerInvocation.cpp
 clang/lib/StaticAnalyzer/Core/CMakeLists.txt
 clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed:
 clang/include/clang/Analysis/CrossTUAnalysisHelper.h
 clang/include/clang/Analysis/PathDiagnosticConsumers.def
 clang/include/clang/Analysis/PathDiagnosticConsumers.h
 clang/lib/Analysis/HTMLPathDiagnosticConsumer.cpp
 clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp
 clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp
 clang/lib/Analysis/SarifPathDiagnosticConsumer.cpp
 clang/lib/Analysis/TextPathDiagnosticConsumer.cpp



diff  --git a/clang/include/clang/Analysis/CrossTUAnalysisHelper.h 
b/clang/include/clang/Analysis/CrossTUAnalysisHelper.h
deleted file mode 100644
index 500e78ddedcf..
--- a/clang/include/clang/Analysis/CrossTUAnalysisHelper.h
+++ /dev/null
@@ -1,41 +0,0 @@
-//===- CrossTUAnalysisHelper.h - Abstraction layer for CTU --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-#ifndef LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
-#define LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
-
-#include "llvm/ADT/Optional.h"
-#include "clang/Basic/SourceManager.h"
-
-namespace clang {
-
-class ASTUnit;
-
-/// This class is an abstract interface acting as a bridge between
-/// an analysis that requires lookups across translation units (a user
-/// of that interface) and the facility that implements such lookups
-/// (an implementation of that interface). This is useful to break direct
-/// link-time dependencies between the (possibly shared) libraries in which
-/// the user and the implementation live.
-class CrossTUAnalysisHelper {
-public:
-  /// Determine the original source location in the original TU for an
-  /// imported source location.
-  /// \p ToLoc Source location in the imported-to AST.
-  /// \return Source location in the imported-from AST and the corresponding
-  /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
-  /// object that is returned here).
-  /// If any error happens (ToLoc is a non-imported source location) empty is
-  /// returned.
-  virtual llvm::Optional>
-  getImportedFromSourceLocationWithPreprocessor(SourceLocation ToLoc) const = 
0;
-
-  virtual ~CrossTUAnalysisHelper() {}
-};
-} // namespace clang
-
-#endif // LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H

diff  --git a/clang/include/clang/Analysis/PathDiagnosticConsumers.def 
b/clang/include/clang/Analysis/PathDiagnosticConsumers.def
deleted file mode 100644
index 33d2072fcf31..
--- a/clang/include/clang/Analysis/PathDiagnosticConsumers.def
+++ /dev/null
@@ -1,50 +0,0 @@
-//===-- PathDiagnosticConsumers.def - Visualizing warnings --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the set of path diagnostic 

[PATCH] D94367: [Clang][Driver] Add -ffinite-loops flags

2021-01-09 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 315641.
atmnpatel added a comment.

Update CommandLineReference.rst to also include `-fno-finite-loops`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94367

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/finite-loops.c
  clang/test/CodeGenCXX/finite-loops.cpp
  clang/test/Driver/clang_f_opts.c

Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -52,6 +52,15 @@
 // CHECK-REROLL-LOOPS: "-freroll-loops"
 // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops"
 
+// RUN: %clang -### -S -ffinite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-FINITE-LOOPS %s
+// RUN: %clang -### -S -fno-finite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FINITE-LOOPS %s
+// RUN: %clang -### -S -fno-finite-loops -ffinite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-FINITE-LOOPS %s
+// RUN: %clang -### -S -ffinite-loops -fno-finite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FINITE-LOOPS %s
+// CHECK-FINITE-LOOPS: "-ffinite-loops"
+// CHECK-FINITE-LOOPS-NOT: "-fno-finite-loops"
+// CHECK-NO-FINITE-LOOPS: "-fno-finite-loops"
+// CHECK-NO-FINITE-LOOPS-NOT: "-ffinite-loops"
+
 // RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s
 // CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate"
 
@@ -292,6 +301,7 @@
 // RUN: -malign-functions=100 \
 // RUN: -malign-loops=100 \
 // RUN: -malign-jumps=100 \
+// RUN: -ffinite-loops -fno-finite-loops  \
 // RUN: %s 2>&1 | FileCheck --check-prefix=IGNORE %s
 // IGNORE-NOT: error: unknown argument
 
Index: clang/test/CodeGenCXX/finite-loops.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/finite-loops.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -o - %s | FileCheck %s -check-prefix=CHECK-CPP03-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -ffinite-loops -o - %s | FileCheck %s -check-prefix=CHECK-FINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -fno-finite-loops -o - %s | FileCheck %s -check-prefix=CHECK-INFINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -o - %s | FileCheck %s -check-prefix=CHECK-CPP11-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -ffinite-loops -o - %s | FileCheck %s -check-prefix=CHECK-FINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -fno-finite-loops -o - %s | FileCheck %s -check-prefix=CHECK-INFINITE-LOOPS
+
+// CHECK-CPP03-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP03-LOOPS-LABEL: @_Z1fii(
+// CHECK-CPP03-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-FINITE-LOOPS: Function Attrs: noinline nounwind optnone mustprogress
+// CHECK-FINITE-LOOPS-LABEL: @_Z1fii(
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+//
+// CHECK-INFINITE-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-INFINITE-LOOPS-LABEL: @_Z1fii(
+// CHECK-INFINITE-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-CPP11-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP11-LOOPS-LABEL: @_Z1fii(
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+//
+int f(int a, int b) {
+  for (; a != b; ) {
+if (a == b)
+  return 1;
+  }
+
+  for (;;) {
+if (a != b)
+  return 1;
+  }
+  return 0;
+}
+
+// CHECK-CPP03-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP03-LOOPS-LABEL: @_Z2dwii(
+// CHECK-CPP03-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-FINITE-LOOPS: Function Attrs: noinline nounwind optnone mustprogress
+// CHECK-FINITE-LOOPS-LABEL: @_Z2dwii(
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+//
+// CHECK-INFINITE-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-INFINITE-LOOPS-LABEL: @_Z2dwii(
+// CHECK-INFINITE-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-CPP11-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP11-LOOPS-LABEL: @_Z2dwii(
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+//
+int dw(int a, int b) {
+  do {
+if (a == b)
+  return 1;
+  } while (a != b);
+
+  do {
+if (a != b)
+  return 1;
+  } while (1);
+  return 0;
+}
+
+// 

[PATCH] D94367: [Clang][Driver] Add -ffinite-loops flags

2021-01-09 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel created this revision.
atmnpatel added reviewers: fhahn, jdoerfert, xbolva00.
Herald added subscribers: dexonsmith, dang.
atmnpatel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Following D94366 , clang will strictly adheres 
to the language standard
when deciding whether or not to emit `mustprogress` attributes for
loops. This patch adds two flags: `-ffinite-loops` and
`-fno-finite-loops` that override the language standard into either
never emitting `mustprogress` attributes or emitting `mustprogress`
attributes for all loops/functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94367

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/finite-loops.c
  clang/test/CodeGenCXX/finite-loops.cpp
  clang/test/Driver/clang_f_opts.c

Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -52,6 +52,15 @@
 // CHECK-REROLL-LOOPS: "-freroll-loops"
 // CHECK-NO-REROLL-LOOPS-NOT: "-freroll-loops"
 
+// RUN: %clang -### -S -ffinite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-FINITE-LOOPS %s
+// RUN: %clang -### -S -fno-finite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FINITE-LOOPS %s
+// RUN: %clang -### -S -fno-finite-loops -ffinite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-FINITE-LOOPS %s
+// RUN: %clang -### -S -ffinite-loops -fno-finite-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FINITE-LOOPS %s
+// CHECK-FINITE-LOOPS: "-ffinite-loops"
+// CHECK-FINITE-LOOPS-NOT: "-fno-finite-loops"
+// CHECK-NO-FINITE-LOOPS: "-fno-finite-loops"
+// CHECK-NO-FINITE-LOOPS-NOT: "-ffinite-loops"
+
 // RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s
 // CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate"
 
@@ -292,6 +301,7 @@
 // RUN: -malign-functions=100 \
 // RUN: -malign-loops=100 \
 // RUN: -malign-jumps=100 \
+// RUN: -ffinite-loops -fno-finite-loops  \
 // RUN: %s 2>&1 | FileCheck --check-prefix=IGNORE %s
 // IGNORE-NOT: error: unknown argument
 
Index: clang/test/CodeGenCXX/finite-loops.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/finite-loops.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -o - %s | FileCheck %s -check-prefix=CHECK-CPP03-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -ffinite-loops -o - %s | FileCheck %s -check-prefix=CHECK-FINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++03 -fno-finite-loops -o - %s | FileCheck %s -check-prefix=CHECK-INFINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -o - %s | FileCheck %s -check-prefix=CHECK-CPP11-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -ffinite-loops -o - %s | FileCheck %s -check-prefix=CHECK-FINITE-LOOPS
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -std=c++11 -fno-finite-loops -o - %s | FileCheck %s -check-prefix=CHECK-INFINITE-LOOPS
+
+// CHECK-CPP03-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP03-LOOPS-LABEL: @_Z1fii(
+// CHECK-CPP03-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-FINITE-LOOPS: Function Attrs: noinline nounwind optnone mustprogress
+// CHECK-FINITE-LOOPS-LABEL: @_Z1fii(
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+//
+// CHECK-INFINITE-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-INFINITE-LOOPS-LABEL: @_Z1fii(
+// CHECK-INFINITE-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-CPP11-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP11-LOOPS-LABEL: @_Z1fii(
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+// CHECK-CPP11-LOOPS:{{.*}} !llvm.loop !
+//
+int f(int a, int b) {
+  for (; a != b; ) {
+if (a == b)
+  return 1;
+  }
+
+  for (;;) {
+if (a != b)
+  return 1;
+  }
+  return 0;
+}
+
+// CHECK-CPP03-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-CPP03-LOOPS-LABEL: @_Z2dwii(
+// CHECK-CPP03-LOOPS-NOT:{{.*}} !llvm.loop !
+//
+// CHECK-FINITE-LOOPS: Function Attrs: noinline nounwind optnone mustprogress
+// CHECK-FINITE-LOOPS-LABEL: @_Z2dwii(
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+// CHECK-FINITE-LOOPS:{{.*}} !llvm.loop !
+//
+// CHECK-INFINITE-LOOPS: Function Attrs: noinline nounwind optnone
+// CHECK-INFINITE-LOOPS-LABEL: 

[clang] e2e82c9 - [CodeGenModule] Drop dso_local on function declarations for ELF -fno-pic -fno-direct-access-external-data

2021-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-01-09T16:31:56-08:00
New Revision: e2e82c9983f0dff671dd47d3e256d80faa40e892

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

LOG: [CodeGenModule] Drop dso_local on function declarations for ELF -fno-pic 
-fno-direct-access-external-data

ELF -fno-pic sets dso_local on a function declaration to allow direct accesses
when taking its address (similar to a data symbol). The emitted code follows the
traditional GCC/Clang -fno-pic behavior: an absolute relocation is produced.

If the function is not defined in the executable, a canonical PLT entry will be
needed at link time. This is similar to a copy relocation and is incompatible
with (-Bsymbolic or --dynamic-list linked shared objects / protected symbols in
a shared object).

This patch gives -fno-pic code a way to avoid such a canonical PLT entry.

The FIXME was about a generalization for -fpie -mpie-copy-relocations (now -fpie
-fdirect-access-external-data). While we could set dso_local to avoid GOT when
taking the address of a function declaration (there is an ignorable difference
about R_386_PC32 vs R_386_PLT32 on i386), it likely does not provide any benefit
and can just cause trouble, so we don't make the generalization.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/dso-local-executable.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 85b5009dce7e..da5b03b138bf 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -983,16 +983,27 @@ static bool shouldAssumeDSOLocal(const CodeGenModule ,
   if (TT.isPPC64())
 return false;
 
-  // If we can use copy relocations we can assume it is local.
-  if (auto *Var = dyn_cast(GV))
-if (!Var->isThreadLocal() && CGOpts.DirectAccessExternalData)
+  if (CGOpts.DirectAccessExternalData) {
+// If -fdirect-access-external-data (default for -fno-pic), set dso_local
+// for non-thread-local variables. If the symbol is not defined in the
+// executable, a copy relocation will be needed at link time. dso_local is
+// excluded for thread-local variables because they generally don't support
+// copy relocations.
+if (auto *Var = dyn_cast(GV))
+  if (!Var->isThreadLocal())
+return true;
+
+// -fno-pic sets dso_local on a function declaration to allow direct
+// accesses when taking its address (similar to a data symbol). If the
+// function is not defined in the executable, a canonical PLT entry will be
+// needed at link time. -fno-direct-access-external-data can avoid the
+// canonical PLT entry. We don't generalize this condition to -fpie/-fpic 
as
+// it could just cause trouble without providing perceptible benefits.
+if (isa(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
   return true;
+  }
 
-  // If we can use a plt entry as the symbol address we can assume it
-  // is local.
-  // FIXME: This should work for PIE, but the gold linker doesn't support it.
-  if (isa(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
-return true;
+  // If we can use copy relocations we can assume it is local.
 
   // Otherwise don't assume it is local.
   return false;

diff  --git a/clang/test/CodeGen/dso-local-executable.c 
b/clang/test/CodeGen/dso-local-executable.c
index 19930b068218..4c282a334b11 100644
--- a/clang/test/CodeGen/dso-local-executable.c
+++ b/clang/test/CodeGen/dso-local-executable.c
@@ -43,9 +43,9 @@
 // STATIC-INDIRECT-NEXT: @bar = external global i32
 // STATIC-INDIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 
42
 // STATIC-INDIRECT-NEXT: @thread_var = external thread_local global i32
-// STATIC-INDIRECT-DAG:  declare dso_local void @import_func()
+// STATIC-INDIRECT-DAG:  declare void @import_func()
 // STATIC-INDIRECT-DAG:  define dso_local i32* @zed()
-// STATIC-INDIRECT-DAG:  declare dso_local void @foo()
+// STATIC-INDIRECT-DAG:  declare void @foo()
 
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - 
| FileCheck --check-prefix=PIE %s
 // PIE:  @baz = dso_local global i32 42



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


[PATCH] D94366: [Clang] Emit mustprogress for infinite C++ loops

2021-01-09 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 315639.
atmnpatel added a comment.

`while(1)` case was mishandled for C++11 onwards, fixed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94366

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/attr-mustprogress-1.cpp

Index: clang/test/CodeGen/attr-mustprogress-1.cpp
===
--- clang/test/CodeGen/attr-mustprogress-1.cpp
+++ clang/test/CodeGen/attr-mustprogress-1.cpp
@@ -7,24 +7,25 @@
 int a = 0;
 int b = 0;
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2f0v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
-// CHECK-NOT:br label [[FOR_COND]], !llvm.loop !{{.*}}
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP2:!llvm.loop !.*]]
+//
 void f0() {
   for (; ;) ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2f1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP4:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -43,7 +44,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]], [[LOOP2:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP5:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -52,14 +53,14 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z1Fv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP6:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:br label [[FOR_COND1:%.*]]
 // CHECK:   for.cond1:
@@ -68,7 +69,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]]
 // CHECK:   for.body2:
-// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP4:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP7:!llvm.loop !.*]]
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -79,7 +80,7 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2F2v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
@@ -89,13 +90,13 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]], [[LOOP5:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP8:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:br label [[FOR_COND1:%.*]]
 // CHECK:   for.cond1:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]]
 // CHECK:   for.body2:
-// CHECK-NEXT:br label [[FOR_COND1]]
+// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP9:!llvm.loop !.*]]
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -106,12 +107,12 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2w1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[WHILE_BODY:%.*]]
 // CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_BODY]]
+// CHECK-NEXT:br label [[WHILE_BODY]], [[LOOP10:!llvm.loop !.*]]
 //
 void w1() {
   while (1)
@@ -128,7 +129,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[WHILE_BODY:%.*]], label [[WHILE_END:%.*]]
 // CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_COND]], [[LOOP6:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[WHILE_COND]], [[LOOP11:!llvm.loop !.*]]
 // CHECK:   while.end:
 // CHECK-NEXT:ret void
 //
@@ -137,7 +138,7 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z1Wv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[WHILE_COND:%.*]]
@@ -147,11 +148,11 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:   

[PATCH] D94366: [Clang] Emit mustprogress for infinite C++ loops

2021-01-09 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel created this revision.
atmnpatel added reviewers: fhahn, jdoerfert, xbolva00.
atmnpatel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently, clang does not emit the `mustprogress` loop or function
attribute for loops with non-zero constant conditionals. Based on recent
discussion in D86844  and D86841 
, it seems that it would be preferable to
emit these attributes to adhere more tightly to the C++ standard as gcc
does.

I will be pushing a patch to add `-ffinite-loops` and `-fno-finite-loops` to
clang to provide more control over this momentarily.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94366

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/attr-mustprogress-1.cpp

Index: clang/test/CodeGen/attr-mustprogress-1.cpp
===
--- clang/test/CodeGen/attr-mustprogress-1.cpp
+++ clang/test/CodeGen/attr-mustprogress-1.cpp
@@ -7,24 +7,25 @@
 int a = 0;
 int b = 0;
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2f0v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
-// CHECK-NOT:br label [[FOR_COND]], !llvm.loop !{{.*}}
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP2:!llvm.loop !.*]]
+//
 void f0() {
   for (; ;) ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2f1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP4:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -43,7 +44,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]], [[LOOP2:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP5:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -52,14 +53,14 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z1Fv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP6:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:br label [[FOR_COND1:%.*]]
 // CHECK:   for.cond1:
@@ -68,7 +69,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]]
 // CHECK:   for.body2:
-// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP4:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP7:!llvm.loop !.*]]
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -79,7 +80,7 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2F2v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[FOR_COND:%.*]]
@@ -89,13 +90,13 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
 // CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]], [[LOOP5:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[FOR_COND]], [[LOOP8:!llvm.loop !.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:br label [[FOR_COND1:%.*]]
 // CHECK:   for.cond1:
 // CHECK-NEXT:br i1 true, label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]]
 // CHECK:   for.body2:
-// CHECK-NEXT:br label [[FOR_COND1]]
+// CHECK-NEXT:br label [[FOR_COND1]], [[LOOP9:!llvm.loop !.*]]
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -106,7 +107,7 @@
 ;
 }
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z2w1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label [[WHILE_BODY:%.*]]
@@ -128,7 +129,7 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label [[WHILE_BODY:%.*]], label [[WHILE_END:%.*]]
 // CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_COND]], [[LOOP6:!llvm.loop !.*]]
+// CHECK-NEXT:br label [[WHILE_COND]], [[LOOP10:!llvm.loop !.*]]
 // CHECK:   while.end:
 // CHECK-NEXT:ret void
 //
@@ -137,7 +138,7 @@
 ;
 }
 

[PATCH] D94364: [clang] Allow specifying the aapcs and aapcs-vfp for windows on arm

2021-01-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: rnk, compnerd, smeenai.
Herald added a subscriber: kristof.beyls.
mstorsjo requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94364

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Sema/callingconv-win-arm.c


Index: clang/test/Sema/callingconv-win-arm.c
===
--- /dev/null
+++ clang/test/Sema/callingconv-win-arm.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -fsyntax-only -triple armv7-windows -verify
+
+// expected-no-diagnostics
+
+void __attribute__((fastcall)) foo(float *a);
+
+void __attribute__((stdcall)) bar(float *a);
+
+void __attribute__((cdecl)) ctest0();
+
+int __attribute__((pcs("aapcs"))) pcs5(void);
+int __attribute__((pcs("aapcs-vfp"))) pcs6(void);
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -1194,6 +1194,8 @@
   case CC_X86FastCall:
   case CC_X86VectorCall:
 return CCCR_Ignore;
+  case CC_AAPCS:
+  case CC_AAPCS_VFP:
   case CC_C:
   case CC_OpenCLKernel:
   case CC_PreserveMost:


Index: clang/test/Sema/callingconv-win-arm.c
===
--- /dev/null
+++ clang/test/Sema/callingconv-win-arm.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -fsyntax-only -triple armv7-windows -verify
+
+// expected-no-diagnostics
+
+void __attribute__((fastcall)) foo(float *a);
+
+void __attribute__((stdcall)) bar(float *a);
+
+void __attribute__((cdecl)) ctest0();
+
+int __attribute__((pcs("aapcs"))) pcs5(void);
+int __attribute__((pcs("aapcs-vfp"))) pcs6(void);
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -1194,6 +1194,8 @@
   case CC_X86FastCall:
   case CC_X86VectorCall:
 return CCCR_Ignore;
+  case CC_AAPCS:
+  case CC_AAPCS_VFP:
   case CC_C:
   case CC_OpenCLKernel:
   case CC_PreserveMost:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4dbb3f5 - [clang] Add llvm-strip to test dependencies

2021-01-09 Thread Shoaib Meenai via cfe-commits

Author: Shoaib Meenai
Date: 2021-01-09T11:57:27-08:00
New Revision: 4dbb3f57c6fe581ef525dbe49a401f4bab834eff

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

LOG: [clang] Add llvm-strip to test dependencies

CodeGen/thinlto_embed_bitcode.ll relies on it.

Added: 


Modified: 
clang/test/CMakeLists.txt

Removed: 




diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index a913b35ed567..562a14826033 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -122,6 +122,7 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-profdata
 llvm-readelf
 llvm-readobj
+llvm-strip
 llvm-symbolizer
 opt
 split-file



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


[PATCH] D94213: Clang: Remove support for 3DNow!, both intrinsics and builtins.

2021-01-09 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Agreed w.r.t. timing -- I would like to get all of these changes landed soon 
after the LLVM 12 branch-cut, to allow plenty time to stew on the main branch 
before they make it into a release to try to identify any issues.

I'd still appreciate review and approval with the proviso that it not land yet, 
however.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94213

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


[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:11
+// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", 
scope: {{.*}}, file: [[FILE]]
+// CHECK: {{.*}} = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]]
+

MaskRay wrote:
> The behavior is default triple dependent. `*-windows-msvc` triples use 
> different static constructor mechanism. I fixed the test by adding `-triple 
> %itanium_abi_triple`
Thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87147

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


[PATCH] D94213: Clang: Remove support for 3DNow!, both intrinsics and builtins.

2021-01-09 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

This all needs properly documenting in the release notes, and possibly in the 
clang docs as well explaining that mmx/3dnow is supported only inside assembly,

Are we likely to get all of the 3dnow and mmx changes done before the 12.00 
branch? Otherwise I'm tempted to suggest we delay this until just after the 
branch is made and we target (and document) it all for 13.00.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94213

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


[PATCH] D93585: [AArch64] Enable out-of-line atomics by default.

2021-01-09 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv updated this revision to Diff 315613.
ilinpv edited the summary of this revision.
ilinpv added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

RT library detection and check for outline atomics support added to the driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93585

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/test/CodeGen/AArch64/arm64_32-atomics.ll
  llvm/test/CodeGen/AArch64/atomic-ops-not-barriers.ll
  llvm/test/CodeGen/AArch64/atomic-ops.ll
  llvm/test/CodeGen/AArch64/cmpxchg-O0.ll
  llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll
  llvm/test/Transforms/AtomicExpand/AArch64/expand-atomicrmw-xchg-fp.ll

Index: llvm/test/Transforms/AtomicExpand/AArch64/expand-atomicrmw-xchg-fp.ll
===
--- llvm/test/Transforms/AtomicExpand/AArch64/expand-atomicrmw-xchg-fp.ll
+++ llvm/test/Transforms/AtomicExpand/AArch64/expand-atomicrmw-xchg-fp.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -mtriple=aarch64-- -atomic-expand %s | FileCheck %s
-; RUN: opt -S -mtriple=aarch64-- -mattr=+outline-atomics -atomic-expand %s | FileCheck %s --check-prefix=OUTLINE-ATOMICS
+; RUN: opt -S -mtriple=aarch64-- -mattr=-outline-atomics -atomic-expand %s | FileCheck %s
+; RUN: opt -S -mtriple=aarch64-- -atomic-expand %s | FileCheck %s --check-prefix=OUTLINE-ATOMICS
 
 define void @atomic_swap_f16(half* %ptr, half %val) nounwind {
 ; CHECK-LABEL: @atomic_swap_f16(
Index: llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll
===
--- llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll
+++ llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s
-; RUN: llc -mtriple=aarch64-apple-ios7.0 -mattr=+outline-atomics -o - %s | FileCheck %s --check-prefix=OUTLINE-ATOMICS
+; RUN: llc -mtriple=aarch64-apple-ios7.0 -mattr=-outline-atomics -o - %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s --check-prefix=OUTLINE-ATOMICS
 
 define i32 @test_return(i32* %p, i32 %oldval, i32 %newval) {
 ; OUTLINE-ATOMICS: bl ___aarch64_cas4_acq_rel
Index: llvm/test/CodeGen/AArch64/cmpxchg-O0.ll
===
--- llvm/test/CodeGen/AArch64/cmpxchg-O0.ll
+++ llvm/test/CodeGen/AArch64/cmpxchg-O0.ll
@@ -1,5 +1,5 @@
-; RUN: llc -verify-machineinstrs -mtriple=aarch64-linux-gnu -O0 -fast-isel=0 -global-isel=false %s -o - | FileCheck -enable-var-scope %s
-; RUN: llc -verify-machineinstrs -mtriple=aarch64-linux-gnu -O0 -fast-isel=0 -global-isel=false -mattr=+outline-atomics %s -o - | FileCheck -enable-var-scope %s --check-prefix=OUTLINE-ATOMICS
+; RUN: llc -verify-machineinstrs -mtriple=aarch64-linux-gnu -O0 -fast-isel=0 -global-isel=false -mattr=-outline-atomics %s -o - | FileCheck -enable-var-scope %s
+; RUN: llc -verify-machineinstrs -mtriple=aarch64-linux-gnu -O0 -fast-isel=0 -global-isel=false %s -o - | FileCheck -enable-var-scope %s --check-prefix=OUTLINE-ATOMICS
 
 define { i8, i1 } @test_cmpxchg_8(i8* %addr, i8 %desired, i8 %new) nounwind {
 ; OUTLINE-ATOMICS: bl __aarch64_cas1_acq_rel
Index: llvm/test/CodeGen/AArch64/atomic-ops.ll
===
--- llvm/test/CodeGen/AArch64/atomic-ops.ll
+++ llvm/test/CodeGen/AArch64/atomic-ops.ll
@@ -1,6 +1,6 @@
-; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs < %s | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK-REG
-; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs -mattr=+outline-atomics < %s | FileCheck %s --check-prefix=OUTLINE_ATOMICS
+; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs -mattr=-outline-atomics < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs -mattr=-outline-atomics < %s | FileCheck %s --check-prefix=CHECK-REG
+; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -verify-machineinstrs < %s | FileCheck %s --check-prefix=OUTLINE_ATOMICS
 
 
 ; Point of CHECK-REG is to make sure UNPREDICTABLE instructions aren't created
Index: llvm/test/CodeGen/AArch64/atomic-ops-not-barriers.ll
===
--- llvm/test/CodeGen/AArch64/atomic-ops-not-barriers.ll
+++ llvm/test/CodeGen/AArch64/atomic-ops-not-barriers.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs < %s | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-linux-gnu 

[PATCH] D94224: [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]

2021-01-09 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki updated this revision to Diff 315601.
miyuki edited the summary of this revision.
miyuki added a comment.

Removed alignas


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94224

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp


Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -1461,9 +1461,7 @@
 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
  ArrayRef typeParams,
  SourceLocation rAngleLoc)
-: NumParams(typeParams.size()) {
-  Brackets.Begin = lAngleLoc.getRawEncoding();
-  Brackets.End = rAngleLoc.getRawEncoding();
+: Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) {
   std::copy(typeParams.begin(), typeParams.end(), begin());
 }
 
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -656,20 +656,8 @@
 /// \endcode
 class ObjCTypeParamList final
 : private llvm::TrailingObjects {
-  /// Stores the components of a SourceRange as a POD.
-  struct PODSourceRange {
-unsigned Begin;
-unsigned End;
-  };
-
-  union {
-/// Location of the left and right angle brackets.
-PODSourceRange Brackets;
-
-// Used only for alignment.
-ObjCTypeParamDecl *AlignmentHack;
-  };
-
+  /// Location of the left and right angle brackets.
+  SourceRange Brackets;
   /// The number of parameters in the list, which are tail-allocated.
   unsigned NumParams;
 
@@ -717,17 +705,9 @@
 return *(end() - 1);
   }
 
-  SourceLocation getLAngleLoc() const {
-return SourceLocation::getFromRawEncoding(Brackets.Begin);
-  }
-
-  SourceLocation getRAngleLoc() const {
-return SourceLocation::getFromRawEncoding(Brackets.End);
-  }
-
-  SourceRange getSourceRange() const {
-return SourceRange(getLAngleLoc(), getRAngleLoc());
-  }
+  SourceLocation getLAngleLoc() const { return Brackets.getBegin(); }
+  SourceLocation getRAngleLoc() const { return Brackets.getEnd(); }
+  SourceRange getSourceRange() const { return Brackets; }
 
   /// Gather the default set of type arguments to be substituted for
   /// these type parameters when dealing with an unspecialized type.


Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -1461,9 +1461,7 @@
 ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
  ArrayRef typeParams,
  SourceLocation rAngleLoc)
-: NumParams(typeParams.size()) {
-  Brackets.Begin = lAngleLoc.getRawEncoding();
-  Brackets.End = rAngleLoc.getRawEncoding();
+: Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) {
   std::copy(typeParams.begin(), typeParams.end(), begin());
 }
 
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -656,20 +656,8 @@
 /// \endcode
 class ObjCTypeParamList final
 : private llvm::TrailingObjects {
-  /// Stores the components of a SourceRange as a POD.
-  struct PODSourceRange {
-unsigned Begin;
-unsigned End;
-  };
-
-  union {
-/// Location of the left and right angle brackets.
-PODSourceRange Brackets;
-
-// Used only for alignment.
-ObjCTypeParamDecl *AlignmentHack;
-  };
-
+  /// Location of the left and right angle brackets.
+  SourceRange Brackets;
   /// The number of parameters in the list, which are tail-allocated.
   unsigned NumParams;
 
@@ -717,17 +705,9 @@
 return *(end() - 1);
   }
 
-  SourceLocation getLAngleLoc() const {
-return SourceLocation::getFromRawEncoding(Brackets.Begin);
-  }
-
-  SourceLocation getRAngleLoc() const {
-return SourceLocation::getFromRawEncoding(Brackets.End);
-  }
-
-  SourceRange getSourceRange() const {
-return SourceRange(getLAngleLoc(), getRAngleLoc());
-  }
+  SourceLocation getLAngleLoc() const { return Brackets.getBegin(); }
+  SourceLocation getRAngleLoc() const { return Brackets.getEnd(); }
+  SourceRange getSourceRange() const { return Brackets; }
 
   /// Gather the default set of type arguments to be substituted for
   /// these type parameters when dealing with an unspecialized type.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93873: [clangd] Cache preambles of closed files

2021-01-09 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

New year's ping ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93873

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


[PATCH] D93591: [MLIR][SPIRV] Add (de-)serialization support for SpecConstantOpeation.

2021-01-09 Thread Lei Zhang via Phabricator via cfe-commits
antiagainst requested changes to this revision.
antiagainst added a comment.
This revision now requires changes to proceed.

Awesome! I just have a few nits left now. Marked as blocking because we need to 
avoid change Clang code.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:623
 {"referencesProvider", true},
-{"astProvider", true},
+{"astProvider", true}, // clangd extension
 {"executeCommandProvider",

Accidental change or rebase leftover?

Anyway we need to revert the change here. :)



Comment at: mlir/lib/Target/SPIRV/Deserialization.cpp:557
+  // mapping.
+  DenseMap>>
+  specConstOperationMap;

Just define a `struct` instead of using `std::tuple`? It will make the code 
more readable. Also we should use `SmallVector` instead of `ArrayRef` here. I 
guess ArrayRef is okay because we have access to the underlying SPIR-V blob 
right now; but it can be a potential hazard given ArrayRef does not owns the 
data.



Comment at: mlir/lib/Target/SPIRV/Deserialization.cpp:1811
+  // that there is no need to update this fake ID since we only need to
+  // reference the creaed Value for the enclosed op from the spv::YieldOp
+  // created later in this method (both of which are the only values in their

s/creaed/created/



Comment at: mlir/lib/Target/SPIRV/Deserialization.cpp:1816
+  // previous Value assigned to it isn't visible in the current scope anyway.
+  DenseMap newValueMap;
+  std::swap(valueMap, newValueMap);

What about using `llvm::SaveAndRestore` to avoid manually swap?



Comment at: mlir/lib/Target/SPIRV/Deserialization.cpp:1791
+
+  // Since the enclosed op is emitted in the current block, split it in a
+  // separate new block.

ergawy wrote:
> antiagainst wrote:
> > What about first creating the spec op, set the insertion point to its body 
> > (with proper guard), and then process the transient instruction? This can 
> > avoid us from doing the block manipulation right? Following the above 
> > comment, this is part of swapping the "context".
> If we do this, since the transient instruction has operands that are 
> constants, global vars, or spec constants, then the instructions to 
> materialize these references will be emitted in the spec op's region. This is 
> the main reason I think we need such manipulation here; we first need to 
> materialize all references, if any, in the parent region and then isolate the 
> spec op's enclosed op.
> 
> Let me know if what you are saying is going over my head :D.
You are right. Sorry I left this comment earlier than the comment about 
serializing into `typesGlobalValues`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93591

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


[PATCH] D94231: [clang][Sema] Compare SourceLocations directly [NFCI]

2021-01-09 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f76788b0930: [clang][Sema] Compare SourceLocations directly 
[NFCI] (authored by miyuki).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94231

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaStmt.cpp


Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -672,8 +672,7 @@
 return true;
 
   if (lhs.first == rhs.first &&
-  lhs.second->getCaseLoc().getRawEncoding()
-   < rhs.second->getCaseLoc().getRawEncoding())
+  lhs.second->getCaseLoc() < rhs.second->getCaseLoc())
 return true;
   return false;
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -436,9 +436,7 @@
  Res != ResEnd; ++Res) {
   if (isa(*Res) || isa(*Res) ||
   (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
-if (!IIDecl ||
-(*Res)->getLocation().getRawEncoding() <
-  IIDecl->getLocation().getRawEncoding())
+if (!IIDecl || (*Res)->getLocation() < IIDecl->getLocation())
   IIDecl = *Res;
   }
 }


Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -672,8 +672,7 @@
 return true;
 
   if (lhs.first == rhs.first &&
-  lhs.second->getCaseLoc().getRawEncoding()
-   < rhs.second->getCaseLoc().getRawEncoding())
+  lhs.second->getCaseLoc() < rhs.second->getCaseLoc())
 return true;
   return false;
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -436,9 +436,7 @@
  Res != ResEnd; ++Res) {
   if (isa(*Res) || isa(*Res) ||
   (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
-if (!IIDecl ||
-(*Res)->getLocation().getRawEncoding() <
-  IIDecl->getLocation().getRawEncoding())
+if (!IIDecl || (*Res)->getLocation() < IIDecl->getLocation())
   IIDecl = *Res;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9f76788 - [clang][Sema] Compare SourceLocations directly [NFCI]

2021-01-09 Thread Mikhail Maltsev via cfe-commits

Author: Mikhail Maltsev
Date: 2021-01-09T14:13:18Z
New Revision: 9f76788b0930ed48f5f20a25f1b30d63c8486531

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

LOG: [clang][Sema] Compare SourceLocations directly [NFCI]

The ordered comparison operators are defined for the SourceLocation
class, so SourceLocation objects can be compared directly. There is no
need to extract the internal representation for comparison.

Reviewed By: aprantl

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3a1294ce431f..dd31f3f98487 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -436,9 +436,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo , 
SourceLocation NameLoc,
  Res != ResEnd; ++Res) {
   if (isa(*Res) || isa(*Res) ||
   (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
-if (!IIDecl ||
-(*Res)->getLocation().getRawEncoding() <
-  IIDecl->getLocation().getRawEncoding())
+if (!IIDecl || (*Res)->getLocation() < IIDecl->getLocation())
   IIDecl = *Res;
   }
 }

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index a47fdf625bba..b24a8ab110b2 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -672,8 +672,7 @@ static bool CmpCaseVals(const std::pair& lhs,
 return true;
 
   if (lhs.first == rhs.first &&
-  lhs.second->getCaseLoc().getRawEncoding()
-   < rhs.second->getCaseLoc().getRawEncoding())
+  lhs.second->getCaseLoc() < rhs.second->getCaseLoc())
 return true;
   return false;
 }



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


[PATCH] D93846: [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier

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

In D93846#2488469 , @thezbyg wrote:

> Diff updated. Previous diff was generated after rebase, and Phabricator 
> change preview did not show any unrelated changes, so I thought that 
> everything is fine.

Now your diff removes the stuff?
You should rebase your change on master or main, (ideally) have only one commit 
on top of it, and than diff `HEAD^1`.


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

https://reviews.llvm.org/D93846

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


[PATCH] D94359: [clangd] Remove ScratchFS from tests

2021-01-09 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 315596.
njames93 added a comment.

Fix windows tests failing(hopefully).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94359

Files:
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp

Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -169,48 +169,6 @@
"-DFallback", "-DAdjust_baz.cc"));
 }
 
-// Allows placement of files for tests and cleans them up after.
-// FIXME: GlobalCompilationDatabase is mostly VFS-clean now, switch to MockFS?
-class ScratchFS {
-  llvm::SmallString<128> Root;
-
-public:
-  ScratchFS() {
-EXPECT_FALSE(llvm::sys::fs::createUniqueDirectory("clangd-cdb-test", Root))
-<< "Failed to create unique directory";
-  }
-
-  ~ScratchFS() {
-EXPECT_FALSE(llvm::sys::fs::remove_directories(Root))
-<< "Failed to cleanup " << Root;
-  }
-
-  llvm::StringRef root() const { return Root; }
-
-  void write(PathRef RelativePath, llvm::StringRef Contents) {
-std::string AbsPath = path(RelativePath);
-EXPECT_FALSE(llvm::sys::fs::create_directories(
-llvm::sys::path::parent_path(AbsPath)))
-<< "Failed to create directories for: " << AbsPath;
-
-std::error_code EC;
-llvm::raw_fd_ostream OS(AbsPath, EC);
-EXPECT_FALSE(EC) << "Failed to open " << AbsPath << " for writing";
-OS << llvm::formatv(Contents.data(),
-llvm::sys::path::convert_to_slash(Root));
-OS.close();
-
-EXPECT_FALSE(OS.has_error());
-  }
-
-  std::string path(PathRef RelativePath) const {
-llvm::SmallString<128> AbsPath(Root);
-llvm::sys::path::append(AbsPath, RelativePath);
-llvm::sys::path::native(AbsPath);
-return AbsPath.str().str();
-  }
-};
-
 TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
   const char *const CDBOuter =
   R"cdb(
@@ -242,34 +200,35 @@
 }
   ]
   )cdb";
-  ScratchFS FS;
-  RealThreadsafeFS TFS;
-  FS.write("compile_commands.json", CDBOuter);
-  FS.write("build/compile_commands.json", CDBInner);
+  MockFS FS;
+  FS.Files[testPath("compile_commands.json")] =
+  llvm::formatv(CDBOuter, llvm::sys::path::convert_to_slash(testRoot()));
+  FS.Files[testPath("build/compile_commands.json")] =
+  llvm::formatv(CDBInner, llvm::sys::path::convert_to_slash(testRoot()));
 
   // Note that gen2.cc goes missing with our following model, not sure this
   // happens in practice though.
   {
-DirectoryBasedGlobalCompilationDatabase DB(TFS);
+DirectoryBasedGlobalCompilationDatabase DB(FS);
 std::vector DiscoveredFiles;
 auto Sub =
 DB.watch([](const std::vector Changes) {
   DiscoveredFiles = Changes;
 });
 
-DB.getCompileCommand(FS.path("build/../a.cc"));
+DB.getCompileCommand(testPath("build/../a.cc"));
 EXPECT_THAT(DiscoveredFiles, UnorderedElementsAre(AllOf(
  EndsWith("a.cc"), Not(HasSubstr("..");
 DiscoveredFiles.clear();
 
-DB.getCompileCommand(FS.path("build/gen.cc"));
+DB.getCompileCommand(testPath("build/gen.cc"));
 EXPECT_THAT(DiscoveredFiles, UnorderedElementsAre(EndsWith("gen.cc")));
   }
 
   // With a custom compile commands dir.
   {
-DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
-Opts.CompileCommandsDir = FS.root().str();
+DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
+Opts.CompileCommandsDir = testRoot();
 DirectoryBasedGlobalCompilationDatabase DB(Opts);
 std::vector DiscoveredFiles;
 auto Sub =
@@ -277,24 +236,23 @@
   DiscoveredFiles = Changes;
 });
 
-DB.getCompileCommand(FS.path("a.cc"));
+DB.getCompileCommand(testPath("a.cc"));
 EXPECT_THAT(DiscoveredFiles,
 UnorderedElementsAre(EndsWith("a.cc"), EndsWith("gen.cc"),
  EndsWith("gen2.cc")));
 DiscoveredFiles.clear();
 
-DB.getCompileCommand(FS.path("build/gen.cc"));
+DB.getCompileCommand(testPath("build/gen.cc"));
 EXPECT_THAT(DiscoveredFiles, IsEmpty());
   }
 }
 
 TEST(GlobalCompilationDatabaseTest, BuildDir) {
-  ScratchFS FS;
-  RealThreadsafeFS TFS;
+  MockFS FS;
   auto Command = [&](llvm::StringRef Relative) {
-DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
 return DirectoryBasedGlobalCompilationDatabase(Opts)
-.getCompileCommand(FS.path(Relative))
+.getCompileCommand(testPath(Relative))
 .getValueOr(tooling::CompileCommand())
 .CommandLine;
   };
@@ -314,7 +272,9 @@
 }
   ]
   )cdb";
-  

[PATCH] D94359: [clangd] Remove ScratchFS from tests

2021-01-09 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: adamcz, hokein, sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

This can lead to issues if files in the tmp directory we don't care about / 
control are found.
This was partially addressed in D94321 , but 
this is a more permanent fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94359

Files:
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp

Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -169,48 +169,6 @@
"-DFallback", "-DAdjust_baz.cc"));
 }
 
-// Allows placement of files for tests and cleans them up after.
-// FIXME: GlobalCompilationDatabase is mostly VFS-clean now, switch to MockFS?
-class ScratchFS {
-  llvm::SmallString<128> Root;
-
-public:
-  ScratchFS() {
-EXPECT_FALSE(llvm::sys::fs::createUniqueDirectory("clangd-cdb-test", Root))
-<< "Failed to create unique directory";
-  }
-
-  ~ScratchFS() {
-EXPECT_FALSE(llvm::sys::fs::remove_directories(Root))
-<< "Failed to cleanup " << Root;
-  }
-
-  llvm::StringRef root() const { return Root; }
-
-  void write(PathRef RelativePath, llvm::StringRef Contents) {
-std::string AbsPath = path(RelativePath);
-EXPECT_FALSE(llvm::sys::fs::create_directories(
-llvm::sys::path::parent_path(AbsPath)))
-<< "Failed to create directories for: " << AbsPath;
-
-std::error_code EC;
-llvm::raw_fd_ostream OS(AbsPath, EC);
-EXPECT_FALSE(EC) << "Failed to open " << AbsPath << " for writing";
-OS << llvm::formatv(Contents.data(),
-llvm::sys::path::convert_to_slash(Root));
-OS.close();
-
-EXPECT_FALSE(OS.has_error());
-  }
-
-  std::string path(PathRef RelativePath) const {
-llvm::SmallString<128> AbsPath(Root);
-llvm::sys::path::append(AbsPath, RelativePath);
-llvm::sys::path::native(AbsPath);
-return AbsPath.str().str();
-  }
-};
-
 TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
   const char *const CDBOuter =
   R"cdb(
@@ -242,34 +200,35 @@
 }
   ]
   )cdb";
-  ScratchFS FS;
-  RealThreadsafeFS TFS;
-  FS.write("compile_commands.json", CDBOuter);
-  FS.write("build/compile_commands.json", CDBInner);
+  MockFS FS;
+  FS.Files[testPath("compile_commands.json")] =
+  llvm::formatv(CDBOuter, testRoot()).str();
+  FS.Files[testPath("build/compile_commands.json")] =
+  llvm::formatv(CDBInner, testRoot()).str();
 
   // Note that gen2.cc goes missing with our following model, not sure this
   // happens in practice though.
   {
-DirectoryBasedGlobalCompilationDatabase DB(TFS);
+DirectoryBasedGlobalCompilationDatabase DB(FS);
 std::vector DiscoveredFiles;
 auto Sub =
 DB.watch([](const std::vector Changes) {
   DiscoveredFiles = Changes;
 });
 
-DB.getCompileCommand(FS.path("build/../a.cc"));
+DB.getCompileCommand(testPath("build/../a.cc"));
 EXPECT_THAT(DiscoveredFiles, UnorderedElementsAre(AllOf(
  EndsWith("a.cc"), Not(HasSubstr("..");
 DiscoveredFiles.clear();
 
-DB.getCompileCommand(FS.path("build/gen.cc"));
+DB.getCompileCommand(testPath("build/gen.cc"));
 EXPECT_THAT(DiscoveredFiles, UnorderedElementsAre(EndsWith("gen.cc")));
   }
 
   // With a custom compile commands dir.
   {
-DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
-Opts.CompileCommandsDir = FS.root().str();
+DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
+Opts.CompileCommandsDir = testRoot();
 DirectoryBasedGlobalCompilationDatabase DB(Opts);
 std::vector DiscoveredFiles;
 auto Sub =
@@ -277,24 +236,23 @@
   DiscoveredFiles = Changes;
 });
 
-DB.getCompileCommand(FS.path("a.cc"));
+DB.getCompileCommand(testPath("a.cc"));
 EXPECT_THAT(DiscoveredFiles,
 UnorderedElementsAre(EndsWith("a.cc"), EndsWith("gen.cc"),
  EndsWith("gen2.cc")));
 DiscoveredFiles.clear();
 
-DB.getCompileCommand(FS.path("build/gen.cc"));
+DB.getCompileCommand(testPath("build/gen.cc"));
 EXPECT_THAT(DiscoveredFiles, IsEmpty());
   }
 }
 
 TEST(GlobalCompilationDatabaseTest, BuildDir) {
-  ScratchFS FS;
-  RealThreadsafeFS TFS;
+  MockFS FS;
   auto Command = [&](llvm::StringRef Relative) {
-DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
 return 

[PATCH] D93347: [Test] Fix undef var in attr-speculative-load-hardening.c

2021-01-09 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93347

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


[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2021-01-09 Thread sameeran joshi via Phabricator via cfe-commits
sameeranjoshi added inline comments.



Comment at: flang/test/Flang-Driver/driver-help.f90:22
 ! HELP-NEXT: -###   Print (but do not run) the commands to run 
for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  
omitted)
 ! HELP-NEXT: -E Only run the preprocessor

I see below crash report, when omitting the  but not omitting the `=` 
symbol.
Not sure if that's correct way of running hence instead of filing bug reporting 
here.

```
./bin/flang-new -E -DX= test.f90
```

```
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
Stack dump:
0.  Program arguments: 
/home/amd/f18_git/final_test/driver_build/bin/flang-new -fc1 -E -D X= -o - 
test.f90
 #0 0x7f26185d0bc1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a4bc1)
 #1 0x7f26185ce9a4 llvm::sys::RunSignalHandlers() 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a29a4)
 #2 0x7f26185ceb10 SignalHandler(int) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a2b10)
 #3 0x7f2617749470 (/lib/x86_64-linux-gnu/libc.so.6+0x46470)
 #4 0x7f2617443498 
Fortran::parser::OffsetToProvenanceMappings::Map(unsigned long) const 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x571498)
 #5 0x7f261744adf2 Fortran::parser::TokenSequence::GetProvenanceRange() 
const 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x578df2)
 #6 0x7f26173dd334 
Fortran::parser::Preprocessor::MacroReplacement(Fortran::parser::TokenSequence 
const&, Fortran::parser::Prescanner&) (.localalias) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50b334)
 #7 0x7f26173e9dc1 Fortran::parser::Prescanner::Statement() (.localalias) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x517dc1)
 #8 0x7f26173ea888 
Fortran::parser::Prescanner::Prescan(Fortran::common::Interval)
 (.localalias) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x51)
 #9 0x7f26173d480b 
Fortran::parser::Parsing::Prescan(std::__cxx11::basic_string, std::allocator > const&, 
Fortran::parser::Options) 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50280b)
#10 0x7f2618424ddd Fortran::frontend::FrontendAction::Execute() 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x)
#11 0x7f261841fa5e 
Fortran::frontend::CompilerInstance::ExecuteAction(Fortran::frontend::FrontendAction&)
 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x8a5e)
#12 0x7f26184132fc 
Fortran::frontend::ExecuteCompilerInvocation(Fortran::frontend::CompilerInstance*)
 
(/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontendTool.so.12git+0x12fc)
#13 0x55bad4081c20 fc1_main(llvm::ArrayRef, char const*) 
(/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x3c20)
#14 0x55bad4080e59 main 
(/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2e59)
#15 0x7f261772a1e3 __libc_start_main 
/build/glibc-5mDdLG/glibc-2.30/csu/../csu/libc-start.c:342:3
#16 0x55bad4080eae _start 
(/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2eae)
flang-new: error: unable to execute command: Segmentation fault (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see 
invocation)
flang-new version 12.0.0 (https://github.com/llvm/llvm-project.git 
2f9cb090cc6db1be5bf524eb0a32537503b3e786)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/amd/f18_git/final_test/driver_build/bin
flang-new: note: diagnostic msg: Error generating preprocessed source(s) - no 
preprocessable inputs.

```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93401

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


[PATCH] D93846: [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier

2021-01-09 Thread Albertas Vyšniauskas via Phabricator via cfe-commits
thezbyg updated this revision to Diff 315578.
thezbyg added a comment.

Diff updated. Previous diff was generated after rebase, and Phabricator change 
preview did not show any unrelated changes, so I thought that everything is 
fine.


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

https://reviews.llvm.org/D93846

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/test/Format/access-modifiers.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8540,6 +8540,292 @@
getLLVMStyle());
 }
 
+TEST_F(FormatTest, FormatsAccessModifiers) {
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n");
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "private:\n"
+   "  int i;\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n");
+  verifyFormat("struct foo { /* comment */\n"
+   "private:\n"
+   "  int i;\n"
+   "  // comment\n"
+   "private:\n"
+   "  int j;\n"
+   "};\n");
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#endif\n"
+   "private:\n"
+   "  int i;\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "#endif\n"
+   "  int j;\n"
+   "};\n");
+  FormatStyle Style = getLLVMStyle();
+  Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Never;
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "private:\n"
+   "  int i;\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "private:\n"
+   "  int i;\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct foo { /* comment */\n"
+   "private:\n"
+   "  int i;\n"
+   "  // comment\n"
+   "private:\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo { /* comment */\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "  // comment\n"
+   "\n"
+   "private:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct foo {\n"
+   "#ifdef FOO\n"
+   "#endif\n"
+   "private:\n"
+   "  int i;\n"
+   "#ifdef FOO\n"
+   "private:\n"
+   "#endif\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "#ifdef FOO\n"
+   "#endif\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "#ifdef FOO\n"
+   "\n"
+   "private:\n"
+   "#endif\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+  Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Always;
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "private:\n"
+ 

[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:11
+// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", 
scope: {{.*}}, file: [[FILE]]
+// CHECK: {{.*}} = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]]
+

The behavior is default triple dependent. `*-windows-msvc` triples use 
different static constructor mechanism. I fixed the test by adding `-triple 
%itanium_abi_triple`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87147

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


[clang] 052b8fe - Fix CodeGenCXX/difile_entry.cpp on Windows

2021-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-01-09T00:46:02-08:00
New Revision: 052b8fe478194018944eac944af7ca853ec3ced7

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

LOG: Fix CodeGenCXX/difile_entry.cpp on Windows

Added: 


Modified: 
clang/test/CodeGenCXX/difile_entry.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/difile_entry.cpp 
b/clang/test/CodeGenCXX/difile_entry.cpp
index 9ef80fe8184c..1ae36e4355ce 100644
--- a/clang/test/CodeGenCXX/difile_entry.cpp
+++ b/clang/test/CodeGenCXX/difile_entry.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir -p %t/test_dir
 // RUN: cd %t/test_dir
 // RUN: cp %s .
-// RUN: %clang_cc1 -main-file-name difile_entry.cpp  -debug-info-kind=limited 
../test_dir/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck  
../test_dir/difile_entry.cpp
+// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name 
difile_entry.cpp -debug-info-kind=limited ../test_dir/difile_entry.cpp 
-std=c++11 -emit-llvm -o - | FileCheck  ../test_dir/difile_entry.cpp
 int x();
 static int i = x();
 



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


[PATCH] D94217: [clang-format] Find main include after block ended with #pragma hdrstop

2021-01-09 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius 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/D94217/new/

https://reviews.llvm.org/D94217

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


[PATCH] D92714: Make -fno-pic respect -fno-direct-access-external-data

2021-01-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38a716c30f09: Make -fno-pic respect 
-fno-direct-access-external-data (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92714

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/dso-local-executable.c


Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -20,7 +20,10 @@
 // MINGW-DAG: define dso_local i32* @zed()
 // MINGW-DAG: declare dllimport void @import_func()
 
+/// Static relocation model defaults to -fdirect-access-external-data and sets
+/// dso_local on most global objects.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - 
| FileCheck --check-prefix=STATIC %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
 // STATIC:  @baz = dso_local global i32 42
 // STATIC-NEXT: @import_var = external dso_local global i32
 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
@@ -31,6 +34,19 @@
 // STATIC-DAG: define dso_local i32* @zed()
 // STATIC-DAG: declare dso_local void @import_func()
 
+/// If -fno-direct-access-external-data is set, drop dso_local from global 
variable
+/// declarations.
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static 
-fno-direct-access-external-data -o - | FileCheck 
--check-prefix=STATIC-INDIRECT %s
+// STATIC-INDIRECT:  @baz = dso_local global i32 42
+// STATIC-INDIRECT-NEXT: @import_var = external global i32
+// STATIC-INDIRECT-NEXT: @weak_bar = extern_weak global i32
+// STATIC-INDIRECT-NEXT: @bar = external global i32
+// STATIC-INDIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 
42
+// STATIC-INDIRECT-NEXT: @thread_var = external thread_local global i32
+// STATIC-INDIRECT-DAG:  declare dso_local void @import_func()
+// STATIC-INDIRECT-DAG:  define dso_local i32* @zed()
+// STATIC-INDIRECT-DAG:  declare dso_local void @foo()
+
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - 
| FileCheck --check-prefix=PIE %s
 // PIE:  @baz = dso_local global i32 42
 // PIE-NEXT: @import_var = external global i32
@@ -87,7 +103,9 @@
 // PIE-NO-PLT-DAG:  define dso_local i32* @zed()
 // PIE-NO-PLT-DAG:  declare void @foo()
 
+/// -fdirect-access-external-data is currently ignored for -fPIC.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 %s -o - | FileCheck 
--check-prefix=SHARED %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=SHARED %s
 // SHARED-DAG: @bar = external global i32
 // SHARED-DAG: @weak_bar = extern_weak global i32
 // SHARED-DAG: declare void @foo()
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -985,8 +985,7 @@
 
   // If we can use copy relocations we can assume it is local.
   if (auto *Var = dyn_cast(GV))
-if (!Var->isThreadLocal() &&
-(RM == llvm::Reloc::Static || CGOpts.DirectAccessExternalData))
+if (!Var->isThreadLocal() && CGOpts.DirectAccessExternalData)
   return true;
 
   // If we can use a plt entry as the symbol address we can assume it


Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -20,7 +20,10 @@
 // MINGW-DAG: define dso_local i32* @zed()
 // MINGW-DAG: declare dllimport void @import_func()
 
+/// Static relocation model defaults to -fdirect-access-external-data and sets
+/// dso_local on most global objects.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - | FileCheck --check-prefix=STATIC %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static -fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
 // STATIC:  @baz = dso_local global i32 42
 // STATIC-NEXT: @import_var = external dso_local global i32
 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
@@ -31,6 +34,19 @@
 // STATIC-DAG: define dso_local i32* @zed()
 // STATIC-DAG: declare dso_local void @import_func()
 
+/// If -fno-direct-access-external-data is set, drop dso_local from global variable
+/// declarations.
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static -fno-direct-access-external-data -o - | FileCheck --check-prefix=STATIC-INDIRECT %s
+// 

[PATCH] D92633: Add -f[no-]direct-access-external-data to supersede -mpie-copy-relocations

2021-01-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d3ebbf53783: Add -f[no-]direct-access-external-data to 
supersede -mpie-copy-relocations (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D92633?vs=309456=315576#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92633

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/dso-local-executable.c
  clang/test/Driver/fdirect-access-external-data.c

Index: clang/test/Driver/fdirect-access-external-data.c
===
--- /dev/null
+++ clang/test/Driver/fdirect-access-external-data.c
@@ -0,0 +1,18 @@
+/// -fno-pic code defaults to -fdirect-access-external-data.
+// RUN: %clang -### -c -target x86_64 %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c -target x86_64 %s -fdirect-access-external-data 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c -target x86_64 %s -fdirect-access-external-data -fno-direct-access-external-data 2>&1 | FileCheck %s --check-prefix=INDIRECT
+
+/// -fpie/-fpic code defaults to -fdirect-access-external-data.
+// RUN: %clang -### -c -target x86_64 %s -fpie 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c -target x86_64 %s -fpie -fno-direct-access-external-data -fdirect-access-external-data 2>&1 | FileCheck %s --check-prefix=DIRECT
+// RUN: %clang -### -c -target aarch64 %s -fpic 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c -target aarch64 %s -fpic -fdirect-access-external-data 2>&1 | FileCheck %s --check-prefix=DIRECT
+
+/// -m[no-]pie-copy-relocations are aliases for compatibility.
+// RUN: %clang -### -c -target riscv64 %s -mno-pie-copy-relocations 2>&1 | FileCheck %s --check-prefix=INDIRECT
+// RUN: %clang -### -c -target riscv64 %s -fpic -mpie-copy-relocations 2>&1 | FileCheck %s --check-prefix=DIRECT
+
+// DEFAULT-NOT: direct-access-external-data"
+// DIRECT:  "-fdirect-access-external-data"
+// INDIRECT:"-fno-direct-access-external-data"
Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -42,7 +42,7 @@
 // PIE-DAG: define dso_local i32* @zed()
 // PIE-DAG: declare void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -mpie-copy-relocations %s -o - | FileCheck --check-prefix=PIE-DIRECT %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -fdirect-access-external-data %s -o - | FileCheck --check-prefix=PIE-DIRECT %s
 // PIE-DIRECT:  @baz = dso_local global i32 42
 // PIE-DIRECT-NEXT: @import_var = external dso_local global i32
 // PIE-DIRECT-NEXT: @weak_bar = extern_weak global i32
@@ -64,7 +64,7 @@
 // NOPLT-DAG: define dso_local i32* @zed()
 // NOPLT-DAG: declare void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64 -emit-llvm -fno-plt -pic-level 1 -pic-is-pie -mpie-copy-relocations %s -o - | FileCheck --check-prefix=PIE-DIRECT-NOPLT %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -fno-plt -pic-level 1 -pic-is-pie -fdirect-access-external-data %s -o - | FileCheck --check-prefix=PIE-DIRECT-NOPLT %s
 // PIE-DIRECT-NOPLT:  @baz = dso_local global i32 42
 // PIE-DIRECT-NOPLT-NEXT: @import_var = external dso_local global i32
 // PIE-DIRECT-NOPLT-NEXT: @weak_bar = extern_weak global i32
@@ -75,7 +75,7 @@
 // PIE-DIRECT-NOPLT-DAG: define dso_local i32* @zed()
 // PIE-DIRECT-NOPLT-DAG: declare void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-is-pie -fno-plt %s -o - | FileCheck --check-prefix=PIE-NO-PLT %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -fno-plt %s -o - | FileCheck --check-prefix=PIE-NO-PLT %s
 // RUN: %clang_cc1 -triple powerpc64le -emit-llvm -mrelocation-model static %s -o - | FileCheck --check-prefix=PIE-NO-PLT %s
 // PIE-NO-PLT:  @baz = dso_local global i32 42
 // PIE-NO-PLT-NEXT: @import_var = external global i32
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -942,6 +942,13 @@
 }
   }
 
+  // PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
+  // -fdirect-access-external-data.
+  Opts.DirectAccessExternalData =
+  Args.hasArg(OPT_fdirect_access_external_data) ||
+  (!Args.hasArg(OPT_fno_direct_access_external_data) &&
+   getLastArgIntValue(Args, OPT_pic_level, 0, Diags) == 0);
+
   // If -fuse-ctor-homing is 

[clang] 38a716c - Make -fno-pic respect -fno-direct-access-external-data

2021-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-01-09T00:32:02-08:00
New Revision: 38a716c30f095c7d7148482070ea4a3352b926d5

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

LOG: Make -fno-pic respect -fno-direct-access-external-data

D92633 added -f[no-]direct-access-external-data to supersede 
-m[no-]pie-copy-relocations.
(The option works for -fpie but is a no-op for -fno-pic and -fpic.)

This patch makes -fno-pic -fno-direct-access-external-data drop dso_local from
global variable declarations. This usually causes the backend to emit a GOT
indirection for external data access. With a GOT relocation, the subsequent
-no-pie link will not have copy relocation even if the data symbol turns out to
be defined by a shared object.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/dso-local-executable.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 959f149667d9..85b5009dce7e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -985,8 +985,7 @@ static bool shouldAssumeDSOLocal(const CodeGenModule ,
 
   // If we can use copy relocations we can assume it is local.
   if (auto *Var = dyn_cast(GV))
-if (!Var->isThreadLocal() &&
-(RM == llvm::Reloc::Static || CGOpts.DirectAccessExternalData))
+if (!Var->isThreadLocal() && CGOpts.DirectAccessExternalData)
   return true;
 
   // If we can use a plt entry as the symbol address we can assume it

diff  --git a/clang/test/CodeGen/dso-local-executable.c 
b/clang/test/CodeGen/dso-local-executable.c
index 5c5c6f59c09c..19930b068218 100644
--- a/clang/test/CodeGen/dso-local-executable.c
+++ b/clang/test/CodeGen/dso-local-executable.c
@@ -20,7 +20,10 @@
 // MINGW-DAG: define dso_local i32* @zed()
 // MINGW-DAG: declare dllimport void @import_func()
 
+/// Static relocation model defaults to -fdirect-access-external-data and sets
+/// dso_local on most global objects.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - 
| FileCheck --check-prefix=STATIC %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
 // STATIC:  @baz = dso_local global i32 42
 // STATIC-NEXT: @import_var = external dso_local global i32
 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
@@ -31,6 +34,19 @@
 // STATIC-DAG: define dso_local i32* @zed()
 // STATIC-DAG: declare dso_local void @import_func()
 
+/// If -fno-direct-access-external-data is set, drop dso_local from global 
variable
+/// declarations.
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static 
-fno-direct-access-external-data -o - | FileCheck 
--check-prefix=STATIC-INDIRECT %s
+// STATIC-INDIRECT:  @baz = dso_local global i32 42
+// STATIC-INDIRECT-NEXT: @import_var = external global i32
+// STATIC-INDIRECT-NEXT: @weak_bar = extern_weak global i32
+// STATIC-INDIRECT-NEXT: @bar = external global i32
+// STATIC-INDIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 
42
+// STATIC-INDIRECT-NEXT: @thread_var = external thread_local global i32
+// STATIC-INDIRECT-DAG:  declare dso_local void @import_func()
+// STATIC-INDIRECT-DAG:  define dso_local i32* @zed()
+// STATIC-INDIRECT-DAG:  declare dso_local void @foo()
+
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - 
| FileCheck --check-prefix=PIE %s
 // PIE:  @baz = dso_local global i32 42
 // PIE-NEXT: @import_var = external global i32
@@ -87,7 +103,9 @@
 // PIE-NO-PLT-DAG:  define dso_local i32* @zed()
 // PIE-NO-PLT-DAG:  declare void @foo()
 
+/// -fdirect-access-external-data is currently ignored for -fPIC.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 %s -o - | FileCheck 
--check-prefix=SHARED %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=SHARED %s
 // SHARED-DAG: @bar = external global i32
 // SHARED-DAG: @weak_bar = extern_weak global i32
 // SHARED-DAG: declare void @foo()



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


[clang] 1d3ebbf - Add -f[no-]direct-access-external-data to supersede -mpie-copy-relocations

2021-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-01-09T00:32:01-08:00
New Revision: 1d3ebbf537832f80be97739abc4f6962caad1dab

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

LOG: Add -f[no-]direct-access-external-data to supersede -mpie-copy-relocations

GCC r218397 "x86-64: Optimize access to globals in PIE with copy reloc" made
-fpie code emit R_X86_64_PC32 to reference external data symbols by default.
Clang adopted -mpie-copy-relocations D19996 as a flexible alternative.

The name -mpie-copy-relocations can be improved [1] and does not capture the
idea that this option can apply to -fno-pic and -fpic [2], so this patch
introduces -f[no-]direct-access-external-data and makes -mpie-copy-relocations
their aliases for compatibility.

[1]
For
```
extern int var;
int get() { return var; }
```
if var is defined in another translation unit in the link unit, there is no copy
relocation.

[2]
-fno-pic -fno-direct-access-external-data is useful to avoid copy relocations.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65888
If a shared object is linked with -Bsymbolic or --dynamic-list and exports a
data symbol, normally the data symbol cannot be accessed by -fno-pic code
(because by default an absolute relocation is produced which will lead to a copy
relocation). -fno-direct-access-external-data can prevent copy relocations.

-fpic -fdirect-access-external-data can avoid GOT indirection. This is like the
undefined counterpart of -fno-semantic-interposition. However, the user should
define var in another translation unit and link with -Bsymbolic or
--dynamic-list, otherwise the linker will error in a -shared link. Generally
the user has better tools for their goal but I want to mention that this
combination is valid.

On COFF, the behavior is like always -fdirect-access-external-data.
`__declspec(dllimport)` is needed to enable indirect access.

There is currently no plan to affect non-ELF behaviors or -fpic behaviors.

-fno-pic -fno-direct-access-external-data will be implemented in the subsequent 
patch.

GCC feature request https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98112

Reviewed By: tmsriram

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

Added: 
clang/test/Driver/fdirect-access-external-data.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/dso-local-executable.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d3851df23122..5c8af65326ed 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -368,8 +368,8 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0)
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
-/// Whether copy relocations support is available when building as PIE.
-CODEGENOPT(PIECopyRelocations, 1, 0)
+/// Whether to use direct access relocations (instead of GOT) to reference 
external data symbols.
+CODEGENOPT(DirectAccessExternalData, 1, 0)
 
 /// Whether we should use the undefined behaviour optimization for control flow
 /// paths that reach the end of a function without executing a required return.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9e1059cd14f0..741c28aa1f01 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2184,6 +2184,10 @@ def fpic : Flag<["-"], "fpic">, Group;
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fdirect_access_external_data : Flag<["-"], 
"fdirect-access-external-data">, Group, Flags<[CC1Option]>,
+  HelpText<"Don't use GOT indirection to reference external data symbols">;
+def fno_direct_access_external_data : Flag<["-"], 
"fno-direct-access-external-data">, Group, Flags<[CC1Option]>,
+  HelpText<"Use GOT indirection to reference external data symbols">;
 defm plt : BoolFOption<"plt",
   "CodeGenOpts.NoPLT", DefaultsToFalse,
   ChangedBy,
@@ -3151,10 +3155,10 @@ def mstack_protector_guard_offset_EQ : Joined<["-"], 
"mstack-protector-guard-off
   HelpText<"Use the given offset for addressing the stack-protector guard">;
 def mstack_protector_guard_reg_EQ : Joined<["-"], 
"mstack-protector-guard-reg=">, Group, Flags<[CC1Option]>,
   HelpText<"Use the given reg for addressing the stack-protector guard">;
-defm pie_copy_relocations : BoolOption<"pie-copy-relocations",
-  "CodeGenOpts.PIECopyRelocations", DefaultsToFalse,
-  ChangedBy,
-  

[PATCH] D92714: Make -fno-pic respect -fno-direct-access-external-data

2021-01-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 315575.
MaskRay added a comment.

Improve tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92714

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/dso-local-executable.c


Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -20,7 +20,10 @@
 // MINGW-DAG: define dso_local i32* @zed()
 // MINGW-DAG: declare dllimport void @import_func()
 
+/// Static relocation model defaults to -fdirect-access-external-data and sets
+/// dso_local on most global objects.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - 
| FileCheck --check-prefix=STATIC %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
 // STATIC:  @baz = dso_local global i32 42
 // STATIC-NEXT: @import_var = external dso_local global i32
 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
@@ -31,6 +34,19 @@
 // STATIC-DAG: define dso_local i32* @zed()
 // STATIC-DAG: declare dso_local void @import_func()
 
+/// If -fno-direct-access-external-data is set, drop dso_local from global 
variable
+/// declarations.
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static 
-fno-direct-access-external-data -o - | FileCheck 
--check-prefix=STATIC-INDIRECT %s
+// STATIC-INDIRECT:  @baz = dso_local global i32 42
+// STATIC-INDIRECT-NEXT: @import_var = external global i32
+// STATIC-INDIRECT-NEXT: @weak_bar = extern_weak global i32
+// STATIC-INDIRECT-NEXT: @bar = external global i32
+// STATIC-INDIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 
42
+// STATIC-INDIRECT-NEXT: @thread_var = external thread_local global i32
+// STATIC-INDIRECT-DAG:  declare dso_local void @import_func()
+// STATIC-INDIRECT-DAG:  define dso_local i32* @zed()
+// STATIC-INDIRECT-DAG:  declare dso_local void @foo()
+
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - 
| FileCheck --check-prefix=PIE %s
 // PIE:  @baz = dso_local global i32 42
 // PIE-NEXT: @import_var = external global i32
@@ -87,7 +103,9 @@
 // PIE-NO-PLT-DAG:  define dso_local i32* @zed()
 // PIE-NO-PLT-DAG:  declare void @foo()
 
+/// -fdirect-access-external-data is currently ignored for -fPIC.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 %s -o - | FileCheck 
--check-prefix=SHARED %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 
-fdirect-access-external-data %s -o - | FileCheck --check-prefix=SHARED %s
 // SHARED-DAG: @bar = external global i32
 // SHARED-DAG: @weak_bar = extern_weak global i32
 // SHARED-DAG: declare void @foo()
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -985,8 +985,7 @@
 
   // If we can use copy relocations we can assume it is local.
   if (auto *Var = dyn_cast(GV))
-if (!Var->isThreadLocal() &&
-(RM == llvm::Reloc::Static || CGOpts.DirectAccessExternalData))
+if (!Var->isThreadLocal() && CGOpts.DirectAccessExternalData)
   return true;
 
   // If we can use a plt entry as the symbol address we can assume it


Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -20,7 +20,10 @@
 // MINGW-DAG: define dso_local i32* @zed()
 // MINGW-DAG: declare dllimport void @import_func()
 
+/// Static relocation model defaults to -fdirect-access-external-data and sets
+/// dso_local on most global objects.
 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - | FileCheck --check-prefix=STATIC %s
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static -fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
 // STATIC:  @baz = dso_local global i32 42
 // STATIC-NEXT: @import_var = external dso_local global i32
 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
@@ -31,6 +34,19 @@
 // STATIC-DAG: define dso_local i32* @zed()
 // STATIC-DAG: declare dso_local void @import_func()
 
+/// If -fno-direct-access-external-data is set, drop dso_local from global variable
+/// declarations.
+// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static -fno-direct-access-external-data -o - | FileCheck --check-prefix=STATIC-INDIRECT %s
+// STATIC-INDIRECT:  @baz = dso_local global i32 42
+// STATIC-INDIRECT-NEXT: @import_var = external global i32
+// STATIC-INDIRECT-NEXT: @weak_bar = extern_weak global i32
+// STATIC-INDIRECT-NEXT: @bar = external global i32
+//