[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 292416.
gamesh411 marked 2 inline comments as done.
gamesh411 added a comment.

Add abort and terminate handling
Extend tests to cover every exit functions
Extract matcher bind labels


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c-teminate.cpp
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
@@ -19,6 +19,7 @@
 "CommandProcessorCheck.cpp",
 "DefaultOperatorNewAlignmentCheck.cpp",
 "DontModifyStdNamespaceCheck.cpp",
+"ExitHandlerCheck.cpp",
 "FloatLoopCounter.cpp",
 "LimitedRandomnessCheck.cpp",
 "MutatingCopyCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
@@ -0,0 +1,412 @@
+// Test as a C file.
+// RUN: %check_clang_tidy %s cert-env32-c %t -- -- -DCMODE
+//
+// Test as a C++ file.
+//
+// Test functions in global namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE
+//
+// Test functions in std namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE -DTEST_NS_NAME=std
+
+#if defined(CPPMODE) && defined(TEST_NS_NAME)
+namespace TEST_NS_NAME {
+#endif
+
+// --
+// EXIT FUNCTIONS
+// --
+
+// No handlers are invoked when _Exit is called.
+void _Exit(int __status);
+
+// Handlers registered by atexit are invoked in reverse order when exit is
+// called.
+void exit(int __status);
+
+// Handlers registered by at_quick_exit are invoked in reverse order when
+// quick_exit is called.
+void quick_exit(int __status);
+
+// The program is terminated without destroying any object and without calling
+// any of the functions passed to atexit or at_quick_exit.
+void abort();
+
+// 
+// HANDLER REGISTRATION
+// 
+
+// Register handlers to run when exit is called.
+int atexit(void (*__func)(void));
+
+// Register handlers to run when exit is called.
+int at_quick_exit(void (*__func)(void));
+
+// --
+// Setjmp/longjmp
+// --
+// C99 requires jmp_buf to be an array type.
+typedef int jmp_buf[1];
+int setjmp(jmp_buf);
+void longjmp(jmp_buf, int);
+
+// Compliant solutions
+
+void cleanup1() {
+  // do cleanup
+}
+
+void cleanup2() {
+  // do cleanup
+}
+
+void test_atexit_single_compliant() {
+  (void)atexit(cleanup1);
+}
+
+void test_atexit_multiple_compliant() {
+  (void)atexit(cleanup1);
+  (void)atexit(cleanup2);
+}
+
+void test_at_quick_exit_single_compliant() {
+  (void)at_quick_exit(cleanup1);
+}
+
+void test_at_quick_exit_multiple_compliant() {
+  (void)at_quick_exit(cleanup1);
+  (void)at_quick_exit(cleanup2);
+}
+
+// Non-compliant solutions calling _Exit
+
+void call__Exit() {
+  _Exit(0);
+}
+
+void call_call__Exit() {
+  call__Exit();
+}
+
+extern int unknown__Exit_flag;
+
+void call__Exit_conditionally() {
+  if (unknown__Exit_flag)
+call__Exit();
+}
+
+void call_call__Exit_conditionally() {
+  call__Exit_conditionally();
+}
+
+void test__Exit_called_directly() {
+  (void)atexit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-22]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-22]]:3: note: exit function called here
+  (void)at_quick_exit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-26]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-26]]:3: note: exit function called here
+};
+
+void test__Exit_called_indirectly() {
+  (void)atexit(call_call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-29]]:1: note: handler function declared here
+  // CHE

[PATCH] D86660: Modifying ImportDeclContext(...) to ensure that we also handle the case when the FieldDecl is an ArrayType whose ElementType is a RecordDecl

2020-09-17 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

In D86660#2278025 , @shafik wrote:

> We are going to move forward with this approach (after dealing with the 
> multi-dimensional array case) temporarily. We are seeing crash bugs from this 
> from users and we want to fix it while we explore the solution space more.

Okay, I understand the business reasons and I am fine with this patch if this 
is really a temporary solution. Just please add a FIXME that indicates this and 
D71378  are temporary, plus that this should 
be really handled by the preceding `import` call.


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

https://reviews.llvm.org/D86660

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


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 13 inline comments as done.
gamesh411 added a comment.

Note that there are no negative test cases that assert that we do NOT report in 
case a custom or an anonymous namespace is used. For that I would need a small 
patch in the testing infrastructure.
Patch needed in check_clang_tidy.py:

  --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  @@ -167,7 +167,7 @@ def run_test_once(args, extra_args):
 subprocess.check_output(
 ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
  '-check-prefixes=' + ','.join(check_fixes_prefixes),
  -   '-strict-whitespace'],
  +   '-strict-whitespace', '--allow-empty'],
 stderr=subprocess.STDOUT)
   except subprocess.CalledProcessError as e:
 print('FileCheck failed:\n' + e.output.decode())
  @@ -180,7 +180,7 @@ def run_test_once(args, extra_args):
 subprocess.check_output(
 ['FileCheck', '-input-file=' + messages_file, input_file_name,
  '-check-prefixes=' + ','.join(check_messages_prefixes),
  -   '-implicit-check-not={{warning|error}}:'],
  +   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
 stderr=subprocess.STDOUT)
   except subprocess.CalledProcessError as e:
 print('FileCheck failed:\n' + e.output.decode())
  @@ -195,7 +195,7 @@ def run_test_once(args, extra_args):
 subprocess.check_output(
 ['FileCheck', '-input-file=' + notes_file, input_file_name,
  '-check-prefixes=' + ','.join(check_notes_prefixes),
  -   '-implicit-check-not={{note|warning|error}}:'],
  +   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
 stderr=subprocess.STDOUT)
   except subprocess.CalledProcessError as e:
 print('FileCheck failed:\n' + e.output.decode())

And then I can assert the non-reports by adding the following runlines:

  // Functions in anonymous or custom namespace should not be considered as exit
  // functions.
  //
  // RUN: %check_clang_tidy -assume-filename=%s.cpp %s -check-suffix=CUSTOM \
  // RUN: cert-env32-c %t -- -- -DCPPMODE -DTEST_NS_NAME=custom
  // CHECK-NOTES-CUSTOM-NOT: NO DIAGS
  //
  // RUN: %check_clang_tidy -assume-filename=%s.cpp %s -check-suffix=ANONYMOUS \
  // RUN: cert-env32-c %t -- -- -DCPPMODE -DTEST_NS_NAME=''
  // CHECK-NOTES-ANONYMOUS-NOT: NO DIAGS




Comment at: clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp:70
+ .bind("handler_expr"));
+  Finder->addMatcher(
+  callExpr(IsRegisterFunction, HasHandlerAsFirstArg).bind("register_call"),

aaron.ballman wrote:
> I am not at all certain whether this is plausible, but I *think* this check 
> can be almost entirely implemented in the matchers rather than having to do 
> manual work. I think you can bind the argument node from the call to 
> `at_quick_exit()` and then use `equalsBoundNode()` to find the function calls 
> within the bound `functionDecl()` node.
> 
> However, if that's not workable, I think you can get rid of the 
> `CalledFunctionsCollector` entirely and just use matchers directly within the 
> `check()` function because by that point, you'll know exactly which AST nodes 
> you want to traverse through.
I have investigated, and to do that recursive matching up to indeterminate 
depth all the while keeping the already matched functions in a set is not 
something I would implement with a single matcher. I could use a standalone 
matcher, but as far as I can understand I would need to implement a callback 
function for handling the matched results out of line for that as well, so I 
think that the ASTVisitor based solution is at least as good as a standalone 
ASTMatcher would be. Therefore I'd rather keep this solution.



Comment at: clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c:31
+// --
+// C99 requires jmp_buf to be an array type.
+typedef int jmp_buf[1];

whisperity wrote:
> Which is the standard version this test file is set to analyse with? I don't 
> see any `-std=` flag in the `RUN:` line.
Right now there is a run-line for handling it as C, and 2 others for handling 
it as C++ with different namespaces. The test cases themselves are not 
dependent on the standard used (AFAIK).  The comment contains a standard 
reference for C, but that is just the first time it was standardized in C so 
the mention is there for traceability and not to restrict the standard used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

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


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 292419.
gamesh411 added a comment.

Reformat diagnostic message
Use explicit name longjmp instead of jump function
Fix liberal auto inside Collector


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c-teminate.cpp
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
@@ -19,6 +19,7 @@
 "CommandProcessorCheck.cpp",
 "DefaultOperatorNewAlignmentCheck.cpp",
 "DontModifyStdNamespaceCheck.cpp",
+"ExitHandlerCheck.cpp",
 "FloatLoopCounter.cpp",
 "LimitedRandomnessCheck.cpp",
 "MutatingCopyCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
@@ -0,0 +1,412 @@
+// Test as a C file.
+// RUN: %check_clang_tidy %s cert-env32-c %t -- -- -DCMODE
+//
+// Test as a C++ file.
+//
+// Test functions in global namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE
+//
+// Test functions in std namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE -DTEST_NS_NAME=std
+
+#if defined(CPPMODE) && defined(TEST_NS_NAME)
+namespace TEST_NS_NAME {
+#endif
+
+// --
+// EXIT FUNCTIONS
+// --
+
+// No handlers are invoked when _Exit is called.
+void _Exit(int __status);
+
+// Handlers registered by atexit are invoked in reverse order when exit is
+// called.
+void exit(int __status);
+
+// Handlers registered by at_quick_exit are invoked in reverse order when
+// quick_exit is called.
+void quick_exit(int __status);
+
+// The program is terminated without destroying any object and without calling
+// any of the functions passed to atexit or at_quick_exit.
+void abort();
+
+// 
+// HANDLER REGISTRATION
+// 
+
+// Register handlers to run when exit is called.
+int atexit(void (*__func)(void));
+
+// Register handlers to run when exit is called.
+int at_quick_exit(void (*__func)(void));
+
+// --
+// Setjmp/longjmp
+// --
+// C99 requires jmp_buf to be an array type.
+typedef int jmp_buf[1];
+int setjmp(jmp_buf);
+void longjmp(jmp_buf, int);
+
+// Compliant solutions
+
+void cleanup1() {
+  // do cleanup
+}
+
+void cleanup2() {
+  // do cleanup
+}
+
+void test_atexit_single_compliant() {
+  (void)atexit(cleanup1);
+}
+
+void test_atexit_multiple_compliant() {
+  (void)atexit(cleanup1);
+  (void)atexit(cleanup2);
+}
+
+void test_at_quick_exit_single_compliant() {
+  (void)at_quick_exit(cleanup1);
+}
+
+void test_at_quick_exit_multiple_compliant() {
+  (void)at_quick_exit(cleanup1);
+  (void)at_quick_exit(cleanup2);
+}
+
+// Non-compliant solutions calling _Exit
+
+void call__Exit() {
+  _Exit(0);
+}
+
+void call_call__Exit() {
+  call__Exit();
+}
+
+extern int unknown__Exit_flag;
+
+void call__Exit_conditionally() {
+  if (unknown__Exit_flag)
+call__Exit();
+}
+
+void call_call__Exit_conditionally() {
+  call__Exit_conditionally();
+}
+
+void test__Exit_called_directly() {
+  (void)atexit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-22]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-22]]:3: note: exit function called here
+  (void)at_quick_exit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-26]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-26]]:3: note: exit function called here
+};
+
+void test__Exit_called_indirectly() {
+  (void)atexit(call_call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-29]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LIN

[PATCH] D87629: Thread safety analysis: Improve documentation for ASSERT_CAPABILITY

2020-09-17 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D87629#2278383 , @ajtowns wrote:

> Not sure the `try { AssertHeld } catch (...) { a = 0; }` example reveals very 
> much: it seems like thread safety annotations aren't checked within a catch 
> block at all?
>
>   Mutex m;
>   int i GUARDED_BY(m);
>   
>   static void thrower() { throw std::exception(); }
>   void f() { i = 1; }
>   void g() {
>   try {
>   thrower();
>   } catch (...) {
>   i = 5;
>   }
>   i = 6;
>   }
>
> gives me warnings for `i=1` and `i=6` but not `i=5` ?

It's not we don't check catch-blocks, but rather that the Clang CFG is 
incomplete:

   [B5 (ENTRY)]
 Succs (1): B4
  
   [B1]
 1: 6
 2: i
 3: [B1.2] = [B1.1]
 Preds (2): B3 B4
 Succs (1): B0
  
   [B2]
 T: try ...
 Succs (1): B3
  
   [B3]
catch (...):
 1: catch (...) {
  [B3.4];
  }
 2: 5
 3: i
 4: [B3.3] = [B3.2]
 Preds (1): B2
 Succs (1): B1
  
   [B4]
 1: thrower
 2: [B4.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(void))
 3: [B4.2]()
 Preds (1): B5
 Succs (1): B1
  
   [B0 (EXIT)]
 Preds (1): B1

There is no edge from the `thrower` call to `B2` or `B3`. We can turn on 
"exception handling edges" from non-noexcept calls to catch blocks, but that's 
a bigger change and it would affect other warnings as well. There are also 
performance problems. (https://bugs.llvm.org/show_bug.cgi?id=43311)

> Using a dummy RAII class with SCOPED_CAPABILITY that does ACQUIRE/RELEASE 
> without modifying the actual mutex seems like it behaves more sensibly to 
> me...

Well, you clearly don't acquire or release anything. It's just a hack that 
seems to solve the problem, but doesn't really (see below).

>   class SCOPED_LOCKABLE assumer
>   {
>   public:
>   assumer(Mutex& m_) EXCLUSIVE_LOCK_FUNCTION(m_) { }
>   ~assumer() UNLOCK_FUNCTION() { }
>   };
>   
>   void h(bool b) {
>   try {
>   if (b) thrower();
>   i = 7;
>   assumer a(m);
>   i = 8;
>   } catch (...) { }
>   i = 9;
>   }
>
> gives me warnings for both `i=7` and `i=9` but allows `i=8`.

You're cherry-picking here. If you move `i=9` into the catch block, there is 
still no warning. And if you remove `if (b) thrower();` we wouldn't want the 
warning, because the assertion could be calling `std::abort` and then we'd have 
a false positive.

Assertions aren't scoped. The easiest way to see that is that destructor 
doesn't do anything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87629

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


[PATCH] D87815: [clang] Fix a typo-correction crash

2020-09-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: rsmith.
Herald added a project: clang.
hokein requested review of this revision.

We leave a dangling TypoExpr when typo-correction is performed
successfully in `checkArgsForPlaceholders`, which leads a crash in the
later TypoCorrection.

This code was added in 
https://github.com/llvm/llvm-project/commit/1586782767938df3a20f7abc4d8335c48b100bc4,
and it didn't seem to have enough test coverage.
The fix is to remove this part, and no failuer tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87815

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/typo-correction-crash.cpp


Index: clang/test/SemaCXX/typo-correction-crash.cpp
===
--- clang/test/SemaCXX/typo-correction-crash.cpp
+++ clang/test/SemaCXX/typo-correction-crash.cpp
@@ -32,3 +32,12 @@
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared 
identifier 'n'}}
 
 void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error 
{{undeclared identifier '_test_'}}
+
+namespace NoCrash {
+class S {
+  void Function(int a) {
+unknown1(unknown2, Function, unknown3); // expected-error 2{{use of 
undeclared identifier}} \
+   expected-error {{reference to 
non-static member function must be called}}
+  }
+};
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6068,8 +6068,6 @@
   ExprResult result = S.CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
-} else if (hasInvalid) {
-  (void)S.CorrectDelayedTyposInExpr(args[i]);
 }
   }
   return hasInvalid;


Index: clang/test/SemaCXX/typo-correction-crash.cpp
===
--- clang/test/SemaCXX/typo-correction-crash.cpp
+++ clang/test/SemaCXX/typo-correction-crash.cpp
@@ -32,3 +32,12 @@
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared identifier 'n'}}
 
 void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error {{undeclared identifier '_test_'}}
+
+namespace NoCrash {
+class S {
+  void Function(int a) {
+unknown1(unknown2, Function, unknown3); // expected-error 2{{use of undeclared identifier}} \
+   expected-error {{reference to non-static member function must be called}}
+  }
+};
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6068,8 +6068,6 @@
   ExprResult result = S.CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
-} else if (hasInvalid) {
-  (void)S.CorrectDelayedTyposInExpr(args[i]);
 }
   }
   return hasInvalid;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87816: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-17 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
awarzynski requested review of this revision.

As per the documentation, the 2nd argument in printDiagnosticMessage
should be a bool that specifies whether the underlying message is a
continuation note diagnostic or not. More specifically, it should be:

  Level == DiagnosticsEngine::Note

instead of:

  Level

This change means that `no input file` in the following scenario will be
now correctly printed in bold:

  $ bin/clang
  clang: error: no input files

In terminals that don't support text formatting the behaviour doesn't
change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87816

Files:
  clang/lib/Frontend/TextDiagnosticPrinter.cpp


Index: clang/lib/Frontend/TextDiagnosticPrinter.cpp
===
--- clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }


Index: clang/lib/Frontend/TextDiagnosticPrinter.cpp
===
--- clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26418: [clang-tidy] Add '-suppress-checks-filter' option to suppress diagnostics from certain files

2020-09-17 Thread Vincent Le Bourlot via Phabricator via cfe-commits
vlebourl added a comment.

Very interested in this one as well!


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

https://reviews.llvm.org/D26418

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


[PATCH] D87816: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-17 Thread Sanne Wouda via Phabricator via cfe-commits
sanwou01 accepted this revision.
sanwou01 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for fixing this! Could you wait a day or two before committing to 
allow others to comment?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87816

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


[PATCH] D83004: [UpdateCCTestChecks] Include generated functions if asked

2020-09-17 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

Maybe add another test that checks for the @__cxx_global_var_init() constructor 
function?
E.g. something like this:

  int init_func(int arg) {
  return arg + 1;
  }
  
  int my_global = init_func(2);




Comment at: llvm/utils/update_cc_test_checks.py:274-277
   prefixes = p[0]
   for prefix in prefixes:
 func_dict.update({prefix: dict()})
+func_order.update({prefix: []})

This should avoid a few update() calls. Not that performance really matters 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83004

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


[PATCH] D83004: [UpdateCCTestChecks] Include generated functions if asked

2020-09-17 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added inline comments.



Comment at: llvm/utils/update_cc_test_checks.py:331
+# are ordered by prefix instead of by function as in "normal"
+# mode.
+if '-emit-llvm' in clang_args:

jdoerfert wrote:
> This is all unfortunate but at least for OpenMP not easily changeable. Let's 
> go with this.
How difficult would it be to only use this behaviour if the normal one fails? 

If we encounter a function that's not in the source code we just append the 
check lines for the generate function where we last added checks. And if we 
then see a function where the order doesn't match the source order fall back to 
just emitting all checks at the end of the file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83004

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


[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D87615#2278002 , @joerg wrote:

> I'm still curious about the source of the vptr diff, but that's a minor 
> question, otherwise. LGTM

Thanks.  I think I've found what's going on here: the memory ranges are 
ultimately printed by `compiler-rt/lib/ubsan/ubsan_diag.cpp` 
(`PrintMemorySnippet`).  The crucial snippet is around l.280:

  // Emit data.
  InternalScopedString Buffer(1024);
  for (uptr P = Min; P != Max; ++P) {
unsigned char C = *reinterpret_cast(P);
Buffer.append("%s%02x", (P % 8 == 0) ? "  " : " ", C);
  }

`Min` is `Loc - 4`, i.e. 4 bytes before the start location.  Before my patch 
(i.e. with 16-byte stack alignment), that was

  0xfeffdcf0: note: object is of type 'S'
   76 62 92 92  ec 1b 06 08 00 00 00 00  44 de ff fe 30 dd ff fe  00 00 00 00 
00 00 00 00  00 00 00 00

i.e. `Loc - 4` wasn't on an 8-byte boundary, thus the line starts with a single 
blank.  With 4-byte aligned stack, I have instead

  0xfeffdd34: note: object is of type 'S'
76 62 92 92 ec 1b 06 08  00 00 00 00 78 dd ff fe  00 00 00 00 00 00 00 00  
00 00 00 00 00 00 00 00

i.e. `Loc - 4` **is** on an 8-byte boundary and the line starts with two blanks.

I can't see that the `vptr.cpp` testcase does anything to guarantee a specific 
alignment here, or depends on one.  In fact, AFAICS it's the only ubsan test 
that looks at that memory dump line at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D87615#2278436 , @MaskRay wrote:

>> This patch avoid the issue by defaulting to -mstackrealign, just like gcc.
>
> This sentence from the description should be removed.

Sure: I usually review and eventually update the description once for the 
commit message, rather than constantly tinkering with it while the review is 
still ongoing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[PATCH] D87291: [clang-format][regression][PR47461] ifdef causes catch to be seen as a function

2020-09-17 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

LGTM.
Don't we risk any other side effects?


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

https://reviews.llvm.org/D87291

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


[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa9cbe5cf30e3: [X86] Fix stack alignment on 32-bit 
Solaris/x86 (authored by ro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

Files:
  compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
  llvm/lib/Target/X86/X86Subtarget.cpp
  llvm/test/CodeGen/X86/stack-align2.ll


Index: llvm/test/CodeGen/X86/stack-align2.ll
===
--- llvm/test/CodeGen/X86/stack-align2.ll
+++ llvm/test/CodeGen/X86/stack-align2.ll
@@ -2,10 +2,12 @@
 ; RUN: llc < %s -mcpu=generic -mtriple=i386-kfreebsd | FileCheck %s 
-check-prefix=KFREEBSD-I386
 ; RUN: llc < %s -mcpu=generic -mtriple=i386-netbsd | FileCheck %s 
-check-prefix=NETBSD-I386
 ; RUN: llc < %s -mcpu=generic -mtriple=i686-apple-darwin8 | FileCheck %s 
-check-prefix=DARWIN-I386
+; RUN: llc < %s -mcpu=generic -mtriple=i386-pc-solaris2.11 | FileCheck %s 
-check-prefix=SOLARIS-I386
 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux | FileCheck %s 
-check-prefix=LINUX-X86_64
 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-kfreebsd | FileCheck %s 
-check-prefix=KFREEBSD-X86_64
 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-netbsd | FileCheck %s 
-check-prefix=NETBSD-X86_64
 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-apple-darwin8 | FileCheck %s 
-check-prefix=DARWIN-X86_64
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-pc-solaris2.11 | FileCheck %s 
-check-prefix=SOLARIS-X86_64
 
 define i32 @test() nounwind {
 entry:
@@ -15,7 +17,8 @@
 ; LINUX-I386: subl $12, %esp
 ; KFREEBSD-I386:  subl $12, %esp
 ; DARWIN-I386:subl $12, %esp
-; NETBSD-I386-NOT: subl{{.*}}, %esp
+; NETBSD-I386-NOT:  subl   {{.*}}, %esp
+; SOLARIS-I386-NOT: subl   {{.*}}, %esp
 
 ; LINUX-X86_64:  pushq %{{.*}}
 ; LINUX-X86_64-NOT:  subq  {{.*}}, %rsp
@@ -23,6 +26,8 @@
 ; DARWIN-X86_64-NOT: subq  {{.*}}, %rsp
 ; NETBSD-X86_64: pushq %{{.*}}
 ; NETBSD-X86_64-NOT: subq  {{.*}}, %rsp
+; SOLARIS-X86_64: pushq %{{.*}}
+; SOLARIS-X86_64-NOT: subq {{.*}}, %rsp
 ; KFREEBSD-X86_64: pushq %{{.*}}
 ; KFREEBSD-X86_64-NOT: subq{{.*}}, %rsp
 }
Index: llvm/lib/Target/X86/X86Subtarget.cpp
===
--- llvm/lib/Target/X86/X86Subtarget.cpp
+++ llvm/lib/Target/X86/X86Subtarget.cpp
@@ -258,12 +258,13 @@
 report_fatal_error("64-bit code requested on a subtarget that doesn't "
"support it!");
 
-  // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both
-  // 32 and 64 bit) and for all 64-bit targets.
+  // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and for all
+  // 64-bit targets.  On Solaris (32-bit), stack alignment is 4 bytes
+  // following the i386 psABI, while on Illumos it is always 16 bytes.
   if (StackAlignOverride)
 stackAlignment = *StackAlignOverride;
-  else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
-   isTargetKFreeBSD() || In64BitMode)
+  else if (isTargetDarwin() || isTargetLinux() || isTargetKFreeBSD() ||
+   In64BitMode)
 stackAlignment = Align(16);
 
   // Consume the vector width attribute or apply any target specific limit.
Index: compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
===
--- compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
@@ -162,7 +162,7 @@
   case 'm':
 // CHECK-MEMBER: vptr.cpp:[[@LINE+6]]:15: runtime error: member access 
within address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
 // CHECK-MEMBER-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]
-// CHECK-MEMBER-NEXT: {{^ .. .. .. ..  .. .. .. .. .. .. .. ..  }}
+// CHECK-MEMBER-NEXT: {{^  ?.. .. .. ..  ?.. .. .. ..  ?.. .. .. ..  ?}}
 // CHECK-MEMBER-NEXT: {{^  \^~~()? *$}}
 // CHECK-MEMBER-NEXT: {{^  vptr for}} [[DYN_TYPE]]
 // CHECK-Linux-MEMBER: #0 {{.*}}access_p{{.*}}vptr.cpp:[[@LINE+1]]
@@ -178,7 +178,7 @@
   case 'f':
 // CHECK-MEMFUN: vptr.cpp:[[@LINE+6]]:15: runtime error: member call on 
address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
 // CHECK-MEMFUN-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]
-// CHECK-MEMFUN-NEXT: {{^ .. .. .. ..  .. .. .. .. .. .. .. ..  }}
+// CHECK-MEMFUN-NEXT: {{^  ?.. .. .. ..  ?.. .. .. ..  ?.. .. .. ..  ?}}
 // CHECK-MEMFUN-NEXT: {{^  \^~~()? *$}}
 // CHECK-MEMFUN-NEXT: {{^  vptr for}} [[DYN_TYPE]]
 // TODO: Add check for stacktrace here.
@@ -196,7 +196,7 @@
   case 'c':
 // CHECK-DOWNCAST: vptr.cpp:[[@LINE+6]]:11: runtime error: downcast of 
address [[PTR:0x[0-9a-f]*]] which does not point to an object 

[clang] 9218f92 - [clang][aarch64] ACLE: Support implicit casts between GNU and SVE vectors

2020-09-17 Thread Cullen Rhodes via cfe-commits

Author: Cullen Rhodes
Date: 2020-09-17T09:35:30Z
New Revision: 9218f9283802b2d1ff33c490761fdb925b1e56d9

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

LOG: [clang][aarch64] ACLE: Support implicit casts between GNU and SVE vectors

This patch adds support for implicit casting between GNU vectors and SVE
vectors when `__ARM_FEATURE_SVE_BITS==N`, as defined by the Arm C
Language Extensions (ACLE, version 00bet5, section 3.7.3.3) for SVE [1].

This behavior makes it possible to use GNU vectors with ACLE functions
that operate on VLAT. For example:

  typedef int8_t vec __attribute__((vector_size(32)));
  vec f(vec x) { return svasrd_x(svptrue_b8(), x, 1); }

Tests are also added for implicit casting between GNU and fixed-length
SVE vectors created by the 'arm_sve_vector_bits' attribute. This
behavior makes it possible to use VLST with existing interfaces that
operate on GNUT. For example:

  typedef int8_t vec1 __attribute__((vector_size(32)));
  void f(vec1);
  #if __ARM_FEATURE_SVE_BITS==256 && __ARM_FEATURE_SVE_VECTOR_OPERATORS
  typedef svint8_t vec2 __attribute__((arm_sve_vector_bits(256)));
  void g(vec2 x) { f(x); } // OK
  #endif

The `__ARM_FEATURE_SVE_VECTOR_OPERATORS` feature macro indicates
interoperability with the GNU vector extension. This is the first patch
providing support for this feature, which once complete will be enabled
by the `-msve-vector-bits` flag, as the `__ARM_FEATURE_SVE_BITS` feature
currently is.

[1] https://developer.arm.com/documentation/100987/latest

Reviewed By: efriedma

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

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
clang/test/Sema/attr-arm-sve-vector-bits.c
clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 20ea91c68d6d..84f747361235 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8516,6 +8516,10 @@ bool ASTContext::areCompatibleSveTypes(QualType 
FirstType,
 else if (VT->getVectorKind() == VectorType::SveFixedLengthDataVector)
   return VT->getElementType().getCanonicalType() ==
  FirstType->getSveEltType(*this);
+else if (VT->getVectorKind() == VectorType::GenericVector)
+  return getTypeSize(SecondType) == getLangOpts().ArmSveVectorBits &&
+ hasSameType(VT->getElementType(),
+ getBuiltinVectorTypeInfo(BT).ElementType);
   }
 }
 return false;

diff  --git a/clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c 
b/clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
index 18a7e1f1496c..e65537cead10 100644
--- a/clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
+++ b/clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
@@ -9,6 +9,7 @@
 typedef svint32_t fixed_int32_t __attribute__((arm_sve_vector_bits(N)));
 typedef svfloat64_t fixed_float64_t __attribute__((arm_sve_vector_bits(N)));
 typedef svbool_t fixed_bool_t __attribute__((arm_sve_vector_bits(N)));
+typedef int32_t gnu_int32_t __attribute__((vector_size(N / 8)));
 
 // CHECK-LABEL: @to_svint32_t(
 // CHECK-NEXT:  entry:
@@ -107,3 +108,55 @@ svbool_t to_svbool_t(fixed_bool_t type) {
 fixed_bool_t from_svbool_t(svbool_t type) {
   return type;
 }
+
+// CHECK-LABEL: @to_svint32_t__from_gnu_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TYPE_ADDR:%.*]] = alloca <16 x i32>, align 16
+// CHECK-NEXT:[[TYPE:%.*]] = load <16 x i32>, <16 x i32>* [[TMP0:%.*]], 
align 16, [[TBAA2]]
+// CHECK-NEXT:store <16 x i32> [[TYPE]], <16 x i32>* [[TYPE_ADDR]], align 
16, [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i32>* [[TYPE_ADDR]] to *
+// CHECK-NEXT:[[TMP2:%.*]] = load , * 
[[TMP1]], align 16, [[TBAA2]]
+// CHECK-NEXT:ret  [[TMP2]]
+//
+svint32_t to_svint32_t__from_gnu_int32_t(gnu_int32_t type) {
+  return type;
+}
+
+// CHECK-LABEL: @from_svint32_t__to_gnu_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TYPE_ADDR:%.*]] = alloca , align 16
+// CHECK-NEXT:store  [[TYPE:%.*]], * 
[[TYPE_ADDR]], align 16, [[TBAA5]]
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast * [[TYPE_ADDR]] to 
<16 x i32>*
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i32>, <16 x i32>* [[TMP0]], align 
16, [[TBAA2]]
+// CHECK-NEXT:store <16 x i32> [[TMP1]], <16 x i32>* [[AGG_RESULT:%.*]], 
align 16, [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+gnu_int32_t from_svint32_t__to_gnu_int32_t(svint32_t type) {
+  return type;
+}
+
+// CHECK-LABEL: @to_fixed_int32_t__from_gnu_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL_COERCE:%.*]] = alloca , align 16
+// CHECK-NEXT:[[TYPE:%.*]] = load <16 x i32>, <16 x i32>* [[TMP0:%.*]], 
align 16, [[TBAA

[PATCH] D87607: [clang][aarch64] Support implicit casts between GNU and SVE vectors

2020-09-17 Thread Cullen Rhodes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9218f9283802: [clang][aarch64] ACLE: Support implicit casts 
between GNU and SVE vectors (authored by c-rhodes).

Changed prior to commit:
  https://reviews.llvm.org/D87607?vs=292162&id=292441#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87607

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
  clang/test/Sema/attr-arm-sve-vector-bits.c
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp

Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,14 +1,26 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
 // expected-no-diagnostics
 
+#include 
+
 #define N __ARM_FEATURE_SVE_BITS
 
 typedef __SVInt8_t svint8_t;
 typedef svint8_t fixed_int8_t __attribute__((arm_sve_vector_bits(N)));
+typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));
 
 template struct S { T var; };
 
 S s;
 
+// Test implicit casts between VLA and VLS vectors
 svint8_t to_svint8_t(fixed_int8_t x) { return x; }
 fixed_int8_t from_svint8_t(svint8_t x) { return x; }
+
+// Test implicit casts between GNU and VLA vectors
+svint8_t to_svint8_t__from_gnu_int8_t(gnu_int8_t x) { return x; }
+gnu_int8_t from_svint8_t__to_gnu_int8_t(svint8_t x) { return x; }
+
+// Test implicit casts between GNU and VLS vectors
+fixed_int8_t to_fixed_int8_t__from_gnu_int8_t(gnu_int8_t x) { return x; }
+gnu_int8_t from_fixed_int8_t__to_gnu_int8_t(fixed_int8_t x) { return x; }
Index: clang/test/Sema/attr-arm-sve-vector-bits.c
===
--- clang/test/Sema/attr-arm-sve-vector-bits.c
+++ clang/test/Sema/attr-arm-sve-vector-bits.c
@@ -1,11 +1,16 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=128 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=256 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=1024 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=2048 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=128 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=256 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=1024 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=2048 -fallow-half-arguments-and-returns %s
+
+#include 
 
 #define N __ARM_FEATURE_SVE_BITS
 
+typedef __fp16 float16_t;
+typedef float float32_t;
+typedef double float64_t;
 typedef __SVInt8_t svint8_t;
 typedef __SVInt16_t svint16_t;
 typedef __SVInt32_t svint32_t;
@@ -19,6 +24,7 @@
 typedef __SVFloat64_t svfloat64_t;
 
 #if defined(__ARM_FEATURE_SVE_BF16)
+typedef __bf16 bfloat16_t;
 typedef __SVBFloat16_t svbfloat16_t;
 #endif
 
@@ -43,6 +49,23 @@
 
 typedef svbool_t fixed_bool_t __attribute__((arm_sve_vector_bits(N)));
 
+// GNU vector types
+typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));
+typedef int16_t gnu_int16_t __attribute__((vector_size(N / 8)));
+typedef int32_t gnu_int32_t __attribute__((vector_size(N / 8)));
+typedef int64_t gnu_int64_t __attribute__((vector_size(N / 8)));
+
+typedef uint8_t gnu_uint8_t __attribute__((vector_size(N / 8)));
+t

[PATCH] D87820: [SyntaxTree][Synthesis] Fix allocation in `createTree` for more general use

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Prior to this change `createTree` could not create arbitrary syntax
trees. Now it dispatches to the constructor of the concrete syntax tree
according to the `NodeKind` passed as argument. This allows reuse inside
the Synthesis API.  # Please enter the commit message for your changes.
Lines starting


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87820

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp

Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -52,11 +52,144 @@
   return createLeaf(A, K, Spelling);
 }
 
+namespace {
+// Allocates the concrete syntax `Node` according to its `NodeKind`.
+syntax::Tree *allocateTree(syntax::Arena &A, syntax::NodeKind Kind) {
+  switch (Kind) {
+  case syntax::NodeKind::Leaf:
+assert(false);
+  case syntax::NodeKind::TranslationUnit:
+return new (A.getAllocator()) syntax::TranslationUnit;
+  case syntax::NodeKind::UnknownExpression:
+return new (A.getAllocator()) syntax::UnknownExpression;
+  case syntax::NodeKind::ParenExpression:
+return new (A.getAllocator()) syntax::ParenExpression;
+  case syntax::NodeKind::ThisExpression:
+return new (A.getAllocator()) syntax::ThisExpression;
+  case syntax::NodeKind::IntegerLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerLiteralExpression;
+  case syntax::NodeKind::CharacterLiteralExpression:
+return new (A.getAllocator()) syntax::CharacterLiteralExpression;
+  case syntax::NodeKind::FloatingLiteralExpression:
+return new (A.getAllocator()) syntax::FloatingLiteralExpression;
+  case syntax::NodeKind::StringLiteralExpression:
+return new (A.getAllocator()) syntax::StringLiteralExpression;
+  case syntax::NodeKind::BoolLiteralExpression:
+return new (A.getAllocator()) syntax::BoolLiteralExpression;
+  case syntax::NodeKind::CxxNullPtrExpression:
+return new (A.getAllocator()) syntax::CxxNullPtrExpression;
+  case syntax::NodeKind::IntegerUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerUserDefinedLiteralExpression;
+  case syntax::NodeKind::FloatUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::FloatUserDefinedLiteralExpression;
+  case syntax::NodeKind::CharUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::CharUserDefinedLiteralExpression;
+  case syntax::NodeKind::StringUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::StringUserDefinedLiteralExpression;
+  case syntax::NodeKind::PrefixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PrefixUnaryOperatorExpression;
+  case syntax::NodeKind::PostfixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PostfixUnaryOperatorExpression;
+  case syntax::NodeKind::BinaryOperatorExpression:
+return new (A.getAllocator()) syntax::BinaryOperatorExpression;
+  case syntax::NodeKind::UnqualifiedId:
+return new (A.getAllocator()) syntax::UnqualifiedId;
+  case syntax::NodeKind::IdExpression:
+return new (A.getAllocator()) syntax::IdExpression;
+  case syntax::NodeKind::CallExpression:
+return new (A.getAllocator()) syntax::CallExpression;
+  case syntax::NodeKind::UnknownStatement:
+return new (A.getAllocator()) syntax::UnknownStatement;
+  case syntax::NodeKind::DeclarationStatement:
+return new (A.getAllocator()) syntax::DeclarationStatement;
+  case syntax::NodeKind::EmptyStatement:
+return new (A.getAllocator()) syntax::EmptyStatement;
+  case syntax::NodeKind::SwitchStatement:
+return new (A.getAllocator()) syntax::SwitchStatement;
+  case syntax::NodeKind::CaseStatement:
+return new (A.getAllocator()) syntax::CaseStatement;
+  case syntax::NodeKind::DefaultStatement:
+return new (A.getAllocator()) syntax::DefaultStatement;
+  case syntax::NodeKind::IfStatement:
+return new (A.getAllocator()) syntax::IfStatement;
+  case syntax::NodeKind::ForStatement:
+return new (A.getAllocator()) syntax::ForStatement;
+  case syntax::NodeKind::WhileStatement:
+return new (A.getAllocator()) syntax::WhileStatement;
+  case syntax::NodeKind::ContinueStatement:
+return new (A.getAllocator()) syntax::ContinueStatement;
+  case syntax::NodeKind::BreakStatement:
+return new (A.getAllocator()) syntax::BreakStatement;
+  case syntax::NodeKind::ReturnStatement:
+return new (A.getAllocator()) syntax::ReturnStatement;
+  case syntax::NodeKind::RangeBasedForStatement:
+return new (A.getAllocator()) syntax::RangeBasedForStatement;
+  case syntax::NodeKind::ExpressionStatement:
+return new (A.getAllocator()) syntax::ExpressionStatement;
+  case syntax:

[PATCH] D87820: [SyntaxTree][Synthesis] Fix allocation in `createTree` for more general use

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 292444.
eduucaldas edited the summary of this revision.
eduucaldas added a comment.

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87820

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp

Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -52,11 +52,144 @@
   return createLeaf(A, K, Spelling);
 }
 
+namespace {
+// Allocates the concrete syntax `Tree` according to its `NodeKind`.
+syntax::Tree *allocateTree(syntax::Arena &A, syntax::NodeKind Kind) {
+  switch (Kind) {
+  case syntax::NodeKind::Leaf:
+assert(false);
+  case syntax::NodeKind::TranslationUnit:
+return new (A.getAllocator()) syntax::TranslationUnit;
+  case syntax::NodeKind::UnknownExpression:
+return new (A.getAllocator()) syntax::UnknownExpression;
+  case syntax::NodeKind::ParenExpression:
+return new (A.getAllocator()) syntax::ParenExpression;
+  case syntax::NodeKind::ThisExpression:
+return new (A.getAllocator()) syntax::ThisExpression;
+  case syntax::NodeKind::IntegerLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerLiteralExpression;
+  case syntax::NodeKind::CharacterLiteralExpression:
+return new (A.getAllocator()) syntax::CharacterLiteralExpression;
+  case syntax::NodeKind::FloatingLiteralExpression:
+return new (A.getAllocator()) syntax::FloatingLiteralExpression;
+  case syntax::NodeKind::StringLiteralExpression:
+return new (A.getAllocator()) syntax::StringLiteralExpression;
+  case syntax::NodeKind::BoolLiteralExpression:
+return new (A.getAllocator()) syntax::BoolLiteralExpression;
+  case syntax::NodeKind::CxxNullPtrExpression:
+return new (A.getAllocator()) syntax::CxxNullPtrExpression;
+  case syntax::NodeKind::IntegerUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerUserDefinedLiteralExpression;
+  case syntax::NodeKind::FloatUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::FloatUserDefinedLiteralExpression;
+  case syntax::NodeKind::CharUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::CharUserDefinedLiteralExpression;
+  case syntax::NodeKind::StringUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::StringUserDefinedLiteralExpression;
+  case syntax::NodeKind::PrefixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PrefixUnaryOperatorExpression;
+  case syntax::NodeKind::PostfixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PostfixUnaryOperatorExpression;
+  case syntax::NodeKind::BinaryOperatorExpression:
+return new (A.getAllocator()) syntax::BinaryOperatorExpression;
+  case syntax::NodeKind::UnqualifiedId:
+return new (A.getAllocator()) syntax::UnqualifiedId;
+  case syntax::NodeKind::IdExpression:
+return new (A.getAllocator()) syntax::IdExpression;
+  case syntax::NodeKind::CallExpression:
+return new (A.getAllocator()) syntax::CallExpression;
+  case syntax::NodeKind::UnknownStatement:
+return new (A.getAllocator()) syntax::UnknownStatement;
+  case syntax::NodeKind::DeclarationStatement:
+return new (A.getAllocator()) syntax::DeclarationStatement;
+  case syntax::NodeKind::EmptyStatement:
+return new (A.getAllocator()) syntax::EmptyStatement;
+  case syntax::NodeKind::SwitchStatement:
+return new (A.getAllocator()) syntax::SwitchStatement;
+  case syntax::NodeKind::CaseStatement:
+return new (A.getAllocator()) syntax::CaseStatement;
+  case syntax::NodeKind::DefaultStatement:
+return new (A.getAllocator()) syntax::DefaultStatement;
+  case syntax::NodeKind::IfStatement:
+return new (A.getAllocator()) syntax::IfStatement;
+  case syntax::NodeKind::ForStatement:
+return new (A.getAllocator()) syntax::ForStatement;
+  case syntax::NodeKind::WhileStatement:
+return new (A.getAllocator()) syntax::WhileStatement;
+  case syntax::NodeKind::ContinueStatement:
+return new (A.getAllocator()) syntax::ContinueStatement;
+  case syntax::NodeKind::BreakStatement:
+return new (A.getAllocator()) syntax::BreakStatement;
+  case syntax::NodeKind::ReturnStatement:
+return new (A.getAllocator()) syntax::ReturnStatement;
+  case syntax::NodeKind::RangeBasedForStatement:
+return new (A.getAllocator()) syntax::RangeBasedForStatement;
+  case syntax::NodeKind::ExpressionStatement:
+return new (A.getAllocator()) syntax::ExpressionStatement;
+  case syntax::NodeKind::CompoundStatement:
+return new (A.getAllocator()) syntax::CompoundStatement;
+  case syntax::NodeKind::UnknownDeclaration:
+return new (A.getAllocator()) syntax::UnknownDeclaration;
+  case syntax::NodeKind::EmptyDeclaration:
+return new (A.getAllocator()) syntax::E

[PATCH] D87822: [FPEnv] Evaluate constant expressions under non-default rounding modes

2020-09-17 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rsmith, rjmccall, mibintc, kpn.
Herald added a project: clang.
sepavloff requested review of this revision.

The change implements evaluation of constant floating point expressions
under non-default rounding modes. The main objective was to support
evaluation of global variable initializers, where constant rounding mode
may be specified by `#pragma STDC FENV_ROUND`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87822

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/AST/const-fpfeatures-diag.c
  clang/test/AST/const-fpfeatures.c

Index: clang/test/AST/const-fpfeatures.c
===
--- /dev/null
+++ clang/test/AST/const-fpfeatures.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -S -emit-llvm -Wno-unknown-pragmas %s -o - | FileCheck %s
+
+// nextUp(1.F) == 0x1.02p0F
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+float F1u = 1.0F + 0x0.02p0F;
+float F2u = 1.0F + 0x0.01p0F;
+float F3u = 0x1.01p0;
+// CHECK: @F1u = {{.*}} float 0x3FF02000
+// CHECK: @F2u = {{.*}} float 0x3FF02000
+// CHECK: @F3u = {{.*}} float 0x3FF02000
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+
+float F1d = 1.0F + 0x0.02p0F;
+float F2d = 1.0F + 0x0.01p0F;
+float F3d = 0x1.01p0;
+
+// CHECK: @F1d = {{.*}} float 0x3FF02000
+// CHECK: @F2d = {{.*}} float 1.00e+00
+// CHECK: @F3d = {{.*}} float 1.00e+00
Index: clang/test/AST/const-fpfeatures-diag.c
===
--- /dev/null
+++ clang/test/AST/const-fpfeatures-diag.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -ffp-exception-behavior=strict -Wno-unknown-pragmas %s
+
+#pragma STDC FENV_ROUND FE_DYNAMIC
+
+// nextUp(1.F) == 0x1.02p0F
+
+float F1 = 0x1.00p0F + 0x0.02p0F;
+float F2 = 0x1.00p0F + 0x0.01p0F; // expected-error{{initializer element is not a compile-time constant}}
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -981,7 +981,9 @@
 void Sema::setRoundingMode(SourceLocation Loc, llvm::RoundingMode FPR) {
   // C2x: 7.6.2p3  If the FE_DYNAMIC mode is specified and FENV_ACCESS is "off",
   // the translator may assume that the default rounding mode is in effect.
-  if (FPR == llvm::RoundingMode::Dynamic && !CurFPFeatures.getAllowFEnvAccess())
+  if (FPR == llvm::RoundingMode::Dynamic &&
+  !CurFPFeatures.getAllowFEnvAccess() &&
+  CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Ignore)
 FPR = llvm::RoundingMode::NearestTiesToEven;
 
   FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2421,10 +2421,29 @@
 static bool HandleFloatToFloatCast(EvalInfo &Info, const Expr *E,
QualType SrcType, QualType DestType,
APFloat &Result) {
+  llvm::RoundingMode RM = llvm::RoundingMode::NearestTiesToEven;
+  if (auto Cast = dyn_cast(E)) {
+FPOptions FPFeatures = Cast->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+RM = FPFeatures.getRoundingMode();
+  }
+  bool DynamicRM = RM == llvm::RoundingMode::Dynamic;
+  if (DynamicRM)
+// If rounding mode is unknown at compile time, still try to execute the
+// operation. If the result is exact, it does not depend on rounding mode.
+RM = llvm::RoundingMode::NearestTiesToEven;
+
+  APFloat::opStatus St;
   APFloat Value = Result;
   bool ignored;
-  Result.convert(Info.Ctx.getFloatTypeSemantics(DestType),
- APFloat::rmNearestTiesToEven, &ignored);
+  St = Result.convert(Info.Ctx.getFloatTypeSemantics(DestType), RM, &ignored);
+
+  // FIXME: if:
+  // - evaluation triggered some FP exception, and
+  // - exception mode is not "ignore", and
+  // - the expression being evaluated is not a part of global variable
+  //   initializer,
+  // the evaluation probably need to be rejected.
+
   return true;
 }
 
@@ -2647,31 +2666,51 @@
 }
 
 /// Perform the given binary floating-point operation, in-place, on LHS.
-static bool handleFloatFloatBinOp(EvalInfo &Info, const Expr *E,
+static bool handleFloatFloatBinOp(EvalInfo &Info, const BinaryOperator *E,
   APFloat &LHS, BinaryOperatorKind Opcode,
   const APFloat &RHS) {
+  FPOptions FPFeatures = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+  llvm::RoundingMode RM = FPFeatures.getRoundingMode();
+  bool DynamicRM = RM == llvm::RoundingMode::Dynamic;
+  if (DynamicRM)
+// If rounding mode is unknown at compile time, still try to execute the
+// operation. If the result is exact, it does not depend on rounding mode.
+RM = llvm::Ro

[PATCH] D85118: [clang][AArch64] Correct return type of Neon vqmovun intrinsics

2020-09-17 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 292454.
DavidSpickett added a comment.

Updated to fix all the vqmovun that have incorrect types.

I'm working on a test specifically for intrinic types, using
the function pointer idea. That will be a seperate change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85118

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-misc.c
  clang/test/Sema/arm64-neon-header.c


Index: clang/test/Sema/arm64-neon-header.c
===
--- clang/test/Sema/arm64-neon-header.c
+++ clang/test/Sema/arm64-neon-header.c
@@ -2,6 +2,6 @@
 
 #include 
 
-int16x8_t foo(int8x8_t p0, int16x8_t p1) {
+int16x8_t foo(uint8x8_t p0, int16x8_t p1) {
   return vqmovun_high_s16(p0, p1); // expected-warning {{incompatible vector 
types returning 'uint8x16_t'}}
 }
Index: clang/test/CodeGen/aarch64-neon-misc.c
===
--- clang/test/CodeGen/aarch64-neon-misc.c
+++ clang/test/CodeGen/aarch64-neon-misc.c
@@ -1908,7 +1908,7 @@
 // CHECK:   [[VQMOVUN_V1_I_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> %b)
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> %a, <8 x i8> 
[[VQMOVUN_V1_I_I]], <16 x i32> 
 // CHECK:   ret <16 x i8> [[SHUFFLE_I_I]]
-int8x16_t test_vqmovun_high_s16(int8x8_t a, int16x8_t b) {
+uint8x16_t test_vqmovun_high_s16(uint8x8_t a, int16x8_t b) {
   return vqmovun_high_s16(a, b);
 }
 
@@ -1918,7 +1918,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <4 x i16> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> %a, <4 x i16> 
[[VQMOVUN_V1_I_I]], <8 x i32> 
 // CHECK:   ret <8 x i16> [[SHUFFLE_I_I]]
-int16x8_t test_vqmovun_high_s32(int16x4_t a, int32x4_t b) {
+uint16x8_t test_vqmovun_high_s32(uint16x4_t a, int32x4_t b) {
   return vqmovun_high_s32(a, b);
 }
 
@@ -1928,7 +1928,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <2 x i32> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <2 x i32> %a, <2 x i32> 
[[VQMOVUN_V1_I_I]], <4 x i32> 
 // CHECK:   ret <4 x i32> [[SHUFFLE_I_I]]
-int32x4_t test_vqmovun_high_s64(int32x2_t a, int64x2_t b) {
+uint32x4_t test_vqmovun_high_s64(uint32x2_t a, int64x2_t b) {
   return vqmovun_high_s64(a, b);
 }
 
Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -14094,8 +14094,8 @@
 // CHECK:   [[VQMOVUNH_S16_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <8 x i8> [[VQMOVUNH_S16_I]], i64 0
 // CHECK:   ret i8 [[TMP1]]
-int8_t test_vqmovunh_s16(int16_t a) {
-  return (int8_t)vqmovunh_s16(a);
+uint8_t test_vqmovunh_s16(int16_t a) {
+  return (uint8_t)vqmovunh_s16(a);
 }
 
 // CHECK-LABEL: @test_vqmovuns_s32(
@@ -14103,15 +14103,15 @@
 // CHECK:   [[VQMOVUNS_S32_I:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.sqxtun.v4i16(<4 x i32> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <4 x i16> [[VQMOVUNS_S32_I]], i64 0
 // CHECK:   ret i16 [[TMP1]]
-int16_t test_vqmovuns_s32(int32_t a) {
-  return (int16_t)vqmovuns_s32(a);
+uint16_t test_vqmovuns_s32(int32_t a) {
+  return (uint16_t)vqmovuns_s32(a);
 }
 
 // CHECK-LABEL: @test_vqmovund_s64(
 // CHECK:   [[VQMOVUND_S64_I:%.*]] = call i32 
@llvm.aarch64.neon.scalar.sqxtun.i32.i64(i64 %a)
 // CHECK:   ret i32 [[VQMOVUND_S64_I]]
-int32_t test_vqmovund_s64(int64_t a) {
-  return (int32_t)vqmovund_s64(a);
+uint32_t test_vqmovund_s64(int64_t a) {
+  return (uint32_t)vqmovund_s64(a);
 }
 
 // CHECK-LABEL: @test_vqmovnh_s16(
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -830,7 +830,7 @@
 
 

 // Signed integer saturating extract and unsigned narrow to high
-def SQXTUN2 : SOpInst<"vqmovun_high", "(;
+def SQXTUN2 : SOpInst<"vqmovun_high", "(;
 
 

 // Integer saturating extract and narrow to high
@@ -1498,7 +1498,7 @@
 
 

 // Scalar Signed Saturating Extract Unsigned Narrow
-def SCALAR_SQXTUN : SInst<"vqmovun", "(1<)1", "SsSiSl">;
+def SCALAR_SQXTUN : SInst<"vqmovun", "(U1<)1", "SsSiSl">;
 
 

 // Scalar Signed Saturating Extract Narrow


Index: clang/test/Sema/arm64-neon-header.c
===
--- c

[PATCH] D87291: [clang-format][regression][PR47461] ifdef causes catch to be seen as a function

2020-09-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D87291#2278743 , @curdeius wrote:

> LGTM.
> Don't we risk any other side effects?

There could be, but maybe we can address them as we see them.

The original reason for including this was so that the Linux kernel could use 
`try` as a variable, I'm trying not to break that but I'm not convinced that

`int try /* abc */ = 0;`

would consider try as a variable any more. my hope is they don't do that..


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

https://reviews.llvm.org/D87291

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


[PATCH] D87825: [ASTMatchers] Define clang::ast_matchers::decompositionDecl

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: JonasToth, aaron.ballman.
ro added a project: clang.
Herald added subscribers: usaxena95, kadircet, fedor.sergeev, jyknight.
ro requested review of this revision.
Herald added a subscriber: ilya-biryukov.

D87588  broke `Debug` builds on both 
Solaris/sparcv9 and Solaris/amd64:

  [48/224] Linking CXX executable bin/clang-query
  FAILED: bin/clang-query
  [...]
  Undefined   first referenced
   symbol in file
  _ZN5clang12ast_matchers17decompositionDeclE 
lib/libclangDynamicASTMatchers.a(Registry.cpp.o)
  ld: fatal: symbol referencing errors

This doesn't happen for `Release` builds or `x86_64-pc-linux-gnu` `Debug` 
builds.

However, from comparison with e.g. `linkageSpecDecl` it's clear that the 
definition in `clang/lib/ASTMatchers/ASTMatchersInternal.cpp` is missing and 
indeed adding it allows the builds to complete.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87825

Files:
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp


Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 typeAliasTemplateDecl;
 const internal::VariadicAllOfMatcher decl;
+const internal::VariadicAllOfMatcher decompositionDecl;
 const internal::VariadicDynCastAllOfMatcher
 linkageSpecDecl;
 const internal::VariadicDynCastAllOfMatcher namedDecl;


Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -710,6 +710,7 @@
 const internal::VariadicDynCastAllOfMatcher
 typeAliasTemplateDecl;
 const internal::VariadicAllOfMatcher decl;
+const internal::VariadicAllOfMatcher decompositionDecl;
 const internal::VariadicDynCastAllOfMatcher
 linkageSpecDecl;
 const internal::VariadicDynCastAllOfMatcher namedDecl;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87588: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

As described in D87825 , this patch broke 
`Debug` builds on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87588

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


[PATCH] D87825: [ASTMatchers] Define clang::ast_matchers::decompositionDecl

2020-09-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

SGTM, that's a pretty traditional issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87825

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


[PATCH] D87825: [ASTMatchers] Define clang::ast_matchers::decompositionDecl

2020-09-17 Thread Rainer Orth via Phabricator via cfe-commits
ro abandoned this revision.
ro added a comment.

Just found this had already been fixed in commit 
f0546173fa4bdde03ecb21a174fcaa8a6490adbd 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87825

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


[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-17 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D31413#2277085 , @sbc100 wrote:

> Might even be worth backporting such as simple but useful fix to the 11 
> release?

I think it's too late in the process for that. Might be a good candidate for 
11.0.1 though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[clang] 40e771c - [clang-format][regression][PR47461] ifdef causes catch to be seen as a function

2020-09-17 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-09-17T13:23:06+01:00
New Revision: 40e771c1c0d33c687230111271060c2ba761269f

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

LOG: [clang-format][regression][PR47461] ifdef causes catch to be seen as a 
function

https://bugs.llvm.org/show_bug.cgi?id=47461

The following change {D80940} caused a regression in code which ifdef's around 
the try and catch block cause incorrect brace placement around the catch

```
  try
  {
  }
  catch (...) {
// This is not a small function
bar = 1;
  }
}
```

The brace after the catch will be placed on a newline

Reviewed By: curdeius

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index f6db58acd8db..c1466196b4d6 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -401,7 +401,7 @@ bool FormatTokenLexer::tryTransformTryUsageForC() {
   if (!Try->is(tok::kw_try))
 return false;
   auto &Next = *(Tokens.end() - 1);
-  if (Next->isOneOf(tok::l_brace, tok::colon))
+  if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
 return false;
 
   if (Tokens.size() > 2) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 98e002003159..eae7b24fae7c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2743,6 +2743,43 @@ TEST_F(FormatTest, FormatTryAsAVariable) {
   verifyFormat("int catch, size;");
   verifyFormat("catch = foo();");
   verifyFormat("if (catch < size) {\n  return true;\n}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.BeforeCatch = true;
+  verifyFormat("try {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("#if NO_EX\n"
+   "try\n"
+   "#endif\n"
+   "{\n"
+   "}\n"
+   "#if NO_EX\n"
+   "catch (...) {\n"
+   "}",
+   Style);
+  verifyFormat("try /* abc */ {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("try\n"
+   "// abc\n"
+   "{\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, FormatSEHTryCatch) {



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


[PATCH] D87291: [clang-format][regression][PR47461] ifdef causes catch to be seen as a function

2020-09-17 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG40e771c1c0d3: [clang-format][regression][PR47461] ifdef 
causes catch to be seen as a function (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87291

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2743,6 +2743,43 @@
   verifyFormat("int catch, size;");
   verifyFormat("catch = foo();");
   verifyFormat("if (catch < size) {\n  return true;\n}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.BeforeCatch = true;
+  verifyFormat("try {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("#if NO_EX\n"
+   "try\n"
+   "#endif\n"
+   "{\n"
+   "}\n"
+   "#if NO_EX\n"
+   "catch (...) {\n"
+   "}",
+   Style);
+  verifyFormat("try /* abc */ {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("try\n"
+   "// abc\n"
+   "{\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, FormatSEHTryCatch) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -401,7 +401,7 @@
   if (!Try->is(tok::kw_try))
 return false;
   auto &Next = *(Tokens.end() - 1);
-  if (Next->isOneOf(tok::l_brace, tok::colon))
+  if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
 return false;
 
   if (Tokens.size() > 2) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2743,6 +2743,43 @@
   verifyFormat("int catch, size;");
   verifyFormat("catch = foo();");
   verifyFormat("if (catch < size) {\n  return true;\n}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.BeforeCatch = true;
+  verifyFormat("try {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("#if NO_EX\n"
+   "try\n"
+   "#endif\n"
+   "{\n"
+   "}\n"
+   "#if NO_EX\n"
+   "catch (...) {\n"
+   "}",
+   Style);
+  verifyFormat("try /* abc */ {\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
+  verifyFormat("try\n"
+   "// abc\n"
+   "{\n"
+   "  int bar = 1;\n"
+   "}\n"
+   "catch (...) {\n"
+   "  int bar = 1;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, FormatSEHTryCatch) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -401,7 +401,7 @@
   if (!Try->is(tok::kw_try))
 return false;
   auto &Next = *(Tokens.end() - 1);
-  if (Next->isOneOf(tok::l_brace, tok::colon))
+  if (Next->isOneOf(tok::l_brace, tok::colon, tok::hash, tok::comment))
 return false;
 
   if (Tokens.size() > 2) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added subscribers: trasz, dim, jrtc27.
jrtc27 added a comment.
Herald added a subscriber: dang.

This has significantly regressed FreeBSD's performance with the new version of 
Clang. It seems Clang does not inline functions at -O1, unlike GCC, and since 
FreeBSD currently compiles its kernel with -O whenever debug symbols are 
enabled[1], this results in all its `static inline` helper functions not being 
inlined at all, a pattern that is common in the kernel, used for things like 
`get_curthread` and the atomics implementations.

[1] This is a dubious decision made r140400 in 2005 to provide "truer debugger 
stack traces" (well, before then there was ping-ponging between -O and -O2 
based on concerns around correctness vs performance, but amd64 is an exception 
that has always used -O2 since r127180 it seems). Given that GCC will inline at 
-O, at least these days, the motivation seems to no longer exist, and compiling 
a kernel at anything other than -O2 (or maybe -O3) seems like a silly thing to 
do, but nevertheless it's what is currently done.

Cc: @dim @trasz


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-09-17 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 292469.
djtodoro added a comment.

- Rebasing


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/verify-debug-info-preservation.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-original-di-preservation.py sample.json sample.html
 
+The `original-di-check` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fverify-debuginfo-preserve -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export=sample.json -g -O2 sample.c
+
 Using ``VerifyDIPreserve``
 ^^
 
Index: clang/test/Driver/verify-debug-info-preservation.c
===
--- /dev/null
+++ clang/test/Driver/verify-debug-info-preservation.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE %s
+
+// VERIFYDIPRESERVE: "-fverify-debuginfo-preserve"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve \
+// RUN: -Xclang -fverify-debuginfo-preserve-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE-JSON-EXPORT %s
+
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve"
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -835,6 +835,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDIPreservationVerify =
+  Args.hasArg(OPT_fverify_debuginfo_preserve);
+  // Ignore the option if the -fverify-debuginfo-preserve wasn't enabled.
+  if (Opts.EnableDIPreservationVerify &&
+  Args.hasArg(OPT_fverify_debuginfo_preserve_export)) {
+ Opts.DIBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fverify_debuginfo_preserve_export));
+  }
+
   Opts.ValueTrackingVariableLocations =
   Args.hasArg(OPT_fexperimental_debug_variable_locations);
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -82,6 +82,7 @@
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
+#include "llvm/Transforms/Utils/VerifyDIPreserve.h"
 #include 
 using namespace clang;
 using namespace llvm;
@@ -893,7 +894,17 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  VerifyDIPreserveCustomPassManager PerModulePasses;
+  DebugInfoPerPassMap DIPreservationMap;
+  if (CodeGenOpts.EnableDIPreservationVerify) {
+PerModulePasses.setVerifyDIPreserveMode(
+VerifyDIPreserveMode::OriginalDebugInfo);
+PerModulePasses.setDIPreservationMap(DIPreservationMap);
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setOrigDIVerifyBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3894,6 +3894,16 @@
 def fexperimental_debug_variable_locations : Flag<["-"],
 "fexperimental-debug-variable-locations">,
 HelpText<"Use experimental new value-tracking variable locations">;
+def fverify_debuginfo_preserve
+: Flag<["-"], "fverify-debuginfo-preserve">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">;
+def fverify_debuginfo_preserve_export
+: Joined<["-"], "fverify-debuginfo-preserve-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debug info (by testing original Debug Info) failures "
+   "into specified (JSON) file (should be abs path as we use "
+   "append mode to insert new JSON objects)."

[clang] 788c7d2 - [clang][docs] Fix documentation of -O

2020-09-17 Thread Jessica Clarke via cfe-commits

Author: Jessica Clarke
Date: 2020-09-17T13:44:01+01:00
New Revision: 788c7d2ec11dfc868a5b03478c922dc9699c6d47

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

LOG: [clang][docs] Fix documentation of -O

D79916 changed the behaviour from -O2 to -O1 but the documentation was
not updated to reflect this.

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 11169e352894..a24e138e86a7 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -385,7 +385,7 @@ Code Generation Options
 :option:`-Og` Like :option:`-O1`. In future versions, this option might
 disable 
diff erent optimizations in order to improve debuggability.
 
-:option:`-O` Equivalent to :option:`-O2`.
+:option:`-O` Equivalent to :option:`-O1`.
 
 :option:`-O4` and higher
 



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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-17 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.

I think once @jrtc27 confirms all her issues are addressed this is good to land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 accepted this revision.
jrtc27 added a comment.
This revision is now accepted and ready to land.

Yes I think everything's been addressed now (though if I keep looking over it I 
might start nit-picking even more :)).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D87187: [Driver] Perform Linux distribution detection just once

2020-09-17 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a subscriber: rnk.
aganea added a comment.

Please install & run `git clang-format` before uploading the patch.




Comment at: clang/include/clang/Driver/Distro.h:27
+// Special value means that no detection was performed yet.
+UninitializedDistro = -1,
 // NB: Releases of a particular Linux distro should be kept together

You can leave out the `-1` since this isn't serialized.



Comment at: clang/lib/Driver/Distro.cpp:29
 
-  // If the host is not running Linux, and we're backed by a real file system,
-  // no need to check the distro. This is the case where someone is
-  // cross-compiling from BSD or Windows to Linux, and it would be meaningless
-  // to try to figure out the "distro" of the non-Linux host.
-  IntrusiveRefCntPtr RealFS =
-  llvm::vfs::getRealFileSystem();
-  llvm::Triple HostTriple(llvm::sys::getProcessTriple());
-  if (!HostTriple.isOSLinux() && &VFS == RealFS.get())
-return Distro::UnknownDistro;
+  if (File) {
+SmallVector Lines;

Early exit & move L23 to L32.



Comment at: clang/lib/Driver/Distro.cpp:54
+
   if (File) {
 SmallVector Lines;

Early exit to avoid indent and ease reading:
```
if (!File)
  return Distro::UnknownDistro;
```
Also move L50 to L57.



Comment at: clang/lib/Driver/Distro.cpp:205
+const llvm::Triple &TargetOrHost) {
+  static Distro::DistroType Type = Distro::UninitializedDistro;
+

I'm not sure if this is safe. @rnk Do we expect to call `GetDistro` with a 
different `VFS` or a different `Triple` when compiling with Clang? For GPU 
targets? Shouldn't we do this higher up, on the call site?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87187

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


[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D31413#2277985 , @ldionne wrote:

> In D31413#2277630 , @smeenai wrote:
>
>> What was the conclusion for the comments about the priority level (100 vs. 
>> 101)?
>
> My understanding is that values below `101` are literally not allowed:
>
>   <...>/llvm/libcxx/src/iostream.cpp:80:66: error: 'init_priority' attribute 
> requires integer constant between 101 and 65535 inclusive
>   _LIBCPP_HIDDEN ios_base::Init __start_std_streams 
> __attribute__((init_priority(100)));
>^  
>~~~
>   1 error generated.
>
> If there's a way around that, and if values below 101 are reserved for the 
> implementation, then I agree `100` is what we should use. @aaron.ballman 
> where did you read that values below 101 were reserved for the implementation?

From GCC itself: https://godbolt.org/z/zajPsj but also from libstdc++ 
maintainers https://gcc.gnu.org/legacy-ml/gcc-help/2014-08/msg00117.html

> The GCC docs at 
> https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html don't imply 
> that -- they say the attribute starts at 101. I agree it's a fairly logical 
> thing to think values before that would be reserved, but it doesn't say 
> explicitly.
>
> Is it possible that GCC reserves values before 101 for the implementation, 
> but Clang implemented the attribute "naively" and just errors out?

Yes, and the way I would handle this is to change the `init_priority` value 
checking to allow values <= 100 if the attribute location is within a system 
header. This would allow libc++ to use the reserved priority but would still 
give errors when attempted from user code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[PATCH] D84470: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D84470#2277991 , @ronlieb wrote:

> The latest patch applied cleanly to our downstream port.
> builds fine, tests very nicely as well. All the failing SOLLVE task wait 
> depend tests now pass.

Could you accept it then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84470

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


[PATCH] D84470: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-17 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb accepted this revision.
ronlieb added a comment.
This revision is now accepted and ready to land.

accepted. not sure if there were any outstanding comments from Johannes. your 
call


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84470

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


[PATCH] D87652: Sema: add support for `__attribute__((__swift_newtype__))`

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2179
+def SwiftNewType : InheritableAttr {
+  let Spellings = [GNU<"swift_newtype">, GNU<"swift_wrapper">];
+  let Args = [EnumArgument<"NewtypeKind", "NewtypeKind",

compnerd wrote:
> aaron.ballman wrote:
> > We don't ever document `swift_wrapper`, is that intentional?
> > 
> > (Do you have code elsewhere that's looking at the spelling of the AST 
> > attribute object? Should you add an `AdditionalMembers` to this declaration 
> > to make that easier to distinguish?)
> Yes, that was intentional.  I believe that `swift_wrapper` predates 
> `swift_newtype` and is only kept for compatibility.  People should gravitate 
> towards `swift_newtype`.
> 
> I don't understand the need for `AdditionalMembers`.
Ah, thank you for the explanation. I think we should document `swift_wrapper` 
as explicitly being deprecated then so it's clear to people (esp Future Aaron) 
what the intent is. It sounds like there's no need for `AdditionalMembers` 
(that's only useful if you need to distinguish between the spellings that share 
a semantic attribute).



Comment at: clang/include/clang/Basic/Attr.td:2183
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftNewTypeDocs];
+}

compnerd wrote:
> aaron.ballman wrote:
> > You should also set: `let HasCustomParsing = 1;` since this uses a custom 
> > parser.
> > 
> > Is the custom parser actually needed though? Or is it only needed because 
> > the enum names selected are keywords? If it's only because of the keyword 
> > nature, should the parser be improved in 
> > `Parser::ParseAttributeArgsCommon()` instead?
> It's for the keyword handling.  I'll take a look and see if I can convert 
> this to the `ParseAttributeArgsCommon` path.
If you can easily modify `ParseAttributeArgsCommon`, then awesome! If that 
turns out to be a slog, I don't insist on the change being made.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4038
+def warn_swift_newtype_attribute_non_typedef
+  : Warning<"%0 attribute may be put on a typedef only; attribute is ignored">,
+InGroup>;

compnerd wrote:
> aaron.ballman wrote:
> > Hrm, we already have existing diagnostics to cover this 
> > (`warn_attribute_wrong_decl_type_str`) but it's in the `IgnoredAttributes` 
> > group. Do you need a new warning group specific to this? Is there a reason 
> > that group is not a subset of `IgnoredAttributes`?
> Hmm, Im okay with changing the group, but I do wonder if Apple is going to 
> worry about diagnostic compatibility.  @doug.gregor, @rjmccall, or 
> @dexonsmith would be better suited to answer the question about command line 
> compatibility.
If you need specific control over the swift attribute diagnostics for ignored 
attributes, you could make the group be a part of `IgnoredAttributes` (so by 
default, swift ignored attributes are controlled by `IgnoredAttributes` but can 
be selectively enabled/disabled).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87652

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


[PATCH] D79432: [analyzer] StdLibraryFunctionsChecker: Add summaries for libc

2020-09-17 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1123-1124
+  "abs", Summary(ArgTypes{IntTy}, RetType{IntTy}, EvalCallAsPure)
+ .Case({ArgumentCondition(0, WithinRange, SingleValue(0)),
+ReturnValueCondition(WithinRange, SingleValue(0))})
+ .Case({ArgumentCondition(0, WithinRange, Range(1, IntMax)),

balazske wrote:
> martong wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > The three-way state split is unjustified here. Usage of `abs` is not a 
> > > > sufficient indication that the value may be 0, otherwise:
> > > > ```lang=c++
> > > > int foo(int x, int y) {
> > > >   int z = abs(y);   // Assuming 'abs' has taken branch on which y == 
> > > > 0...
> > > >   return x / z; // ... we'll be forced to emit a division by zero 
> > > > warning here.
> > > > }
> > > > ```
> > > > 
> > > > Generally, there are very few cases when state splits upon function 
> > > > calls are justified. The common cases are:
> > > > - The function returns bool and finding that bool is the only reason to 
> > > > ever call this function. Eg., `isalpha()` and such.
> > > > - The function can at any time completely unpredictably take any of the 
> > > > branches, in other words, taint is involved. Eg., `scanf()` can always 
> > > > fail simply because the user of the program wrote something special 
> > > > into stdin.
> > > > returns bool
> > > 
> > > Or something that kinda resembles bool (eg., `isalpha()` returns a 
> > > variety of different ints in practice due to its static lookup table 
> > > implementation strategy but the user only cares about whether it's zero 
> > > or non-zero).
> > Alright, I agree, I'll remove these cases. 
> > 
> > Generally speaking I realized that it is hard to create these cases, and it 
> > is very rare when we can come up with a meaningful case set for any 
> > function. So while we are at it, could you please take a look at another 
> > patch, where I add no cases just argument constraints: D82288 ?
> But it could make sense that if the input of the function is known before the 
> call, we can compute the output? For `abs(x)` if we know that `x == 0` is 
> true the checker could assume `abs(x) == 0` too. These "cases" provide data 
> for this functionality.
> For abs(x) if we know that x == 0 is true the checker could assume abs(x) == 
> 0 too. 
Yes, this is absolutely true.

I think, we could approach this with introducing a postcall Kind for the 
summaries. Currently, we already have `EvalCallAsPure` and `NoEvalCall` for 
evalCall. We could have let's say 
```
enum PostCallKind { UnconditionedStateSplit, 
ConstrainReturnIfArgConstraintsAreSatisfied }
```
For the ConstrainReturnIfArgConstraintsAreSatisfied we should check if the 
preconditions for the Args in the Case are all evaluated to Known and if so 
only would we apply the constraint on the return value.
@NoQ What do you think?
@steakhal FYI.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79432

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


[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:3582
+
+The parameter takes the single string representation of the Swift function 
name.
+The name may be a compound Swift name.  For a type, enum constant, property, or

The parameter takes -> The argument is



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3977
 
+// Swift attributes.
+def warn_attr_swift_name_function

I want to make sure we're clear with the terminology used in the diagnostics, 
so there's a fair number of "take -> have" suggestions here, but I want to be 
sure I'm correct before you apply those suggestions.

I'm used to function declarations having parameters which take arguments from a 
function call expression. Are the diagnostics about "taking a parameter" 
talking about "having a parameter" or about "taking an argument"? I believe the 
string arguments are function signatures rather than function names (perhaps?) 
and so we should be talking about having a parameter, but I wasn't 100% sure.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3979
+def warn_attr_swift_name_function
+  : Warning<"parameter of %0 attribute must be a Swift function name string">,
+InGroup;

How about: `%0 attribute argument must be a string literal specifying a Swift 
function name`?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3988
+def warn_attr_swift_name_subscript_not_accessor
+  : Warning<"%0 attribute for 'subscript' must be a getter or setter">,
+InGroup;

`%0 attribute for 'subscript' must %select{be a getter or setter|have at least 
one parameter|have a 'self' parameter}1` ?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3994
+def warn_attr_swift_name_subscript_no_parameter
+  : Warning<"%0 attribute for 'subscript' must take at least one parameter">,
+InGroup;

take -> have



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3997
+def warn_attr_swift_name_setter_parameters
+  : Warning<"%0 attribute for setter must take one parameter for new value">,
+InGroup;

take -> have

elsewhere `new value` is spelled `'newValue:`, should that be the same here?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4006
+def warn_attr_swift_name_getter_parameters
+  : Warning<"%0 attribute for getter must not take any parameters besides 
'self:'">,
+InGroup;

take -> have



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4009
+def warn_attr_swift_name_subscript_setter_no_newValue
+  : Warning<"%0 attribute for 'subscript' setter must take a 'newValue:' 
parameter">,
+InGroup;

take -> have



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4012
+def warn_attr_swift_name_subscript_setter_multiple_newValues
+  : Warning<"%0 attribute for 'subscript' setter cannot take multiple 
'newValue:' parameters">,
+InGroup;

take -> have



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4015
+def warn_attr_swift_name_subscript_getter_newValue
+  : Warning<"%0 attribute for 'subscript' getter cannot take a 'newValue:' 
parameter">,
+InGroup;

take -> have



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4017
+InGroup;
+def warn_attr_swift_name_function_no_prototype
+  : Warning<"%0 attribute can only be applied to function declarations with 
prototypes">,

I don't think you need this diagnostic -- you should be able to use 
`warn_attribute_wrong_decl_type` (it has a non-K&R-style functions option which 
is a bit more clear).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

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


[PATCH] D87830: [clang-tidy][test] Allow empty checks in check_clang_tidy.py

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 created this revision.
Herald added subscribers: cfe-commits, martong, steakhal, Szelethus, dkrupp, 
xazax.hun, whisperity.
Herald added a project: clang.
gamesh411 requested review of this revision.

Currently there is no way to assert that a check does not produce warnings for 
a specific run. The CHECK-NOT directive can be used, but an empty file is 
always discarded by FileCheck. Extend the FileCheck invocation with 
'--allow-empty' to support this usecase.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87830

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87830: [clang-tidy][test] Allow empty checks in check_clang_tidy.py

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 292485.
gamesh411 added a comment.

Update commit msg with example


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87830

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87830: [clang-tidy][test] Allow empty checks in check_clang_tidy.py

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 292487.
gamesh411 added a comment.

Tidy up commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87830

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -167,7 +167,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
'-check-prefixes=' + ','.join(check_fixes_prefixes),
-   '-strict-whitespace'],
+   '-strict-whitespace', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -180,7 +180,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
'-check-prefixes=' + ','.join(check_messages_prefixes),
-   '-implicit-check-not={{warning|error}}:'],
+   '-implicit-check-not={{warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -195,7 +195,7 @@
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,
'-check-prefixes=' + ','.join(check_notes_prefixes),
-   '-implicit-check-not={{note|warning|error}}:'],
+   '-implicit-check-not={{note|warning|error}}:', '--allow-empty'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-09-17 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 292488.
gamesh411 added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c-teminate.cpp
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
@@ -19,6 +19,7 @@
 "CommandProcessorCheck.cpp",
 "DefaultOperatorNewAlignmentCheck.cpp",
 "DontModifyStdNamespaceCheck.cpp",
+"ExitHandlerCheck.cpp",
 "FloatLoopCounter.cpp",
 "LimitedRandomnessCheck.cpp",
 "MutatingCopyCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
@@ -0,0 +1,412 @@
+// Test as a C file.
+// RUN: %check_clang_tidy %s cert-env32-c %t -- -- -DCMODE
+//
+// Test as a C++ file.
+//
+// Test functions in global namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE
+//
+// Test functions in std namespace.
+// RUN: %check_clang_tidy -assume-filename=%s.cpp %s cert-env32-c %t \
+// RUN: -- -- -DCPPMODE -DTEST_NS_NAME=std
+
+#if defined(CPPMODE) && defined(TEST_NS_NAME)
+namespace TEST_NS_NAME {
+#endif
+
+// --
+// EXIT FUNCTIONS
+// --
+
+// No handlers are invoked when _Exit is called.
+void _Exit(int __status);
+
+// Handlers registered by atexit are invoked in reverse order when exit is
+// called.
+void exit(int __status);
+
+// Handlers registered by at_quick_exit are invoked in reverse order when
+// quick_exit is called.
+void quick_exit(int __status);
+
+// The program is terminated without destroying any object and without calling
+// any of the functions passed to atexit or at_quick_exit.
+void abort();
+
+// 
+// HANDLER REGISTRATION
+// 
+
+// Register handlers to run when exit is called.
+int atexit(void (*__func)(void));
+
+// Register handlers to run when exit is called.
+int at_quick_exit(void (*__func)(void));
+
+// --
+// Setjmp/longjmp
+// --
+// C99 requires jmp_buf to be an array type.
+typedef int jmp_buf[1];
+int setjmp(jmp_buf);
+void longjmp(jmp_buf, int);
+
+// Compliant solutions
+
+void cleanup1() {
+  // do cleanup
+}
+
+void cleanup2() {
+  // do cleanup
+}
+
+void test_atexit_single_compliant() {
+  (void)atexit(cleanup1);
+}
+
+void test_atexit_multiple_compliant() {
+  (void)atexit(cleanup1);
+  (void)atexit(cleanup2);
+}
+
+void test_at_quick_exit_single_compliant() {
+  (void)at_quick_exit(cleanup1);
+}
+
+void test_at_quick_exit_multiple_compliant() {
+  (void)at_quick_exit(cleanup1);
+  (void)at_quick_exit(cleanup2);
+}
+
+// Non-compliant solutions calling _Exit
+
+void call__Exit() {
+  _Exit(0);
+}
+
+void call_call__Exit() {
+  call__Exit();
+}
+
+extern int unknown__Exit_flag;
+
+void call__Exit_conditionally() {
+  if (unknown__Exit_flag)
+call__Exit();
+}
+
+void call_call__Exit_conditionally() {
+  call__Exit_conditionally();
+}
+
+void test__Exit_called_directly() {
+  (void)atexit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-22]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-22]]:3: note: exit function called here
+  (void)at_quick_exit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-26]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-26]]:3: note: exit function called here
+};
+
+void test__Exit_called_indirectly() {
+  (void)atexit(call_call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function instead of terminating normally with a return [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-29]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-33]]:3: note: exit function called here
+  (void)at_quick_exit(call_call__Exit);
+  // CH

[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

One of the concerns I have with this not being a flow-sensitive check is that 
most of the bad situations are not going to be caught by the clang-tidy version 
of the check. The CERT rules show contrived code examples, but the more 
frequent issue looks like:

  void cleanup(struct whatever *ptr) {
assert(ptr); // This potentially calls abort()
free(ptr->buffer);
free(ptr);
  }
  
  void some_cleanup_func(void) {
for (size_t idx = 0; idx < GlobalElementCount; ++idx) {
  cleanup(GlobalElement[idx]);
}
  }
  
  void some_exit_handler(void) {
...
some_cleanup_func();
...
  }

The fact that we're not looking through the call sites (even without cross-TU 
support) means the check isn't going to catch the most problematic cases. You 
could modify the called function collector to gather this a bit better, but 
you'd issue false positives in flow-sensitive situations like:

  void some_cleanup_func(void) {
for (size_t idx = 0; idx < GlobalElementCount; ++idx) {
  struct whatever *ptr = GlobalElement[idx];
  if (ptr) {
// Now we know abort() won't be called
cleanup(ptr);
  }
}
  }

Have you run this check over any large code bases to see if it currently 
catches any true positive diagnostics?




Comment at: clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp:101
+  diag(RegisterCall->getBeginLoc(),
+   "exit-handler potentially calls an exit function instead of terminating 
"
+   "normally with a return");

I know it was my suggestion originally, but I realize that's just describing 
the code not what's wrong with it. How about: `exit handler potentially 
terminates the program without running other exit handlers`?



Comment at: clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp:114
+  diag(RegisterCall->getSourceRange().getBegin(),
+   "exit-handler potentially calls a longjmp instead of terminating "
+   "normally with a return");

Similar suggestion here: `exit handler potentially calls 'longjmp' which may 
fail to run other exit handlers`?



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst:7
+Finds functions registered by ``atexit`` and ``at_quick_exit`` that are calling
+exit functions ``_Exit``, ``exit``, ``quick_exit`` or ``longjmp``.
+

`terminate`?



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst:9
+
+All exit handlers must return normally
+--

You should not copy and paste the text from the CERT standard here. There would 
be copyright questions from that, but also, the CERT standard is a wiki that 
gets updated with some regularity so these docs are likely to get stale anyway.

We usually handle this by paraphrasing a bit about what the rule is checking 
for, and then provide a link directly to the CERT rule for the user to get the 
details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

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


[PATCH] D87812: [FPEnv] Use typed accessors in FPOptions

2020-09-17 Thread Melanie Blower via Phabricator via cfe-commits
mibintc accepted this revision.
mibintc added a comment.
This revision is now accepted and ready to land.

LGTM - thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87812

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


[PATCH] D87720: Sema: add support for `__attribute__((__swift_private__))`

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2189
+  let Subjects =
+  SubjectList<[Enum, Function, Struct, TypedefName,
+   ObjCClassMethod, ObjCInstanceMethod, ObjCInterface, 
ObjCProperty, ObjCProtocol],

Similar concerns here with listing all of the subjects as with the other 
review? (I don't have strong opinions.)



Comment at: clang/lib/Sema/SemaDecl.cpp:2613-2614
SNA->getName(), AMK == Sema::AMK_Override);
+  else if (isa(Attr) && AMK == Sema::AMK_Override)
+NewAttr = nullptr;
   else if (const auto *OA = dyn_cast(Attr))

Hmm, I'm a bit confused. The attribute is an inheritable attribute, but when we 
try to merge attributes between declarations, we drop it?



Comment at: clang/test/SemaObjC/attr-swift-private.m:1
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s
+

No need for blocks support?



Comment at: clang/test/SemaObjC/attr-swift-private.m:25
+};
+
+typedef struct { } T __attribute__((__swift_private__));

Should also have tests for the subjects you expect not to work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87720

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


[PATCH] D87831: [clang] Expose helper function to turn PP keywords spelling into PPKeywordKind

2020-09-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
kbobyrev requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87831

Files:
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang/include/clang/Basic/TokenKinds.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Basic/TokenKinds.cpp

Index: clang/lib/Basic/TokenKinds.cpp
===
--- clang/lib/Basic/TokenKinds.cpp
+++ clang/lib/Basic/TokenKinds.cpp
@@ -65,3 +65,56 @@
   }
   return false;
 }
+
+tok::PPKeywordKind tok::getPPKeywordFromSpelling(const std::string &Name) {
+  // We use a perfect hash function here involving the length of the keyword,
+  // the first and third character.  For preprocessor ID's there are no
+  // collisions (if there were, the switch below would complain about duplicate
+  // case values).  Note that this depends on 'if' being null terminated.
+  unsigned Len = Name.size();
+
+#define HASH(LEN, FIRST, THIRD)\
+  (LEN << 5) + (((FIRST - 'a') + (THIRD - 'a')) & 31)
+#define CASE(LEN, FIRST, THIRD, NAME)  \
+  case HASH(LEN, FIRST, THIRD):\
+return memcmp(Name.c_str(), #NAME, LEN) ? tok::pp_not_keyword  \
+: tok::pp_##NAME
+
+  if (Len < 2)
+return tok::pp_not_keyword;
+  switch (HASH(Len, Name[0], Name[2])) {
+  default:
+return tok::pp_not_keyword;
+CASE(2, 'i', '\0', if);
+CASE(4, 'e', 'i', elif);
+CASE(4, 'e', 's', else);
+CASE(4, 'l', 'n', line);
+CASE(4, 's', 'c', sccs);
+CASE(5, 'e', 'd', endif);
+CASE(5, 'e', 'r', error);
+CASE(5, 'i', 'e', ident);
+CASE(5, 'i', 'd', ifdef);
+CASE(5, 'u', 'd', undef);
+
+CASE(6, 'a', 's', assert);
+CASE(6, 'd', 'f', define);
+CASE(6, 'i', 'n', ifndef);
+CASE(6, 'i', 'p', import);
+CASE(6, 'p', 'a', pragma);
+
+CASE(7, 'd', 'f', defined);
+CASE(7, 'i', 'c', include);
+CASE(7, 'w', 'r', warning);
+
+CASE(8, 'u', 'a', unassert);
+CASE(12, 'i', 'c', include_next);
+
+CASE(14, '_', 'p', __public_macro);
+
+CASE(15, '_', 'p', __private_macro);
+
+CASE(16, '_', 'i', __include_macros);
+#undef CASE
+#undef HASH
+  }
+}
Index: clang/lib/Basic/IdentifierTable.cpp
===
--- clang/lib/Basic/IdentifierTable.cpp
+++ clang/lib/Basic/IdentifierTable.cpp
@@ -271,54 +271,7 @@
 }
 
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
-  // We use a perfect hash function here involving the length of the keyword,
-  // the first and third character.  For preprocessor ID's there are no
-  // collisions (if there were, the switch below would complain about duplicate
-  // case values).  Note that this depends on 'if' being null terminated.
-
-#define HASH(LEN, FIRST, THIRD) \
-  (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
-#define CASE(LEN, FIRST, THIRD, NAME) \
-  case HASH(LEN, FIRST, THIRD): \
-return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
-
-  unsigned Len = getLength();
-  if (Len < 2) return tok::pp_not_keyword;
-  const char *Name = getNameStart();
-  switch (HASH(Len, Name[0], Name[2])) {
-  default: return tok::pp_not_keyword;
-  CASE( 2, 'i', '\0', if);
-  CASE( 4, 'e', 'i', elif);
-  CASE( 4, 'e', 's', else);
-  CASE( 4, 'l', 'n', line);
-  CASE( 4, 's', 'c', sccs);
-  CASE( 5, 'e', 'd', endif);
-  CASE( 5, 'e', 'r', error);
-  CASE( 5, 'i', 'e', ident);
-  CASE( 5, 'i', 'd', ifdef);
-  CASE( 5, 'u', 'd', undef);
-
-  CASE( 6, 'a', 's', assert);
-  CASE( 6, 'd', 'f', define);
-  CASE( 6, 'i', 'n', ifndef);
-  CASE( 6, 'i', 'p', import);
-  CASE( 6, 'p', 'a', pragma);
-
-  CASE( 7, 'd', 'f', defined);
-  CASE( 7, 'i', 'c', include);
-  CASE( 7, 'w', 'r', warning);
-
-  CASE( 8, 'u', 'a', unassert);
-  CASE(12, 'i', 'c', include_next);
-
-  CASE(14, '_', 'p', __public_macro);
-
-  CASE(15, '_', 'p', __private_macro);
-
-  CASE(16, '_', 'i', __include_macros);
-#undef CASE
-#undef HASH
-  }
+  return tok::getPPKeywordFromSpelling(getNameStart());
 }
 
 //===--===//
Index: clang/include/clang/Basic/TokenKinds.h
===
--- clang/include/clang/Basic/TokenKinds.h
+++ clang/include/clang/Basic/TokenKinds.h
@@ -96,6 +96,8 @@
 /// Return true if this is an annotation token representing a pragma.
 bool isPragmaAnnotation(TokenKind K);
 
+PPKeywordKind getPPKeywordFromSpelling(const std::string &Name);
+
 } // end namespace tok
 } // end namespace clang
 
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===
--- clang-tools-extra

[PATCH] D78305: [NFC] Rename Sema.FPFeatures to CurFPFeatures and accessor to getCurFPFeatures

2020-09-17 Thread Melanie Blower via Phabricator via cfe-commits
mibintc abandoned this revision.
mibintc added a comment.

not needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78305

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


[PATCH] D87164: Extending Baremetal toolchain's support for the rtlib option.

2020-09-17 Thread Manuel Carrasco via Phabricator via cfe-commits
mcarrasco marked an inline comment as done.
mcarrasco added a comment.

Great!

Thanks a lot for your answer @jroelofs !!

Then, do you think this current proposal to BareMetal.cpp is enough?

Best,
Manuel.


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

https://reviews.llvm.org/D87164

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


[PATCH] D87831: [clang] Expose helper function to turn PP keywords spelling into PPKeywordKind

2020-09-17 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.h:99
 
+PPKeywordKind getPPKeywordFromSpelling(const std::string &Name);
+

A string is expensive here and unneeded. Why not a `StringRef`?



Comment at: clang/lib/Basic/IdentifierTable.cpp:274
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
-  // We use a perfect hash function here involving the length of the keyword,
-  // the first and third character.  For preprocessor ID's there are no
-  // collisions (if there were, the switch below would complain about duplicate
-  // case values).  Note that this depends on 'if' being null terminated.
-
-#define HASH(LEN, FIRST, THIRD) \
-  (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
-#define CASE(LEN, FIRST, THIRD, NAME) \
-  case HASH(LEN, FIRST, THIRD): \
-return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
-
-  unsigned Len = getLength();
-  if (Len < 2) return tok::pp_not_keyword;
-  const char *Name = getNameStart();
-  switch (HASH(Len, Name[0], Name[2])) {
-  default: return tok::pp_not_keyword;
-  CASE( 2, 'i', '\0', if);
-  CASE( 4, 'e', 'i', elif);
-  CASE( 4, 'e', 's', else);
-  CASE( 4, 'l', 'n', line);
-  CASE( 4, 's', 'c', sccs);
-  CASE( 5, 'e', 'd', endif);
-  CASE( 5, 'e', 'r', error);
-  CASE( 5, 'i', 'e', ident);
-  CASE( 5, 'i', 'd', ifdef);
-  CASE( 5, 'u', 'd', undef);
-
-  CASE( 6, 'a', 's', assert);
-  CASE( 6, 'd', 'f', define);
-  CASE( 6, 'i', 'n', ifndef);
-  CASE( 6, 'i', 'p', import);
-  CASE( 6, 'p', 'a', pragma);
-
-  CASE( 7, 'd', 'f', defined);
-  CASE( 7, 'i', 'c', include);
-  CASE( 7, 'w', 'r', warning);
-
-  CASE( 8, 'u', 'a', unassert);
-  CASE(12, 'i', 'c', include_next);
-
-  CASE(14, '_', 'p', __public_macro);
-
-  CASE(15, '_', 'p', __private_macro);
-
-  CASE(16, '_', 'i', __include_macros);
-#undef CASE
-#undef HASH
-  }
+  return tok::getPPKeywordFromSpelling(getNameStart());
 }

Better to use `IdentifierInfo::getName()` to avoid recomputing the length.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87831

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


[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-17 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In D31413#2279182 , @aaron.ballman 
wrote:

> Yes, and the way I would handle this is to change the `init_priority` value 
> checking to allow values <= 100 if the attribute location is within a system 
> header. This would allow libc++ to use the reserved priority but would still 
> give errors when attempted from user code.

Ok, that makes sense. If Clang implements that change, I can go back and change 
it in libc++. I unfortunately don't have bandwidth to go and do that, since 
this isn't affecting a platform I directly work on. So if anyone's willing to 
go and change Clang to make that work, ping me here and I'll fix libc++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[clang] d5ce823 - [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-17 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-09-17T11:21:10-04:00
New Revision: d5ce8233bfcfdeb66c715a1def8e0b34d236d48a

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

LOG: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

This patch fixes the problem that user-defined mapper array is not correctly 
privatized inside a task. This problem causes 
openmp/libomptarget/test/offloading/target_depend_nowait.cpp fails.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_depend_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index dfd9752c20c9..d402e13c2134 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3784,9 +3784,9 @@ static void emitPrivatesInit(CodeGenFunction &CGF,
   bool IsTargetTask =
   isOpenMPTargetDataManagementDirective(D.getDirectiveKind()) ||
   isOpenMPTargetExecutionDirective(D.getDirectiveKind());
-  // For target-based directives skip 3 firstprivate arrays BasePointersArray,
-  // PointersArray and SizesArray. The original variables for these arrays are
-  // not captured and we get their addresses explicitly.
+  // For target-based directives skip 4 firstprivate arrays BasePointersArray,
+  // PointersArray, SizesArray, and MappersArray. The original variables for
+  // these arrays are not captured and we get their addresses explicitly.
   if ((!IsTargetTask && !Data.FirstprivateVars.empty() && ForDup) ||
   (IsTargetTask && KmpTaskSharedsPtr.isValid())) {
 SrcBase = CGF.MakeAddrLValue(
@@ -3809,7 +3809,7 @@ static void emitPrivatesInit(CodeGenFunction &CGF,
   if (const VarDecl *Elem = Pair.second.PrivateElemInit) {
 const VarDecl *OriginalVD = Pair.second.Original;
 // Check if the variable is the target-based BasePointersArray,
-// PointersArray or SizesArray.
+// PointersArray, SizesArray, or MappersArray.
 LValue SharedRefLValue;
 QualType Type = PrivateLValue.getType();
 const FieldDecl *SharedField = CapturesInfo.lookup(OriginalVD);
@@ -8866,6 +8866,17 @@ emitOffloadingArrays(CodeGenFunction &CGF,
   }
 }
 
+namespace {
+/// Additional arguments for emitOffloadingArraysArgument function.
+struct ArgumentsOptions {
+  bool ForEndCall = false;
+  bool IsTask = false;
+  ArgumentsOptions() = default;
+  ArgumentsOptions(bool ForEndCall, bool IsTask)
+  : ForEndCall(ForEndCall), IsTask(IsTask) {}
+};
+} // namespace
+
 /// Emit the arguments to be passed to the runtime library based on the
 /// arrays of base pointers, pointers, sizes, map types, and mappers.  If
 /// ForEndCall, emit map types to be passed for the end of the region instead 
of
@@ -8874,8 +8885,9 @@ static void emitOffloadingArraysArgument(
 CodeGenFunction &CGF, llvm::Value *&BasePointersArrayArg,
 llvm::Value *&PointersArrayArg, llvm::Value *&SizesArrayArg,
 llvm::Value *&MapTypesArrayArg, llvm::Value *&MappersArrayArg,
-CGOpenMPRuntime::TargetDataInfo &Info, bool ForEndCall = false) {
-  assert((!ForEndCall || Info.separateBeginEndCalls()) &&
+CGOpenMPRuntime::TargetDataInfo &Info,
+const ArgumentsOptions &Options = ArgumentsOptions()) {
+  assert((!Options.ForEndCall || Info.separateBeginEndCalls()) &&
  "expected region end call to runtime only when end call is separate");
   CodeGenModule &CGM = CGF.CGM;
   if (Info.NumberOfPtrs) {
@@ -8893,14 +8905,17 @@ static void emitOffloadingArraysArgument(
 /*Idx0=*/0, /*Idx1=*/0);
 MapTypesArrayArg = CGF.Builder.CreateConstInBoundsGEP2_32(
 llvm::ArrayType::get(CGM.Int64Ty, Info.NumberOfPtrs),
-ForEndCall && Info.MapTypesArrayEnd ? Info.MapTypesArrayEnd
-: Info.MapTypesArray,
+Options.ForEndCall && Info.MapTypesArrayEnd ? Info.MapTypesArrayEnd
+: Info.MapTypesArray,
 /*Idx0=*/0,
 /*Idx1=*/0);
-MappersArrayArg =
-Info.HasMapper
-? CGF.Builder.CreatePointerCast(Info.MappersArray, 
CGM.VoidPtrPtrTy)
-: llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy);
+// Always emit the mapper array address in case of a target task for
+// privatization.
+if (!Options.IsTask && !Info.HasMapper)
+  MappersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy);
+else
+  MappersArrayArg =
+  CGF.Builder.CreatePointerCast(Info.MappersArray, CGM.VoidPtrPtrTy);
   } else {
 BasePointersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy);
 PointersArrayArg = llvm::ConstantPointerNull::get(CGM.VoidPtrPtrTy);
@@ -9648

[PATCH] D84470: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-17 Thread Alexey Bataev 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 rGd5ce8233bfcf: [OpenMP 5.0] Fix user-defined mapper 
privatization in tasks (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84470

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_depend_codegen.cpp

Index: clang/test/OpenMP/target_depend_codegen.cpp
===
--- clang/test/OpenMP/target_depend_codegen.cpp
+++ clang/test/OpenMP/target_depend_codegen.cpp
@@ -43,8 +43,8 @@
 
 // TCHECK: [[ENTTY:%.+]] = type { i8*, i8*, i{{32|64}}, i32, i32 }
 
-// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 4]
-// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]
+// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [3 x i64] [i64 0, i64 4, i64 {{16|12}}]
+// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [3 x i64] [i64 544, i64 800, i64 3]
 // CHECK-DAG: @{{.*}} = weak constant i8 0
 
 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
@@ -61,6 +61,9 @@
   ty Y;
 };
 
+#pragma omp declare mapper(id \
+   : TT  \
+   s) map(s.X, s.Y)
 int global;
 extern int global;
 
@@ -102,29 +105,75 @@
   // CHECK:   [[BOOL:%.+]] = icmp ne i32 %{{.+}}, 0
   // CHECK:   br i1 [[BOOL]], label %[[THEN:.+]], label %[[ELSE:.+]]
   // CHECK:   [[THEN]]:
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP:%.+]], i32 0, i32 0
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[MADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M:%.+]], i[[SZ]] 0, i[[SZ]] 0
   // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]**
   // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]**
   // CHECK-DAG:   store i[[SZ]]* [[BP0:%[^,]+]], i[[SZ]]** [[CBPADDR0]]
   // CHECK-DAG:   store i[[SZ]]* [[BP0]], i[[SZ]]** [[CPADDR0]]
+  // CHECK-DAG:   store i8* null, i8** [[MADDR0]],
 
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1
+  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 1
+  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 1
+  // CHECK-DAG:   [[MADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M]], i[[SZ]] 0, i[[SZ]] 1
   // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
   // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
   // CHECK-DAG:   store i[[SZ]] [[BP1:%[^,]+]], i[[SZ]]* [[CBPADDR1]]
   // CHECK-DAG:   store i[[SZ]] [[BP1]], i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0
-  // CHECK-DAG:   getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0
+  // CHECK-DAG:   store i8* null, i8** [[MADDR1]],
+
+  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 2
+  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 2
+  // CHECK-DAG:   [[MADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M]], i[[SZ]] 0, i[[SZ]] 2
+  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to [[STRUCT_TT:%.+]]**
+  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to [[STRUCT_TT]]**
+  // CHECK-DAG:   store [[STRUCT_TT]]* [[D_ADDR:%.+]], [[STRUCT_TT]]** [[CBPADDR2]]
+  // CHECK-DAG:   store [[STRUCT_TT]]* [[D_ADDR]], [[STRUCT_TT]]** [[CPADDR2]]
+  // CHECK-DAG:   store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MAPPER_ID:@.+]] to i8*), i8** [[MADDR2]],
+
+  // CHECK-DAG:   [[BP_START:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 0
+  // CHECK-DAG:   [[P_START:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 0
+  // CHECK-DAG:   [[M_START:%.+]] = bitcast [3 x i8*]* [[M]] to i8**
   // CHECK:   [[GEP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
   // CHECK:   [[DEV1:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_

[clang] 40df06c - [CUDA][HIP] Defer overloading resolution diagnostics for host device functions

2020-09-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-09-17T11:30:42-04:00
New Revision: 40df06cdafc010002fc9cfe1dda73d689b7d27a6

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

LOG: [CUDA][HIP] Defer overloading resolution diagnostics for host device 
functions

In CUDA/HIP a function may become implicit host device function by
pragma or constexpr. A host device function is checked in both
host and device compilation. However it may be emitted only
on host or device side, therefore the diagnostics should be
deferred until it is known to be emitted.

Currently clang is only able to defer certain diagnostics. This causes
false alarms and limits the usefulness of host device functions.

This patch lets clang defer all overloading resolution diagnostics for host 
device functions.

An option -fgpu-defer-diag is added to control this behavior. By default
it is off.

It is NFC for other languages.

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

Added: 
clang/test/SemaCUDA/deferred-oeverload.cu
clang/test/TableGen/deferred-diag.td

Modified: 
clang/include/clang/Basic/Diagnostic.td
clang/include/clang/Basic/DiagnosticAST.h
clang/include/clang/Basic/DiagnosticAnalysis.h
clang/include/clang/Basic/DiagnosticComment.h
clang/include/clang/Basic/DiagnosticCrossTU.h
clang/include/clang/Basic/DiagnosticDriver.h
clang/include/clang/Basic/DiagnosticFrontend.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/DiagnosticLex.h
clang/include/clang/Basic/DiagnosticParse.h
clang/include/clang/Basic/DiagnosticRefactoring.h
clang/include/clang/Basic/DiagnosticSema.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/DiagnosticSerialization.h
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Sema/Sema.h
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaSYCL.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/SemaType.cpp
clang/test/TableGen/DiagnosticBase.inc
clang/tools/diagtool/DiagnosticNames.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 48ba8c0f469f..ab2c738a2ace 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -45,6 +45,7 @@ class TextSubstitution {
   // diagnostics
   string Component = "";
   string CategoryName = "";
+  bit Deferrable = 0;
 }
 
 // Diagnostic Categories.  These can be applied to groups or individual
@@ -83,6 +84,7 @@ class Diagnostic {
   bitAccessControl = 0;
   bitWarningNoWerror = 0;
   bitShowInSystemHeader = 0;
+  bitDeferrable = 0;
   Severity   DefaultSeverity = defaultmapping;
   DiagGroup  Group;
   string CategoryName = "";
@@ -106,6 +108,14 @@ class SuppressInSystemHeader {
   bit ShowInSystemHeader = 0;
 }
 
+class Deferrable {
+  bit Deferrable = 1;
+}
+
+class NonDeferrable {
+  bit Deferrable = 0;
+}
+
 // FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
 class Error : Diagnostic, 
SFINAEFailure {
   bit ShowInSystemHeader = 1;

diff  --git a/clang/include/clang/Basic/DiagnosticAST.h 
b/clang/include/clang/Basic/DiagnosticAST.h
index afe5f62e2012..76c31ad9508e 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -15,7 +15,7 @@ namespace clang {
 namespace diag {
 enum {
 #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, CATEGORY)
\
+ SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
   ENUM,
 #define ASTSTART
 #include "clang/Basic/DiagnosticASTKinds.inc"

diff  --git a/clang/include/clang/Basic/DiagnosticAnalysis.h 
b/clang/include/clang/Basic/DiagnosticAnalysis.h
index eea35a4d616e..f9037cc8d75a 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -15,7 +15,7 @@ namespace clang {
 namespace diag {
 enum {
 #def

[PATCH] D84364: [CUDA][HIP] Defer overloading resolution diagnostics for host device functions

2020-09-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG40df06cdafc0: [CUDA][HIP] Defer overloading resolution 
diagnostics for host device functions (authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D84364?vs=289814&id=292518#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84364

Files:
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCUDA/deferred-oeverload.cu
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1294,6 +1294,11 @@
 else
   OS << ", false";
 
+if (R.getValueAsBit("Deferrable"))
+  OS << ", true";
+else
+  OS << ", false";
+
 // Category number.
 OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap));
 OS << ")\n";
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -28,7 +28,7 @@
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,   \
- SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY)\
+ SFINAE,NOWERROR,SHOWINSYSHEADER,DEFER,CATEGORY)\
   { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- /dev/null
+++ clang/test/TableGen/deferred-diag.td
@@ -0,0 +1,27 @@
+// RUN: clang-tblgen -gen-clang-diags-defs -I%S %s -o - 2>&1 | \
+// RUN:FileCheck --strict-whitespace %s
+include "DiagnosticBase.inc"
+
+// Test usage of Deferrable and NonDeferrable in diagnostics.
+
+def test_default : Error<"This error is non-deferrable by default">;
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, false, 0)
+
+def test_deferrable : Error<"This error is deferrable">, Deferrable;
+// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+
+def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, false, 0)
+
+let Deferrable = 1 in {
+
+def test_let : Error<"This error is deferrable by let">;
+// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+
+// Make sure TextSubstitution is allowed in the let Deferrable block.
+def textsub : TextSubstitution<"%select{text1|text2}0">;
+
+def test_let2 : Error<"This error is deferrable by let %sub{textsub}0">;
+// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, 0)
+
+}
\ No newline at end of file
Index: clang/test/TableGen/DiagnosticBase.inc
===
--- clang/test/TableGen/DiagnosticBase.inc
+++ clang/test/TableGen/DiagnosticBase.inc
@@ -45,6 +45,7 @@
   // dia

[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D31413#2279404 , @ldionne wrote:

> In D31413#2279182 , @aaron.ballman 
> wrote:
>
>> Yes, and the way I would handle this is to change the `init_priority` value 
>> checking to allow values <= 100 if the attribute location is within a system 
>> header. This would allow libc++ to use the reserved priority but would still 
>> give errors when attempted from user code.
>
> Ok, that makes sense. If Clang implements that change, I can go back and 
> change it in libc++. I unfortunately don't have bandwidth to go and do that, 
> since this isn't affecting a platform I directly work on. So if anyone's 
> willing to go and change Clang to make that work, ping me here and I'll fix 
> libc++.

I can make the change, but it may be a few weeks before I get to it. If someone 
gets to it sooner, I'd be happy to review the patch for them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[PATCH] D87775: [clangd] Add option for disabling AddUsing tweak on some namespaces.

2020-09-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/ConfigFragment.h:167
+  struct StyleBlock {
+// List of namespaces that should not appear in "using" declarations.
+std::vector> FullyQualifiedNamespaces;

sammccall wrote:
> Can we describe this positively first?
> 
> Namespaces whose members should be fully-qualified, rather than via using 
> declarations or directives.
> Affects availability of the "add using declaration" tweak.
I copied the comment from the other place and added the bit about tweak. WDYT?



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:197
+  std::string Buf;
+  llvm::raw_string_ostream NamespaceStream(Buf);
+  Namespace.print(NamespaceStream,

sammccall wrote:
> validate it's a namespace, and then call printNamespaceScope (AST.h)?
> 
> This handles the right spelling of anonymous/inline NSes.
It's already guaranteed to be a namespace, that's checked before calling this 
function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87775

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


[PATCH] D87164: Extending Baremetal toolchain's support for the rtlib option.

2020-09-17 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs accepted this revision.
jroelofs added a comment.
This revision is now accepted and ready to land.

Yeah, this should do what you're after. LGTM


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

https://reviews.llvm.org/D87164

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


[PATCH] D87775: [clangd] Add option for disabling AddUsing tweak on some namespaces.

2020-09-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 292521.
adamcz marked 5 inline comments as done.
adamcz added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87775

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Annotations.h"
+#include "Config.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -2471,8 +2472,14 @@
 
 TWEAK_TEST(AddUsing);
 TEST_F(AddUsingTest, Prepare) {
+  Config Cfg;
+  Cfg.Style.FullyQualifiedNamespaces.push_back("ban");
+  WithContextValue WithConfig(Config::Key, std::move(Cfg));
+
   const std::string Header = R"cpp(
 #define NS(name) one::two::name
+namespace ban { void foo() {} }
+namespace banana { void foo() {} }
 namespace one {
 void oo() {}
 template class tt {};
@@ -2506,6 +2513,10 @@
   // Test that we don't crash or misbehave on unnamed DeclRefExpr.
   EXPECT_UNAVAILABLE(Header +
  "void fun() { one::two::cc() ^| one::two::cc(); }");
+  // Do not offer code action when operating on a banned namespace.
+  EXPECT_UNAVAILABLE(Header + "void fun() { ban::fo^o(); }");
+  EXPECT_UNAVAILABLE(Header + "void fun() { ::ban::fo^o(); }");
+  EXPECT_AVAILABLE(Header + "void fun() { banana::fo^o(); }");
 
   // Check that we do not trigger in header files.
   FileName = "test.h";
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "AST.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
@@ -190,6 +191,21 @@
   return Out;
 }
 
+bool isNamespaceForbidden(const Tweak::Selection &Inputs,
+  const NestedNameSpecifier &Namespace) {
+  std::string NamespaceStr = printNamespaceScope(*Namespace.getAsNamespace());
+
+  for (StringRef Banned : Config::current().Style.FullyQualifiedNamespaces) {
+StringRef PrefixMatch = NamespaceStr;
+PrefixMatch.consume_front("::");
+PrefixMatch.consume_front(Banned);
+if (PrefixMatch.consume_front("::"))
+  return true;
+  }
+
+  return false;
+}
+
 bool AddUsing::prepare(const Selection &Inputs) {
   auto &SM = Inputs.AST->getSourceManager();
 
@@ -248,6 +264,9 @@
 return false;
   }
 
+  if (isNamespaceForbidden(Inputs, *QualifierToRemove.getNestedNameSpecifier()))
+return false;
+
   // Macros are difficult. We only want to offer code action when what's spelled
   // under the cursor is a namespace qualifier. If it's a macro that expands to
   // a qualifier, user would not know what code action will actually change.
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -38,6 +38,7 @@
 DictParser Dict("Config", this);
 Dict.handle("If", [&](Node &N) { parse(F.If, N); });
 Dict.handle("CompileFlags", [&](Node &N) { parse(F.CompileFlags, N); });
+Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -71,6 +72,15 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::StyleBlock &F, Node &N) {
+DictParser Dict("Style", this);
+Dict.handle("FullyQualifiedNamespaces", [&](Node &N) {
+  if (auto Values = scalarValues(N))
+F.FullyQualifiedNamespaces = std::move(*Values);
+});
+Dict.parse(N);
+  }
+
   void parse(Fragment::IndexBlock &F, Node &N) {
 DictParser Dict("Index", this);
 Dict.handle("Background",
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -161,6 +161,16 @@
 llvm::Optional> Background;
   };
   IndexBlock Index;
+
+  // Describes the style of the codebase, beyond formatting.
+  struct StyleBlock {
+// Namespaces that should always be fully qualified, meaning no "using"
+// declarations, always spell out the whole name (with or without leading
+// ::). All nested namespaces are affected a

[clang-tools-extra] 7f1f89e - Fix build failure in clangd

2020-09-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-09-17T11:51:09-04:00
New Revision: 7f1f89ec8d9944559042bb6d3b1132eabe3409de

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

LOG: Fix build failure in clangd

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index afa72f9d4051..18ff96202e0a 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -43,7 +43,7 @@ namespace {
 const char *getDiagnosticCode(unsigned ID) {
   switch (ID) {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROPU, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, CATEGORY)
\
+ SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
   case clang::diag::ENUM:  
\
 return #ENUM;
 #include "clang/Basic/DiagnosticASTKinds.inc"



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


[PATCH] D87837: [Driver] Remove the deprecation warning for -fuse-ld=/abs/path

2020-09-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: chandlerc, hans.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
MaskRay requested review of this revision.

The feature has been used in the widespread build system Bazel
https://github.com/bazelbuild/bazel/commit/cdd0c3cdba270115940e8ca5ec8104cbcd694671

I have notified them about using --ld-path= forwards
https://github.com/bazelbuild/bazel/pull/8580#issuecomment-694321543
but we have to give some transitional period.

Intended for release/11.x for https://bugs.llvm.org/show_bug.cgi?id=47540


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87837

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/fuse-ld.c


Index: clang/test/Driver/fuse-ld.c
===
--- clang/test/Driver/fuse-ld.c
+++ clang/test/Driver/fuse-ld.c
@@ -2,7 +2,8 @@
 // RUN: -fuse-ld=/usr/local/bin/or1k-linux-ld 2>&1 \
 // RUN: -target x86_64-unknown-linux \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ABSOLUTE-LD
-// CHECK-ABSOLUTE-LD: warning: '-fuse-ld=' taking a path is deprecated. Use 
'--ld-path=' instead
+/// TODO: Issue the deprecation warning in a future release.
+// DISABLE-CHECK-ABSOLUTE-LD: warning: '-fuse-ld=' taking a path is 
deprecated. Use '--ld-path=' instead
 // CHECK-ABSOLUTE-LD: /usr/local/bin/or1k-linux-ld
 
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -576,12 +576,13 @@
   return GetProgramPath(DefaultLinker);
   }
 
+  // TODO Issue the warning in a future release.
   // Extending -fuse-ld= to an absolute or relative path is unexpected. 
Checking
   // for the linker flavor is brittle. In addition, prepending "ld." or "ld64."
   // to a relative path is surprising. This is more complex due to priorities
   // among -B, COMPILER_PATH and PATH. --ld-path= should be used instead.
-  if (UseLinker.find('/') != StringRef::npos)
-getDriver().Diag(diag::warn_drv_use_ld_non_word);
+  // if (UseLinker.find('/') != StringRef::npos)
+  //   getDriver().Diag(diag::warn_drv_use_ld_non_word);
 
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to


Index: clang/test/Driver/fuse-ld.c
===
--- clang/test/Driver/fuse-ld.c
+++ clang/test/Driver/fuse-ld.c
@@ -2,7 +2,8 @@
 // RUN: -fuse-ld=/usr/local/bin/or1k-linux-ld 2>&1 \
 // RUN: -target x86_64-unknown-linux \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ABSOLUTE-LD
-// CHECK-ABSOLUTE-LD: warning: '-fuse-ld=' taking a path is deprecated. Use '--ld-path=' instead
+/// TODO: Issue the deprecation warning in a future release.
+// DISABLE-CHECK-ABSOLUTE-LD: warning: '-fuse-ld=' taking a path is deprecated. Use '--ld-path=' instead
 // CHECK-ABSOLUTE-LD: /usr/local/bin/or1k-linux-ld
 
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -576,12 +576,13 @@
   return GetProgramPath(DefaultLinker);
   }
 
+  // TODO Issue the warning in a future release.
   // Extending -fuse-ld= to an absolute or relative path is unexpected. Checking
   // for the linker flavor is brittle. In addition, prepending "ld." or "ld64."
   // to a relative path is surprising. This is more complex due to priorities
   // among -B, COMPILER_PATH and PATH. --ld-path= should be used instead.
-  if (UseLinker.find('/') != StringRef::npos)
-getDriver().Diag(diag::warn_drv_use_ld_non_word);
+  // if (UseLinker.find('/') != StringRef::npos)
+  //   getDriver().Diag(diag::warn_drv_use_ld_non_word);
 
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87702: [Frontend] Add pragma align natural and sort out pragma pack stack effect

2020-09-17 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 292533.
Xiangling_L added a comment.

Fix the PragmaStack is empty assertion failure when we do: #pragma pack(2) then 
#pragma align(reset)


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

https://reviews.llvm.org/D87702

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Driver/aix-pragma-pack.c
  clang/test/Layout/aix-double-struct-member.cpp
  clang/test/Layout/aix-power-natural-interaction.cpp
  clang/test/Sema/aix-pragma-pack-and-align.c

Index: clang/test/Sema/aix-pragma-pack-and-align.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-pack-and-align.c
@@ -0,0 +1,231 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -faix-pragma-pack -verify -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+#pragma align(natural)
+#pragma pack(4)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma pack()
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
+#pragma pack(pop)
+#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
+struct B {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test1::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test1
+
+namespace test2 {
+#pragma align(natural)
+#pragma pack(2)
+struct A {
+  int i;
+  double d;
+};
+
+int a = sizeof(A);
+#pragma align(reset)
+
+struct B {
+  int i;
+  double d;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=2, preferredalign=2,
+// CHECK-NEXT:|  nvsize=12, nvalign=2, preferrednvalign=2]
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test2::B
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+
+} // namespace test2
+
+namespace test3 {
+#pragma pack(2)
+#pragma align(natural)
+struct A {
+  double d;
+};
+#pragma align(reset)
+#pragma pack(pop)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test3::A
+// CHECK-NEXT:  0 |   double d
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=4, preferrednvalign=8]
+
+} // namespace test3
+
+namespace test4 {
+#pragma pack(2)
+#pragma align(natural)
+#pragma pack(pop)
+
+struct A {
+  int i;
+  double d;
+} a;
+#pragma align(reset)
+#pragma pack(pop)
+
+int i = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test4::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  8 |   double d
+// CHECK-NEXT:| [sizeof=16, dsize=16, align=4, preferredalign=8,
+// CHECK-NEXT:|  nvsize=16, nvalign=4, preferrednvalign=8]
+
+} // namespace test4
+
+namespace test5 {
+#pragma align(power)
+#pragma align(natural)
+#pragma pack(2)
+#pragma align(reset)
+struct A {
+  int i;
+  double d;
+};
+#pragma align(reset)
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::A
+// CHECK-NEXT:  0 |   int i
+// CHECK-NEXT:  4 |   double d
+// CHECK-NEXT:| [sizeof=12, dsize=12, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=12, nvalign=4, preferrednvalign=4]
+
+} // namespace test5
+
+namespace test6 

[PATCH] D87029: [AIX] Implement AIX special bitfield related alignment rules

2020-09-17 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 292537.
Xiangling_L added a comment.

Rebased on the pragma/pack patch;
Added packed related testcase for bitfield;


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

https://reviews.llvm.org/D87029

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Layout/aix-bitfield-alignment.cpp
  clang/test/Layout/aix-oversized-bitfield.cpp

Index: clang/test/Layout/aix-oversized-bitfield.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-oversized-bitfield.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only %s | \
+// RUN:   FileCheck --check-prefix=CHECK64 %s
+
+struct A
+{
+long long l : 64; // expected-error{{width of bit-field 'l' (64 bits) exceeds size of its type (32 bits)}}
+};
+
+int a = sizeof(A);
+
+// CHECK64:  *** Dumping AST Record Layout
+// CHECK64-NEXT:  0 | struct A
+// CHECK64-NEXT: 0:0-63 |   long long l
+// CHECK64-NEXT:| [sizeof=8, dsize=8, align=8, preferredalign=8,
+// CHECK64-NEXT:|  nvsize=8, nvalign=8, preferrednvalign=8]
Index: clang/test/Layout/aix-bitfield-alignment.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-bitfield-alignment.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only  -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+struct A {
+  bool b : 3;
+  unsigned char c : 2;
+  unsigned short s : 6;
+};
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-2 |   _Bool b
+// CHECK-NEXT:  0:3-4 |   unsigned char c
+// CHECK-NEXT: 0:5-10 |   unsigned short s
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+struct B {
+  char c;
+  int : 0;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int 
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+struct C {
+  signed int a1 : 6;
+  signed char a2 : 4;
+  short int a3 : 2;
+  int a4 : 2;
+  signed long a5 : 5;
+  long long int a6 : 6;
+  unsigned long a7 : 8;
+};
+
+int c = sizeof(C);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct C
+// CHECK-NEXT:  0:0-5 |   int a1
+// CHECK-NEXT:  0:6-9 |   signed char a2
+// CHECK-NEXT:  1:2-3 |   short a3
+// CHECK-NEXT:  1:4-5 |   int a4
+// CHECK-NEXT: 1:6-10 |   long a5
+// CHECK-NEXT:  2:3-8 |   long long a6
+// CHECK32: 4:0-7 |   unsigned long a7
+// CHECK32:   | [sizeof=8, dsize=8, align=4, preferredalign=4,
+// CHECK32:   |  nvsize=8, nvalign=4, preferrednvalign=4]
+// CHECK64: 3:1-8 |   unsigned long a7
+// CHECK64:   | [sizeof=8, dsize=8, align=8, preferredalign=8,
+// CHECK64:   |  nvsize=8, nvalign=8, preferrednvalign=8]
+
+typedef __attribute__((aligned(32))) short mySHORT;
+struct D {
+  char c : 8;
+  mySHORT : 0;
+};
+
+int d = sizeof(D);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct D
+// CHECK-NEXT:  0:0-7 |   char c
+// CHECK-NEXT:   32:- |   mySHORT
+// CHECK-NEXT:| [sizeof=32, dsize=32, align=32, preferredalign=32,
+// CHECK-NEXT:|  nvsize=32, nvalign=32, preferrednvalign=32]
+
+enum class Bool : bool { False = 0,
+ True = 1 };
+
+struct E {
+  Bool b : 1;
+};
+
+int e = sizeof(E);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct E
+// CHECK-NEXT:  0:0-0 |   enum Bool b
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16443,7 +16443,22 @@
 bool MSBitfieldViolation =
 Value.ugt(TypeStorageSize) &&
 (IsMsStruct || Context.getTargetInfo().getCXXABI().isMicrosoft());
-if (CStdConstraintViolation || MSBitfieldViolation) {
+
+bool AIXBitfieldViolation = false;
+if (const BuiltinType *BTy = FieldTy.getTypePtr()->getAs()) {
+  if ((BTy->getKind() == BuiltinT

[clang] 1e19165 - [SyntaxTree][Synthesis] Fix allocation in `createTree` for more general use

2020-09-17 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-17T16:09:35Z
New Revision: 1e19165bd89db6671a80e0b25b32d5c7ae79455c

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

LOG: [SyntaxTree][Synthesis] Fix allocation in `createTree` for more general use

Prior to this change `createTree` could not create arbitrary syntax
trees. Now it dispatches to the constructor of the concrete syntax tree
according to the `NodeKind` passed as argument. This allows reuse inside
the Synthesis API.  # Please enter the commit message for your changes.
Lines starting

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/BuildTree.h
clang/lib/Tooling/Syntax/Synthesis.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/BuildTree.h 
b/clang/include/clang/Tooling/Syntax/BuildTree.h
index b9405167bf99..452edf580ae1 100644
--- a/clang/include/clang/Tooling/Syntax/BuildTree.h
+++ b/clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -35,13 +35,15 @@ syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K,
 syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
 
 // Synthesis of Trees
+/// Creates the concrete syntax node according to the specified `NodeKind` `K`.
+/// Returns it as a pointer to the base class `Tree`.
 syntax::Tree *
-createTree(Arena &A,
+createTree(syntax::Arena &A,
std::vector> Children,
syntax::NodeKind K);
 
 // Synthesis of Syntax Nodes
-clang::syntax::EmptyStatement *createEmptyStatement(clang::syntax::Arena &A);
+syntax::EmptyStatement *createEmptyStatement(syntax::Arena &A);
 
 } // namespace syntax
 } // namespace clang

diff  --git a/clang/lib/Tooling/Syntax/Synthesis.cpp 
b/clang/lib/Tooling/Syntax/Synthesis.cpp
index 6de3d5b5752d..2fe95a40cb32 100644
--- a/clang/lib/Tooling/Syntax/Synthesis.cpp
+++ b/clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -52,11 +52,144 @@ syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, 
tok::TokenKind K) {
   return createLeaf(A, K, Spelling);
 }
 
+namespace {
+// Allocates the concrete syntax `Tree` according to its `NodeKind`.
+syntax::Tree *allocateTree(syntax::Arena &A, syntax::NodeKind Kind) {
+  switch (Kind) {
+  case syntax::NodeKind::Leaf:
+assert(false);
+  case syntax::NodeKind::TranslationUnit:
+return new (A.getAllocator()) syntax::TranslationUnit;
+  case syntax::NodeKind::UnknownExpression:
+return new (A.getAllocator()) syntax::UnknownExpression;
+  case syntax::NodeKind::ParenExpression:
+return new (A.getAllocator()) syntax::ParenExpression;
+  case syntax::NodeKind::ThisExpression:
+return new (A.getAllocator()) syntax::ThisExpression;
+  case syntax::NodeKind::IntegerLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerLiteralExpression;
+  case syntax::NodeKind::CharacterLiteralExpression:
+return new (A.getAllocator()) syntax::CharacterLiteralExpression;
+  case syntax::NodeKind::FloatingLiteralExpression:
+return new (A.getAllocator()) syntax::FloatingLiteralExpression;
+  case syntax::NodeKind::StringLiteralExpression:
+return new (A.getAllocator()) syntax::StringLiteralExpression;
+  case syntax::NodeKind::BoolLiteralExpression:
+return new (A.getAllocator()) syntax::BoolLiteralExpression;
+  case syntax::NodeKind::CxxNullPtrExpression:
+return new (A.getAllocator()) syntax::CxxNullPtrExpression;
+  case syntax::NodeKind::IntegerUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerUserDefinedLiteralExpression;
+  case syntax::NodeKind::FloatUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::FloatUserDefinedLiteralExpression;
+  case syntax::NodeKind::CharUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::CharUserDefinedLiteralExpression;
+  case syntax::NodeKind::StringUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::StringUserDefinedLiteralExpression;
+  case syntax::NodeKind::PrefixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PrefixUnaryOperatorExpression;
+  case syntax::NodeKind::PostfixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PostfixUnaryOperatorExpression;
+  case syntax::NodeKind::BinaryOperatorExpression:
+return new (A.getAllocator()) syntax::BinaryOperatorExpression;
+  case syntax::NodeKind::UnqualifiedId:
+return new (A.getAllocator()) syntax::UnqualifiedId;
+  case syntax::NodeKind::IdExpression:
+return new (A.getAllocator()) syntax::IdExpression;
+  case syntax::NodeKind::CallExpression:
+return new (A.getAllocator()) syntax::CallExpression;
+  case syntax::NodeKind::UnknownStatement:
+return new (A.getAllocator()) syntax::UnknownStatement;
+  case syntax::NodeKind::DeclarationStatement:
+r

[PATCH] D87820: [SyntaxTree][Synthesis] Fix allocation in `createTree` for more general use

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e19165bd89d: [SyntaxTree][Synthesis] Fix allocation in 
`createTree` for more general use (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87820

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp

Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -52,11 +52,144 @@
   return createLeaf(A, K, Spelling);
 }
 
+namespace {
+// Allocates the concrete syntax `Tree` according to its `NodeKind`.
+syntax::Tree *allocateTree(syntax::Arena &A, syntax::NodeKind Kind) {
+  switch (Kind) {
+  case syntax::NodeKind::Leaf:
+assert(false);
+  case syntax::NodeKind::TranslationUnit:
+return new (A.getAllocator()) syntax::TranslationUnit;
+  case syntax::NodeKind::UnknownExpression:
+return new (A.getAllocator()) syntax::UnknownExpression;
+  case syntax::NodeKind::ParenExpression:
+return new (A.getAllocator()) syntax::ParenExpression;
+  case syntax::NodeKind::ThisExpression:
+return new (A.getAllocator()) syntax::ThisExpression;
+  case syntax::NodeKind::IntegerLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerLiteralExpression;
+  case syntax::NodeKind::CharacterLiteralExpression:
+return new (A.getAllocator()) syntax::CharacterLiteralExpression;
+  case syntax::NodeKind::FloatingLiteralExpression:
+return new (A.getAllocator()) syntax::FloatingLiteralExpression;
+  case syntax::NodeKind::StringLiteralExpression:
+return new (A.getAllocator()) syntax::StringLiteralExpression;
+  case syntax::NodeKind::BoolLiteralExpression:
+return new (A.getAllocator()) syntax::BoolLiteralExpression;
+  case syntax::NodeKind::CxxNullPtrExpression:
+return new (A.getAllocator()) syntax::CxxNullPtrExpression;
+  case syntax::NodeKind::IntegerUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::IntegerUserDefinedLiteralExpression;
+  case syntax::NodeKind::FloatUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::FloatUserDefinedLiteralExpression;
+  case syntax::NodeKind::CharUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::CharUserDefinedLiteralExpression;
+  case syntax::NodeKind::StringUserDefinedLiteralExpression:
+return new (A.getAllocator()) syntax::StringUserDefinedLiteralExpression;
+  case syntax::NodeKind::PrefixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PrefixUnaryOperatorExpression;
+  case syntax::NodeKind::PostfixUnaryOperatorExpression:
+return new (A.getAllocator()) syntax::PostfixUnaryOperatorExpression;
+  case syntax::NodeKind::BinaryOperatorExpression:
+return new (A.getAllocator()) syntax::BinaryOperatorExpression;
+  case syntax::NodeKind::UnqualifiedId:
+return new (A.getAllocator()) syntax::UnqualifiedId;
+  case syntax::NodeKind::IdExpression:
+return new (A.getAllocator()) syntax::IdExpression;
+  case syntax::NodeKind::CallExpression:
+return new (A.getAllocator()) syntax::CallExpression;
+  case syntax::NodeKind::UnknownStatement:
+return new (A.getAllocator()) syntax::UnknownStatement;
+  case syntax::NodeKind::DeclarationStatement:
+return new (A.getAllocator()) syntax::DeclarationStatement;
+  case syntax::NodeKind::EmptyStatement:
+return new (A.getAllocator()) syntax::EmptyStatement;
+  case syntax::NodeKind::SwitchStatement:
+return new (A.getAllocator()) syntax::SwitchStatement;
+  case syntax::NodeKind::CaseStatement:
+return new (A.getAllocator()) syntax::CaseStatement;
+  case syntax::NodeKind::DefaultStatement:
+return new (A.getAllocator()) syntax::DefaultStatement;
+  case syntax::NodeKind::IfStatement:
+return new (A.getAllocator()) syntax::IfStatement;
+  case syntax::NodeKind::ForStatement:
+return new (A.getAllocator()) syntax::ForStatement;
+  case syntax::NodeKind::WhileStatement:
+return new (A.getAllocator()) syntax::WhileStatement;
+  case syntax::NodeKind::ContinueStatement:
+return new (A.getAllocator()) syntax::ContinueStatement;
+  case syntax::NodeKind::BreakStatement:
+return new (A.getAllocator()) syntax::BreakStatement;
+  case syntax::NodeKind::ReturnStatement:
+return new (A.getAllocator()) syntax::ReturnStatement;
+  case syntax::NodeKind::RangeBasedForStatement:
+return new (A.getAllocator()) syntax::RangeBasedForStatement;
+  case syntax::NodeKind::ExpressionStatement:
+return new (A.getAllocator()) syntax::ExpressionStatement;
+  case syntax::NodeKind::CompoundStatement:
+return new (A.getAllocator()) syntax::CompoundStatement;
+  case syntax::NodeKind::UnknownDeclaration:
+return new (A.getAllocator()) syntax::UnknownDeclaration;
+  case syntax::N

[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 292539.
eduucaldas added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -137,6 +137,50 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, Copy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementContinue->dump(Arena->getSourceManager(;
+  // FIXME: Test that copy is independent of original, once the Mutations API is
+  // more developed.
+}
+
+TEST_P(SynthesisTest, Copy_Original) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'int' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | `-'a' synthesized
+  `-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Copy_Child) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree->getFirstChild());
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+SimpleDeclaration Detached synthesized
+|-'int' synthesized
+|-SimpleDeclarator Declarator synthesized
+| `-'a' synthesized
+`-';' synthesized
+  )txt"));
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -199,6 +199,27 @@
   return T;
 }
 
+static syntax::Leaf *copyLeaf(syntax::Arena &A, const syntax::Leaf *L) {
+  auto *Leaf = new (A.getAllocator()) syntax::Leaf(L->getToken());
+  if (L->canModify())
+syntax::FactoryImpl::setCanModify(Leaf);
+
+  return Leaf;
+}
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (const auto *L = dyn_cast(N)) {
+return copyLeaf(A, L);
+  }
+
+  const auto *T = cast(N);
+  auto Children = std::vector>();
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+Children.push_back({deepCopy(A, C), C->getRole()});
+  }
+  return createTree(A, Children, N->getKind());
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   return cast(
   createTree(A, {{createLeaf(A, tok::semi), NodeRole::Unknown}},
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -42,6 +42,13 @@
std::vector> Children,
syntax::NodeKind K);
 
+/// Deep copies `N`.
+///
+/// The copy is detached, i.e. `Parent == NextSibling == nullptr` and
+/// `Role == Detached`.
+/// The copy is synthesized, i.e. `Original == false`.
+syntax::Node *deepCopy(syntax::Arena &A, const syntax::Node *N);
+
 // Synthesis of Syntax Nodes
 syntax::EmptyStatement *createEmptyStatement(syntax::Arena &A);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85685: Support dwarf fission for wasm object files

2020-09-17 Thread Wouter van Oortmerssen via Phabricator via cfe-commits
aardappel added inline comments.



Comment at: llvm/lib/MC/WasmObjectWriter.cpp:1313
+  }
+  return writeOneObject(Asm, Layout, DwoMode::AllSections);
+}

Nit picking on this because I can't find anything else to complain about:
This line would be more readable inside an `else`.
I know LLVM prefers "early out" (and so do I), but here IsSplitDwarf is really 
not an early out case since it is the most complex case, and !IsSplitDwarf is 
not great for early out either because it is the common case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85685

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


[clang] e09107a - [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-17 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-09-17T19:28:57+03:00
New Revision: e09107ab80dced55414fa458cf78e6cdfe90da6e

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

LOG: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

Instead of relying on whether a certain identifier is a builtin, introduce 
BuiltinAttr to specify a declaration as having builtin semantics.

This fixes incompatible redeclarations of builtins, as reverting the identifier 
as being builtin due to one incompatible redeclaration would have broken rest 
of the builtin calls.
Mostly-compatible redeclarations of builtins also no longer have builtin 
semantics. They don't call the builtin nor inherit their attributes.
A long-standing FIXME regarding builtins inside a namespace enclosed in extern 
"C" not being recognized is also addressed.

Due to the more correct handling attributes for builtin functions are added in 
more places, resulting in more useful warnings.
Tests are updated to reflect that.

Intrinsics without an inline definition in intrin.h had `inline` and `static` 
removed as they had no effect and caused them to no longer be recognized as 
builtins otherwise.

A pthread_create() related test is XFAIL-ed, as it relied on it being 
recognized as a builtin based on its name.
The builtin declaration syntax is too restrictive and doesn't allow custom 
structs, function pointers, etc.
It seems to be the only case and fixing this would require reworking the 
current builtin syntax, so this seems acceptable.

Fixes PR45410.

Reviewed By: rsmith, yutsumi

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

Added: 
clang/test/CodeGen/builtin-redeclaration.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Headers/intrin.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/CodeGen/callback_pthread_create.c
clang/test/CodeGenCXX/builtins.cpp
clang/test/Sema/implicit-builtin-decl.c
clang/test/Sema/warn-fortify-source.c
clang/test/SemaCXX/cxx11-compat.cpp
clang/test/SemaCXX/warn-unused-local-typedef.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 628649a6998d..c2073e68be2c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3526,3 +3526,11 @@ def ReleaseHandle : InheritableParamAttr {
   let Subjects = SubjectList<[ParmVar]>;
   let Documentation = [ReleaseHandleDocs];
 }
+
+def Builtin : InheritableAttr {
+  let Spellings = [];
+  let Args = [UnsignedArgument<"ID">];
+  let Subjects = SubjectList<[Function]>;
+  let SemaHandler = 0;
+  let Documentation = [Undocumented];
+}

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index fb5b7ec22d07..efefe62c4a2c 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1020,6 +1020,7 @@ LIBBUILTIN(strncasecmp, "icC*cC*z", "f",   "strings.h", 
ALL_GNU_LANGUAGES)
 LIBBUILTIN(_exit, "vi",   "fr","unistd.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(vfork, "p","fj","unistd.h", ALL_LANGUAGES)
 // POSIX pthread.h
+// FIXME: Should specify argument types.
 LIBBUILTIN(pthread_create, "",  "fC<2,3>", "pthread.h", ALL_GNU_LANGUAGES)
 
 // POSIX setjmp.h

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index fc554a35e721..204a0f0cc0a5 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -225,18 +225,6 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   }
   void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
 
-  /// True if setNotBuiltin() was called.
-  bool hasRevertedBuiltin() const {
-return ObjCOrBuiltinID == tok::NUM_OBJC_KEYWORDS;
-  }
-
-  /// Revert the identifier to a non-builtin identifier. We do this if
-  /// the name of a known builtin library function is used to declare that
-  /// function, but an unexpected type is specified.
-  void revertBuiltin() {
-setBuiltinID(0);
-  }
-
   /// Return a value indicating whether this is a builtin function.
   ///
   /// 0 is not-built-in. 1+ are specific builtin functions.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 89771046f977..670bd8983265 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4109,6 +4109,8 @@ class Sema final {
 

[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-17 Thread Raul Tambre 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 rGe09107ab80dc: [Sema] Introduce BuiltinAttr, per-declaration 
builtin-ness (authored by tambre).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Headers/intrin.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/builtin-redeclaration.c
  clang/test/CodeGen/callback_pthread_create.c
  clang/test/CodeGenCXX/builtins.cpp
  clang/test/Sema/implicit-builtin-decl.c
  clang/test/Sema/warn-fortify-source.c
  clang/test/SemaCXX/cxx11-compat.cpp
  clang/test/SemaCXX/warn-unused-local-typedef.cpp

Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -67,10 +67,10 @@
 
 void test() {
   typedef signed long int superint; // no diag
-  printf("%f", (superint) 42);
+  printf("%ld", (superint)42);
 
   typedef signed long int superint2; // no diag
-  printf("%f", static_cast(42));
+  printf("%ld", static_cast(42));
 
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/test/SemaCXX/cxx11-compat.cpp
===
--- clang/test/SemaCXX/cxx11-compat.cpp
+++ clang/test/SemaCXX/cxx11-compat.cpp
@@ -31,7 +31,7 @@
 s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
 t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}
 
-#define PRIuS "uS"
+#define PRIuS "zu"
 int printf(const char *, ...);
 typedef __typeof(sizeof(int)) size_t;
 void h(size_t foo, size_t bar) {
Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 
 typedef unsigned long size_t;
@@ -13,13 +11,7 @@
 
 extern int sprintf(char *str, const char *format, ...);
 
-#if defined(USE_PASS_OBJECT_SIZE)
-void *memcpy(void *dst, const void *src, size_t c);
-static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp");
-static void *memcpy(void *const dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) {
-  return 0;
-}
-#elif defined(USE_BUILTINS)
+#if defined(USE_BUILTINS)
 #define memcpy(x,y,z) __builtin_memcpy(x,y,z)
 #else
 void *memcpy(void *dst, const void *src, size_t c);
@@ -45,14 +37,7 @@
   };
   struct pair p;
   char buf[20];
-  memcpy(&p.first, buf, 20);
-#ifdef USE_PASS_OBJECT_SIZE
-  // Use the more strict checking mode on the pass_object_size attribute:
-  // expected-warning@-3 {{memcpy' will always overflow; destination buffer has size 4, but size argument is 20}}
-#else
-  // Or just fallback to type 0:
-  // expected-warning@-6 {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
-#endif
+  memcpy(&p.first, buf, 20); // expected-warning {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
 }
 
 void call_strncat() {
Index: clang/test/Sema/implicit-builtin-decl.c
===
--- clang/test/Sema/implicit-builtin-decl.c
+++ clang/test/Sema/implicit-builtin-decl.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
 
 void f() {
   int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
@@ -63,9 +62,5 @@
 struct __jmp_bu

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-17 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked 11 inline comments as done.
compnerd added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3977
 
+// Swift attributes.
+def warn_attr_swift_name_function

aaron.ballman wrote:
> I want to make sure we're clear with the terminology used in the diagnostics, 
> so there's a fair number of "take -> have" suggestions here, but I want to be 
> sure I'm correct before you apply those suggestions.
> 
> I'm used to function declarations having parameters which take arguments from 
> a function call expression. Are the diagnostics about "taking a parameter" 
> talking about "having a parameter" or about "taking an argument"? I believe 
> the string arguments are function signatures rather than function names 
> (perhaps?) and so we should be talking about having a parameter, but I wasn't 
> 100% sure.
Discussed offline.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3997
+def warn_attr_swift_name_setter_parameters
+  : Warning<"%0 attribute for setter must take one parameter for new value">,
+InGroup;

aaron.ballman wrote:
> take -> have
> 
> elsewhere `new value` is spelled `'newValue:`, should that be the same here?
`newValue:` is the argument label spelling and "new value" is the argument 
value, which is the reason for the difference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

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


[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87839

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -38,6 +39,7 @@
 return ::testing::AssertionSuccess();
   }
 
+private:
   Tree *createTree(ArrayRef Children) {
 auto ChildrenWithRoles = std::vector>();
 ChildrenWithRoles.reserve(Children.size());
@@ -76,6 +78,7 @@
 return AllForests;
   }
 
+public:
   // Generates all trees with a `Base` layer of `Node`s and `NodeCountPerLayer`
   // `Node`s per layer. An example of Tree with `Base` = {`(`, `)`} and
   // `NodeCountPerLayer` = {2, 2}:
@@ -138,4 +141,178 @@
   }
 }
 
+std::string dump(Arena &A, const List::ElementAndDelimiter &ED) {
+  auto Format = [](StringRef s) { return "'" + s.trim().str() + "'"; };
+
+  std::string Delimiter =
+  ED.delimiter ? Format(ED.delimiter->dumpTokens(A.getSourceManager()))
+   : "nul";
+
+  std::string Element =
+  ED.element ? Format(ED.element->dumpTokens(A.getSourceManager())) : "nul";
+
+  return "(" + Element + ", " + Delimiter + ")";
+}
+
+std::string dump(Arena &A, ArrayRef> EDs) {
+  if (EDs.empty())
+return "[]";
+
+  std::string Storage;
+  llvm::raw_string_ostream OS(Storage);
+
+  OS << "[" << dump(A, EDs.front());
+  for (auto ED = std::next(EDs.begin()), End = EDs.end(); ED != End; ++ED)
+OS << ", " << dump(A, *ED);
+  OS << "]";
+  return OS.str();
+}
+
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", nul)]
+TEST_P(TreeTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(*Arena, {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  }, NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', nul)]");
+}
+
+/// "a,  , c"  <=> [("a", ","), (nul, ","), ("c", nul)]
+TEST_P(TreeTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(*Arena, {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  }, NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), (nul, ','), ('c', nul)]");
+}
+
+/// "a, b  c"  <=> [("a", ","), ("b", nul), ("c", nul)]
+TEST_P(TreeTest, List_Separated_MissingDelimiter) {
+  buildTree("", GetParam());
+
+  // "a, b  c"
+  auto *List = dyn_cast(syntax::createTree(*Arena, {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  }, NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', nul), ('c', nul)]");
+}
+
+/// "a, b,"<=> [("a", ","), ("b", ","), (nul, nul)]
+TEST_P(TreeTest, List_Separated_MissingLastElement) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(*Arena, {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  }, NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), (nul, nul)]");
+}
+
+/// "a:: b:: c::" <=> [("a", "::"), ("b", "::"), ("c", "::")]
+TEST_P(TreeTest, List_Terminated_WellFormed) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  buildTree("", GetParam());
+
+  // "a:: b:: c::"
+  auto *List = dyn_cast(syntax::createTree(*Arena, {
+  

[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-17 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 292547.
eduucaldas added a comment.

Apply arc lint patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87839

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -38,6 +39,7 @@
 return ::testing::AssertionSuccess();
   }
 
+private:
   Tree *createTree(ArrayRef Children) {
 auto ChildrenWithRoles = std::vector>();
 ChildrenWithRoles.reserve(Children.size());
@@ -76,6 +78,7 @@
 return AllForests;
   }
 
+public:
   // Generates all trees with a `Base` layer of `Node`s and `NodeCountPerLayer`
   // `Node`s per layer. An example of Tree with `Base` = {`(`, `)`} and
   // `NodeCountPerLayer` = {2, 2}:
@@ -138,4 +141,201 @@
   }
 }
 
+std::string dump(Arena &A, const List::ElementAndDelimiter &ED) {
+  auto Format = [](StringRef s) { return "'" + s.trim().str() + "'"; };
+
+  std::string Delimiter =
+  ED.delimiter ? Format(ED.delimiter->dumpTokens(A.getSourceManager()))
+   : "nul";
+
+  std::string Element =
+  ED.element ? Format(ED.element->dumpTokens(A.getSourceManager())) : "nul";
+
+  return "(" + Element + ", " + Delimiter + ")";
+}
+
+std::string dump(Arena &A, ArrayRef> EDs) {
+  if (EDs.empty())
+return "[]";
+
+  std::string Storage;
+  llvm::raw_string_ostream OS(Storage);
+
+  OS << "[" << dump(A, EDs.front());
+  for (auto ED = std::next(EDs.begin()), End = EDs.end(); ED != End; ++ED)
+OS << ", " << dump(A, *ED);
+  OS << "]";
+  return OS.str();
+}
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", nul)]
+TEST_P(TreeTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', nul)]");
+}
+
+/// "a,  , c"  <=> [("a", ","), (nul, ","), ("c", nul)]
+TEST_P(TreeTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), (nul, ','), ('c', nul)]");
+}
+
+/// "a, b  c"  <=> [("a", ","), ("b", nul), ("c", nul)]
+TEST_P(TreeTest, List_Separated_MissingDelimiter) {
+  buildTree("", GetParam());
+
+  // "a, b  c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', nul), ('c', nul)]");
+}
+
+/// "a, b,"<=> [("a", ","), ("b", ","), (nul, nul)]
+TEST_P(TreeTest, List_Separated_MissingLastElement) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dump(*Arena, List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), (nul, nul)]");
+}
+
+/// "a:: b:: c::" <=> [("a", "::"), ("b", "::"), ("c", "::")]
+TEST_P(TreeTest, List_T

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-17 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 292548.
compnerd marked 2 inline comments as done.
compnerd added a comment.

Address feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_name.m

Index: clang/test/SemaObjC/attr-swift_name.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_name.m
@@ -0,0 +1,174 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s
+
+#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))
+
+typedef struct {
+  float x, y, z;
+} Point3D;
+
+__attribute__((__swift_name__("PType")))
+@protocol P
+@end
+
+__attribute__((__swift_name__("IClass")))
+@interface I
+- (instancetype)init SWIFT_NAME("init()");
+- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");
+
++ (void)refresh SWIFT_NAME("refresh()");
+
+- (instancetype)i SWIFT_NAME("i()");
+
+- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");
+- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");
+- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");
+
++ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
+
++ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2}}
+
++ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning
+
++ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning
++ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning
+
++ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (instancetype)specialI SWIFT_NAME("init(options:)");
++ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 2)}}
++ (instancetype)specialK SWIFT_NAME("init(_:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
++ (instancetype)specialL SWIFT_NAME("i(options:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
+
++ (instancetype)trailingParen SWIFT_NAME("foo(");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
++ (instancetype)trailingColon SWIFT_NAME("foo:");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
++ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for base name}}
++ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for parameter name}}
+
+@property(strong) id someProp SWIFT_NAME("prop");
+@end
+
+enum SWIFT_NAME("E") E {
+  value1,
+  value2,
+  value3 SWIFT_NAME("three"),
+  value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for base name}}
+};
+
+struct SWIFT_NAME("TStruct") SStruct {
+  int i, j, k SWIFT_NAME("kay");
+};
+
+int i SWIFT_NAME("g_i");
+
+void f0(int i) SWIFT_NAME("f_0");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
+
+void f1(int i) SWIFT_NAME("f_1()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
+void f2(int i) SWIFT_NAME("f_2(a:b:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2)}}
+
+void f3(int x, int y) SWIFT_NAME("fWithX(_:y:)");
+void f4(int x, int *error) SWIFT_NAME("fWithX(_:)");
+
+typedef int int_t SWIFT_NAME("IntType");
+
+struct Poin

[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-17 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 292550.
martong added a comment.

- apply -> assume, Add isApplicable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87785

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -126,6 +126,25 @@
   (void)fread(ptr, sz, nmem, fp); // expected-warning {{1st function call argument is an uninitialized value}}
 }
 
+static void test_fread_buffer_size_constraint_no_crash(FILE *f, size_t n) {
+  size_t rlen; /* how much to read */
+  size_t nr;   /* number of chars actually read */
+  char b[8192];
+  rlen = 8192;
+  do {
+char *p = b;
+if (rlen > n)
+  rlen = n; /* cannot read more than asked */
+nr = fread(p, sizeof(char), rlen, f);
+n -= nr; /* still have to read `n' chars */
+  } while (n > 0 && nr == rlen); /* until end of count or eof */
+}
+// Test that we do not crash here.
+void test_fread_buffer_size_constraint_no_crash_caller(FILE *f) {
+  /* read MAX_SIZE_T chars */
+  test_fread_buffer_size_constraint_no_crash(f, ~((size_t)0));
+}
+
 ssize_t getline(char **, size_t *, FILE *);
 void test_getline(FILE *fp) {
   char *line = 0;
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -104,14 +104,18 @@
   public:
 ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
 virtual ~ValueConstraint() {}
-/// Apply the effects of the constraint on the given program state. If null
-/// is returned then the constraint is not feasible.
-virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary,
-  CheckerContext &C) const = 0;
-virtual ValueConstraintPtr negate() const {
-  llvm_unreachable("Not implemented");
-};
+
+/// Returns true if we can do any assumption on the constraint, i.e. if it
+/// is meaningful to call an Engine `assume` function.
+virtual bool isApplicable(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary,
+  CheckerContext &C) const = 0;
+
+/// Returns the program states for the cases when the constraint is
+/// satisfiable and non satisfiable.
+virtual std::pair
+assume(ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
+   CheckerContext &C) const = 0;
 
 // Check whether the constraint is malformed or not. It is malformed if the
 // specified argument has a mismatch with the given FunctionDecl (e.g. the
@@ -169,29 +173,25 @@
const Summary &Summary) const;
 
   public:
-ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary,
-  CheckerContext &C) const override {
-  switch (Kind) {
-  case OutOfRange:
-return applyAsOutOfRange(State, Call, Summary);
-  case WithinRange:
-return applyAsWithinRange(State, Call, Summary);
-  }
-  llvm_unreachable("Unknown range kind!");
+bool isApplicable(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary,
+  CheckerContext &C) const override {
+  SVal V = getArgSVal(Call, getArgNo());
+  return V.getAs().hasValue();
 }
 
-ValueConstraintPtr negate() const override {
-  RangeConstraint Tmp(*this);
+std::pair
+assume(ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
+   CheckerContext &C) const override {
   switch (Kind) {
   case OutOfRange:
-Tmp.Kind = WithinRange;
-break;
+return {applyAsOutOfRange(State, Call, Summary),
+applyAsWithinRange(State, Call, Summary)};
   case WithinRange:
-Tmp.Kind = OutOfRange;
-break;
+return {applyAsWithinRange(State, Call, Summary),
+applyAsOutOfRange(State, Call, Summary)};
   }
-  return std::make_shared(Tmp);
+  llvm_unreachable("Unknown range kind!");
 }
 
 bool checkSpecificValidity(const FunctionDecl *FD) const override {
@@ -214,36 +214,37 @@
 : ValueConstraint(ArgN), Opcode(Opcode), OtherArgN(OtherArgN) {}
 ArgNo getOtherArgNo() const { return OtherArgN; }
 BinaryOperator::Opcode getOpcode() const { return Opcode; }
-ProgramStateRef apply(ProgramStateRef State, const CallE

[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-17 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Alright, I refactored the change a bit. A Constraint::assume works similarly to 
an engine DualAssume. Plus I added `isApplicable` to check if it is meaningful 
to call the assume at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87785

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


[PATCH] D84364: [CUDA][HIP] Defer overloading resolution diagnostics for host device functions

2020-09-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Looks like this patch broke the MSan buildbots, PTAL (repro instructions 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild):

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/46239/steps/check-clang%20msan/logs/stdio

  FAIL: Clang :: SemaCUDA/deferred-oeverload.cu (11308 of 26387)
   TEST 'Clang :: SemaCUDA/deferred-oeverload.cu' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/12.0.0/include 
-nostdsysteminc -fcuda-is-device -fsyntax-only -verify=dev,com 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCUDA/deferred-oeverload.cu
-std=c++11 -fgpu-defer-diag
  : 'RUN: at line 3';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/12.0.0/include 
-nostdsysteminc -fsyntax-only -verify=host,com 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCUDA/deferred-oeverload.cu
-std=c++11 -fgpu-defer-diag
  --
  Exit Code: 77
  
  Command Output (stderr):
  --
  ==41680==WARNING: MemorySanitizer: use-of-uninitialized-value
  #0 0xddfbf73 in 
clang::OverloadCandidateSet::CompleteCandidates(clang::Sema&, 
clang::OverloadCandidateDisplayKind, llvm::ArrayRef, 
clang::SourceLocation, llvm::function_ref) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:11484:9
  #1 0xde4e7ca in 
clang::OverloadCandidateSet::NoteCandidates(std::__1::pair, clang::Sema&, clang::OverloadCandidateDisplayKind, 
llvm::ArrayRef, llvm::StringRef, clang::SourceLocation, 
llvm::function_ref) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:11529:9
  #2 0xde6316f in FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, 
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, 
clang::OverloadCandidateSet*, clang::OverloadCandidate**, 
clang::OverloadingResult, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:12959:19
  #3 0xde6296b in clang::Sema::BuildOverloadedCallExpr(clang::Scope*, 
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, bool, 
bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:13032:10
  #4 0xd4e126b in clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, 
clang::SourceLocation, llvm::MutableArrayRef, 
clang::SourceLocation, clang::Expr*, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:6378:16
  #5 0xd53e073 in clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, 
clang::SourceLocation, llvm::MutableArrayRef, 
clang::SourceLocation, clang::Expr*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:6275:7
  #6 0xcaa957f in 
clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:2066:23
  #7 0xcaaf03e in 
clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, 
clang::Parser::TypeCastState, bool, bool*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:1811:9
  #8 0xcaa5f3e in 
clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, 
clang::Parser::TypeCastState, bool, bool*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:681:20
  #9 0xcaa15f3 in 
clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:173:20
  #10 0xcaa13ad in 
clang::Parser::ParseExpression(clang::Parser::TypeCastState) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:124:18
  #11 0xcbc8288 in 
clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:446:19
  #12 0xcbc2183 in 
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, 
clang::Parser::ParsedAttributesWithRange&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:234:12
  #13 0xcbc119d in 
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:106:20
  #14 0xcbdd830 in clang::Parser::ParseCompoundStatementBody(bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:1098:11
  #15 0xcbe0b67 in clang::Parser::P

[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-17 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Apparently this patch triggers compiler crashes on some of our code. I'll try 
to create a reproducer, but it would be great to revert the patch for now.

  *** SIGSEGV (@0x7f68892d8fe8),  received by PID 8210 (TID 8225) on cpu 65; 
stack trace: ***
  PC: @ 0x7f686d8a169d  (unknown)  clang::Decl::getAvailability()
  @ 0x7f6712fad13b   1376  FailureSignalHandler()
  @ 0x7f696f1b69a0  34448  (unknown)
  @ 0x7f688c278c9a352  ShouldDiagnoseAvailabilityOfDecl()
  @ 0x7f688c27897d352  clang::Sema::DiagnoseAvailabilityOfDecl()
  @ 0x7f688c8bd3c7   1584  clang::Sema::DiagnoseUseOfDecl()
  @ 0x7f688c8cc1e8672  clang::Sema::BuildDeclarationNameExpr()
  @ 0x7f688c8c9e30192  clang::Sema::BuildDeclarationNameExpr()
  @ 0x7f688c8c2698   1280  clang::Sema::ActOnIdExpression()
  @ 0x7f688e9b95db   9136  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b358b128  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b9ebb   9136  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b358b128  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b1998112  
clang::Parser::ParseAssignmentExpression()
  @ 0x7f688e9b1832 64  clang::Parser::ParseExpression()
  @ 0x7f688e9bd6f0   4064  clang::Parser::ParseParenExpression()
  @ 0x7f688e9b6bb4   9136  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b358b128  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b1998112  
clang::Parser::ParseAssignmentExpression()
  @ 0x7f688e9c1285288  clang::Parser::ParseExpressionList()
  @ 0x7f688e9b4731   3088  
clang::Parser::ParsePostfixExpressionSuffix()
  @ 0x7f688e9bb92a   9136  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b358b128  clang::Parser::ParseCastExpression()
  @ 0x7f688e9b1998112  
clang::Parser::ParseAssignmentExpression()
  @ 0x7f688e9b1832 64  clang::Parser::ParseExpression()
  @ 0x7f688ea43040240  clang::Parser::ParseReturnStatement()
  @ 0x7f688ea3cef0   1264  
clang::Parser::ParseStatementOrDeclarationAfterAttributes()
  @ 0x7f688ea3c5cf160  
clang::Parser::ParseStatementOrDeclaration()
  @ 0x7f688ea4490a   1264  
clang::Parser::ParseCompoundStatementBody()
  @ 0x7f688ea45df9272  
clang::Parser::ParseFunctionStatementBody()
  @ 0x7f688ea6a7b4960  clang::Parser::ParseFunctionDefinition()
  @ 0x7f688e9600bd   2880  clang::Parser::ParseDeclGroup()
  @ 0x7f688ea69634368  
clang::Parser::ParseDeclOrFunctionDefInternal()
  @ 0x7f688ea68c20672  
clang::Parser::ParseDeclarationOrFunctionDefinition()
  @ 0x7f688ea684ee768  clang::Parser::ParseExternalDeclaration()
  @ 0x7f688ea667a9368  clang::Parser::ParseTopLevelDecl()
  @ 0x7f688e93d2a2240  clang::ParseAST()
  @ 0x7f688fe079bd 80  clang::ASTFrontendAction::ExecuteAction()
  @ 0x7f688fe073b8144  clang::FrontendAction::Execute()
  @ 0x7f688fd1bdd6480  clang::ASTUnit::Parse()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84362

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


[PATCH] D87095: [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.

2020-09-17 Thread Ahmed Bougacha via Phabricator via cfe-commits
ab updated this revision to Diff 292557.
ab added a comment.
Herald added a subscriber: pzheng.

Reformat ValidArchs.


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

https://reviews.llvm.org/D87095

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arclite-link.c
  clang/test/Driver/target-triple-deployment.c
  clang/test/Preprocessor/arm64e.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/BinaryFormat/MachO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/LTOModule.cpp
  llvm/lib/Object/MachOObjectFile.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  llvm/test/MC/AArch64/arm64e-subtype.s
  llvm/test/MC/AArch64/arm64e.s
  llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
  llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
  llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
  llvm/test/tools/llvm-readobj/macho-arm64e.test
  llvm/unittests/ADT/TripleTest.cpp
  llvm/utils/UpdateTestChecks/asm.py

Index: llvm/utils/UpdateTestChecks/asm.py
===
--- llvm/utils/UpdateTestChecks/asm.py
+++ llvm/utils/UpdateTestChecks/asm.py
@@ -335,6 +335,7 @@
   'amdgcn': (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
   'arm': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
   'arm64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
+  'arm64e': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'arm64-apple-ios': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
   'armv7-apple-ios' : (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
   'armv7-apple-darwin': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),
Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -1590,5 +1590,10 @@
 Triple T = Triple("aarch64_be");
 EXPECT_EQ(Triple::aarch64_be, T.getArch());
   }
+  {
+Triple T = Triple("arm64e");
+EXPECT_EQ(Triple::aarch64, T.getArch());
+EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
+  }
 }
 } // end anonymous namespace
Index: llvm/test/tools/llvm-readobj/macho-arm64e.test
===
--- /dev/null
+++ llvm/test/tools/llvm-readobj/macho-arm64e.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -h %t.o | FileCheck %s
+
+# CHECK: Magic: Magic64 (0xFEEDFACF)
+# CHECK: CpuType: Arm64 (0x10C)
+# CHECK: CpuSubType: CPU_SUBTYPE_ARM64E (0x2)
+
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x010C
+  cpusubtype:  0x0002
+  filetype:0x0001
+  ncmds:   0
+  sizeofcmds:  0
+  flags:   0x
+  reserved:0x
Index: llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
===
--- llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
+++ llvm/test/tools/llvm-objdump/MachO/universal-arm64.test
@@ -22,7 +22,7 @@
 # CHECK-NEXT: offset 16384
 # CHECK-NEXT: size 384
 # CHECK-NEXT: align 2^14 (16384)
-# CHECK-NEXT: architecture
+# CHECK-NEXT: architecture arm64e
 # CHECK-NEXT: cputype CPU_TYPE_ARM64
 # CHECK-NEXT: cpusubtype CPU_SUBTYPE_ARM64E
 # CHECK-NEXT: capabilities 0x0
Index: llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-dwarfdump/AArch64/arm64e.ll
@@ -0,0 +1,17 @@
+; RUN: llc -O0 %s -filetype=obj -o - \
+; RUN:   | llvm-dwarfdump -arch arm64e - | FileCheck %s
+; CHECK: file format Mach-O arm64
+
+source_filename = "/tmp/empty.c"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64e-apple-ios"
+
+!llvm.module.flags = !{!1, !2, !3, !4}
+!llvm.dbg.cu = !{!5}
+
+!1 = !{i32 2, !"Dwarf Version", i32 4}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 1, !"wchar_size", i32 4}
+!4 = !{i32 7, !"PIC Level", i32 2}
+!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!6 = !DIFile(filename: "/tmp/empty.c", directory: "/Volumes/Data/llvm-project")
Index: llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
===
--- llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
+++ llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
@@ -1,16 +1,39 @@
 // RUN: llvm-mc -triple arm64-apple-macos10.10.2 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileC

[PATCH] D87187: [Driver] Perform Linux distribution detection just once

2020-09-17 Thread Reid "Away June-Sep" Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/lib/Driver/Distro.cpp:205
+const llvm::Triple &TargetOrHost) {
+  static Distro::DistroType Type = Distro::UninitializedDistro;
+

aganea wrote:
> I'm not sure if this is safe. @rnk Do we expect to call `GetDistro` with a 
> different `VFS` or a different `Triple` when compiling with Clang? For GPU 
> targets? Shouldn't we do this higher up, on the call site?
I think there is a plausible use case for a compile server that does two 
compiles with different VFSs where you would get different distro detection 
results. I think this should be a field on the `Driver` object instead of a 
global variable.

I know LLD uses lots of globals, but that's not part of the clang design 
philosophy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87187

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Brandon Bergren via Phabricator via cfe-commits
Bdragon28 added a comment.

In D79916#2279045 , @jrtc27 wrote:

> This has significantly regressed FreeBSD's performance with the new version 
> of Clang. It seems Clang does not inline functions at -O1, unlike GCC, and 
> since FreeBSD currently compiles its kernel with -O whenever debug symbols 
> are enabled[1] (which, of course, is almost always true), this results in all 
> its `static inline` helper functions not being inlined at all, a pattern that 
> is common in the kernel, used for things like `get_curthread` and the atomics 
> implementations.
>
> [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
> debugger stack traces" (well, before then there was ping-ponging between -O 
> and -O2 based on concerns around correctness vs performance, but amd64 is an 
> exception that has always used -O2 since r127180 it seems). Given that GCC 
> will inline at -O, at least these days, the motivation seems to no longer 
> exist, and compiling a kernel at anything other than -O2 (or maybe -O3) seems 
> like a silly thing to do, but nevertheless it's what is currently done.
>
> Cc: @dim @trasz

This is actually SUCH a bad idea that a kernel built with -O will *not work at 
all* on 32 bit powerpc platforms (presumably due to allocating stack frames in 
the middle of assembly fragments in the memory management that are supposed to 
be inlined at all times.) I had to hack kern.pre.mk to rquest -O2 at all times 
just to get a functioning kernel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D79916#2279812 , @Bdragon28 wrote:

> In D79916#2279045 , @jrtc27 wrote:
>
>> This has significantly regressed FreeBSD's performance with the new version 
>> of Clang. It seems Clang does not inline functions at -O1, unlike GCC, and 
>> since FreeBSD currently compiles its kernel with -O whenever debug symbols 
>> are enabled[1] (which, of course, is almost always true), this results in 
>> all its `static inline` helper functions not being inlined at all, a pattern 
>> that is common in the kernel, used for things like `get_curthread` and the 
>> atomics implementations.
>>
>> [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
>> debugger stack traces" (well, before then there was ping-ponging between -O 
>> and -O2 based on concerns around correctness vs performance, but amd64 is an 
>> exception that has always used -O2 since r127180 it seems). Given that GCC 
>> will inline at -O, at least these days, the motivation seems to no longer 
>> exist, and compiling a kernel at anything other than -O2 (or maybe -O3) 
>> seems like a silly thing to do, but nevertheless it's what is currently done.
>>
>> Cc: @dim @trasz
>
> This is actually SUCH a bad idea that a kernel built with -O will *not work 
> at all* on 32 bit powerpc platforms (presumably due to allocating stack 
> frames in the middle of assembly fragments in the memory management that are 
> supposed to be inlined at all times.) I had to hack kern.pre.mk to rquest -O2 
> at all times just to get a functioning kernel.

Well, -O0, -O1, -O2 and -O should all produce working kernels, and any cases 
where they don't are compiler bugs (or kernel bugs if they rely on UB) that 
should be fixed, not worked around by tweaking the compiler flags in a fragile 
way until you get the behaviour relied on. Correctness and performance are very 
different issues here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D87187: [Driver] Perform Linux distribution detection just once

2020-09-17 Thread Reid "Away June-Sep" Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/lib/Driver/Distro.cpp:205
+const llvm::Triple &TargetOrHost) {
+  static Distro::DistroType Type = Distro::UninitializedDistro;
+

rnk wrote:
> aganea wrote:
> > I'm not sure if this is safe. @rnk Do we expect to call `GetDistro` with a 
> > different `VFS` or a different `Triple` when compiling with Clang? For GPU 
> > targets? Shouldn't we do this higher up, on the call site?
> I think there is a plausible use case for a compile server that does two 
> compiles with different VFSs where you would get different distro detection 
> results. I think this should be a field on the `Driver` object instead of a 
> global variable.
> 
> I know LLD uses lots of globals, but that's not part of the clang design 
> philosophy.
Sorry, I spoke too soon.

For @aganea's concern, my understanding is that the distro is a property of the 
host machine doing the compilation. Even if we do two compiles in the same 
process on the same machine with two triples, they should have the same distro, 
if they are using the same real FS. At least, the FS shouldn't change out from 
under us in a way that changes the result of distro detection. :) I think it's 
reasonable to use distro detection to inform header search paths, but we should 
avoid using it to control properties of the output, like stack protection 
security features, for example. Otherwise, it becomes impossible to target one 
Linux distro from another, because the distro does not appear to be 
controllable by a command line flag.

And, now that I see what is happening with the real FS checks here, I withdraw 
my concern. Even if you did make this a property of the driver, I would want 
some global variable somewhere to check that we don't end up doing the distro 
check twice. It's the only way to really be sure that some passerby doesn't 
introduce a new distro check. =P


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87187

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


[PATCH] D87791: [CUDA][HIP] Fix -gsplit-dwarf option

2020-09-17 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D87791#2278417 , @yaxunl wrote:

> Therefore in either case there is no need to rename the intermediate .o files 
> since they are temporary files which have unique names.
>
> The .dwo files are not temporary files. They are supposed to be shipped with 
> .o files for debugging info.

Ack.  
BTW, is split-dwarf useful for AMD GPUs on device side? I don't think we can 
currently utilize DWO files on device side with CUDA at all. To think of it, 
it's probably going to break GPU-side debugging as CUDA can only deal with 
dwarf info embedded in the GPU binary. 
If it does not work for AMD GPUs, perhaps we should just disable it for GPUs.

> Since .dwo files are not temporary files, it is not necessary to follow the 
> -save-temps name convention. For the host object, we keep the original .dwo 
> file name. For the device object, we add '_' and GPU arch to the stem, which 
> is sufficient and concise.

What will happen with `-save-temps` ? Will dwo files match object file names?


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

https://reviews.llvm.org/D87791

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


[clang-tools-extra] 772bd8a - Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"

2020-09-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-09-17T13:55:31-04:00
New Revision: 772bd8a7d99b8db899f594d393986e4b6cd85aa1

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

LOG: Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host 
device functions"

This reverts commit 7f1f89ec8d9944559042bb6d3b1132eabe3409de.

This reverts commit 40df06cdafc010002fc9cfe1dda73d689b7d27a6.

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang/include/clang/Basic/Diagnostic.td
clang/include/clang/Basic/DiagnosticAST.h
clang/include/clang/Basic/DiagnosticAnalysis.h
clang/include/clang/Basic/DiagnosticComment.h
clang/include/clang/Basic/DiagnosticCrossTU.h
clang/include/clang/Basic/DiagnosticDriver.h
clang/include/clang/Basic/DiagnosticFrontend.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/DiagnosticLex.h
clang/include/clang/Basic/DiagnosticParse.h
clang/include/clang/Basic/DiagnosticRefactoring.h
clang/include/clang/Basic/DiagnosticSema.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/DiagnosticSerialization.h
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Sema/Sema.h
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaSYCL.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/SemaType.cpp
clang/test/TableGen/DiagnosticBase.inc
clang/tools/diagtool/DiagnosticNames.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 
clang/test/SemaCUDA/deferred-oeverload.cu
clang/test/TableGen/deferred-diag.td



diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 18ff96202e0a..afa72f9d4051 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -43,7 +43,7 @@ namespace {
 const char *getDiagnosticCode(unsigned ID) {
   switch (ID) {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROPU, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
+ SHOWINSYSHEADER, CATEGORY)
\
   case clang::diag::ENUM:  
\
 return #ENUM;
 #include "clang/Basic/DiagnosticASTKinds.inc"

diff  --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index ab2c738a2ace..48ba8c0f469f 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -45,7 +45,6 @@ class TextSubstitution {
   // diagnostics
   string Component = "";
   string CategoryName = "";
-  bit Deferrable = 0;
 }
 
 // Diagnostic Categories.  These can be applied to groups or individual
@@ -84,7 +83,6 @@ class Diagnostic {
   bitAccessControl = 0;
   bitWarningNoWerror = 0;
   bitShowInSystemHeader = 0;
-  bitDeferrable = 0;
   Severity   DefaultSeverity = defaultmapping;
   DiagGroup  Group;
   string CategoryName = "";
@@ -108,14 +106,6 @@ class SuppressInSystemHeader {
   bit ShowInSystemHeader = 0;
 }
 
-class Deferrable {
-  bit Deferrable = 1;
-}
-
-class NonDeferrable {
-  bit Deferrable = 0;
-}
-
 // FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
 class Error : Diagnostic, 
SFINAEFailure {
   bit ShowInSystemHeader = 1;

diff  --git a/clang/include/clang/Basic/DiagnosticAST.h 
b/clang/include/clang/Basic/DiagnosticAST.h
index 76c31ad9508e..afe5f62e2012 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -15,7 +15,7 @@ namespace clang {
 namespace diag {
 enum {
 #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
+ SHOWINSYSHEADER, CATEGORY)
\
   ENUM,
 #define ASTSTART
 #include "clang/Basic/DiagnosticASTKinds.inc"

diff  --git a/clang/include/clang/Basic/DiagnosticAnalysis.h 
b/clang/include/clang/Basic/DiagnosticAnalysis.h
index f

[clang] 829d14e - Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"

2020-09-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-09-17T13:56:09-04:00
New Revision: 829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91

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

LOG: Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"

This reverts commit ee5519d323571c4a9a7d92cb817023c9b95334cd.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Attr.h
clang/include/clang/AST/CanonicalType.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclarationName.h
clang/include/clang/AST/NestedNameSpecifier.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/PartialDiagnostic.h
clang/include/clang/Sema/Ownership.h
clang/include/clang/Sema/ParsedAttr.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/Basic/Diagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 397fee4d866b..de0d1198b6d4 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3064,9 +3064,8 @@ OPT_LIST(V)
 };
 
 /// Insertion operator for diagnostics.
-const StreamableDiagnosticBase &
-operator<<(const StreamableDiagnosticBase &DB,
-   const ASTContext::SectionInfo &Section);
+const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+const ASTContext::SectionInfo &Section);
 
 /// Utility function for constructing a nullary selector.
 inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {

diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index b4dce8f41c67..b3729b2e0d99 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -350,12 +350,19 @@ struct ParsedTargetAttr {
 
 #include "clang/AST/Attrs.inc"
 
-inline const StreamableDiagnosticBase &
-operator<<(const StreamableDiagnosticBase &DB, const Attr *At) {
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+   const Attr *At) {
   DB.AddTaggedVal(reinterpret_cast(At),
   DiagnosticsEngine::ak_attr);
   return DB;
 }
+
+inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+   const Attr *At) {
+  PD.AddTaggedVal(reinterpret_cast(At),
+  DiagnosticsEngine::ak_attr);
+  return PD;
+}
 }  // end namespace clang
 
 #endif

diff  --git a/clang/include/clang/AST/CanonicalType.h 
b/clang/include/clang/AST/CanonicalType.h
index b6d9b69db09a..488284713bce 100644
--- a/clang/include/clang/AST/CanonicalType.h
+++ b/clang/include/clang/AST/CanonicalType.h
@@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() 
const {
   return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
 }
 
-inline const StreamableDiagnosticBase &
-operator<<(const StreamableDiagnosticBase &DB, CanQualType T) {
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+   CanQualType T) {
   DB << static_cast(T);
   return DB;
 }

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 852ba2316f82..c2511514fe72 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4513,8 +4513,14 @@ class EmptyDecl : public Decl {
 
 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
 /// into a diagnostic with <<.
-inline const StreamableDiagnosticBase &
-operator<<(const StreamableDiagnosticBase &PD, const NamedDecl *ND) {
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+   const NamedDecl* ND) {
+  DB.AddTaggedVal(reinterpret_cast(ND),
+  DiagnosticsEngine::ak_nameddecl);
+  return DB;
+}
+inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+   const NamedDecl* ND) {
   PD.AddTaggedVal(reinterpret_cast(ND),
   DiagnosticsEngine::ak_nameddecl);
   return PD;

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 065a7413e7e7..20f058b87e7f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4070,8 +4070,11 @@ class MSGuidDecl : public ValueDecl,
 
 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
 /// into a diagnostic with <<.
-const StreamableDiagn

[PATCH] D84364: [CUDA][HIP] Defer overloading resolution diagnostics for host device functions

2020-09-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D84364#2279684 , @hctim wrote:

> Looks like this patch broke the MSan buildbots, PTAL (repro instructions 
> https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild):
>
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/46239/steps/check-clang%20msan/logs/stdio
>
>   FAIL: Clang :: SemaCUDA/deferred-oeverload.cu (11308 of 26387)
>    TEST 'Clang :: SemaCUDA/deferred-oeverload.cu' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 1';   
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
> -internal-isystem 
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/12.0.0/include 
> -nostdsysteminc -fcuda-is-device -fsyntax-only -verify=dev,com 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCUDA/deferred-oeverload.cu
> -std=c++11 -fgpu-defer-diag
>   : 'RUN: at line 3';   
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
> -internal-isystem 
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/12.0.0/include 
> -nostdsysteminc -fsyntax-only -verify=host,com 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCUDA/deferred-oeverload.cu
> -std=c++11 -fgpu-defer-diag
>   --
>   Exit Code: 77
>   
>   Command Output (stderr):
>   --
>   ==41680==WARNING: MemorySanitizer: use-of-uninitialized-value
>   #0 0xddfbf73 in 
> clang::OverloadCandidateSet::CompleteCandidates(clang::Sema&, 
> clang::OverloadCandidateDisplayKind, llvm::ArrayRef, 
> clang::SourceLocation, llvm::function_ref) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:11484:9
>   #1 0xde4e7ca in 
> clang::OverloadCandidateSet::NoteCandidates(std::__1::pair  clang::PartialDiagnostic>, clang::Sema&, 
> clang::OverloadCandidateDisplayKind, llvm::ArrayRef, 
> llvm::StringRef, clang::SourceLocation, llvm::function_ref (clang::OverloadCandidate&)>) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:11529:9
>   #2 0xde6316f in FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, 
> clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
> llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, 
> clang::OverloadCandidateSet*, clang::OverloadCandidate**, 
> clang::OverloadingResult, bool) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:12959:19
>   #3 0xde6296b in clang::Sema::BuildOverloadedCallExpr(clang::Scope*, 
> clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, 
> llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, 
> bool, bool) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaOverload.cpp:13032:10
>   #4 0xd4e126b in clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, 
> clang::SourceLocation, llvm::MutableArrayRef, 
> clang::SourceLocation, clang::Expr*, bool) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:6378:16
>   #5 0xd53e073 in clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, 
> clang::SourceLocation, llvm::MutableArrayRef, 
> clang::SourceLocation, clang::Expr*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:6275:7
>   #6 0xcaa957f in 
> clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult true>) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:2066:23
>   #7 0xcaaf03e in 
> clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, 
> clang::Parser::TypeCastState, bool, bool*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:1811:9
>   #8 0xcaa5f3e in 
> clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, 
> clang::Parser::TypeCastState, bool, bool*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:681:20
>   #9 0xcaa15f3 in 
> clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:173:20
>   #10 0xcaa13ad in 
> clang::Parser::ParseExpression(clang::Parser::TypeCastState) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:124:18
>   #11 0xcbc8288 in 
> clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:446:19
>   #12 0xcbc2183 in 
> clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector  32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, 
> clang::Parser::ParsedAttributesWithRange&) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseStmt.cpp:234:12
>   #13 0xcbc119d in 
> clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector 32u>&, clang::Parser::ParsedStmtCo

[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-17 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D84362#2279688 , @tra wrote:

> Apparently this patch triggers compiler crashes on some of our code. I'll try 
> to create a reproducer, but it would be great to revert the patch for now.

It's likely the same issue as the one reported in D84364 
, but we probably triggered it independently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84362

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Brandon Bergren via Phabricator via cfe-commits
Bdragon28 added a comment.

In D79916#2279816 , @jrtc27 wrote:

> In D79916#2279812 , @Bdragon28 wrote:
>
>> In D79916#2279045 , @jrtc27 wrote:
>>
>>> This has significantly regressed FreeBSD's performance with the new version 
>>> of Clang. It seems Clang does not inline functions at -O1, unlike GCC, and 
>>> since FreeBSD currently compiles its kernel with -O whenever debug symbols 
>>> are enabled[1] (which, of course, is almost always true), this results in 
>>> all its `static inline` helper functions not being inlined at all, a 
>>> pattern that is common in the kernel, used for things like `get_curthread` 
>>> and the atomics implementations.
>>>
>>> [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
>>> debugger stack traces" (well, before then there was ping-ponging between -O 
>>> and -O2 based on concerns around correctness vs performance, but amd64 is 
>>> an exception that has always used -O2 since r127180 it seems). Given that 
>>> GCC will inline at -O, at least these days, the motivation seems to no 
>>> longer exist, and compiling a kernel at anything other than -O2 (or maybe 
>>> -O3) seems like a silly thing to do, but nevertheless it's what is 
>>> currently done.
>>>
>>> Cc: @dim @trasz
>>
>> This is actually SUCH a bad idea that a kernel built with -O will *not work 
>> at all* on 32 bit powerpc platforms (presumably due to allocating stack 
>> frames in the middle of assembly fragments in the memory management that are 
>> supposed to be inlined at all times.) I had to hack kern.pre.mk to rquest 
>> -O2 at all times just to get a functioning kernel.
>
> Well, -O0, -O1, -O2 and -O should all produce working kernels, and any cases 
> where they don't are compiler bugs (or kernel bugs if they rely on UB) that 
> should be fixed, not worked around by tweaking the compiler flags in a 
> fragile way until you get the behaviour relied on. Correctness and 
> performance are very different issues here.

As an example:

  static __inline void
  mtsrin(vm_offset_t va, register_t value)
  {
  
  __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
  }

This code is used in the mmu when bootstrapping the cpu like so:

  for (i = 0; i < 16; i++)
  mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
  powerpc_sync();
  
  sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
  __asm __volatile("mtsdr1 %0" :: "r"(sdr));
  isync();
  
  tlbia();

During the loop there, we are in the middle of programming the MMU segment 
registers in real mode, and is supposed to be doing all work out of registers. 
(and powerpc_sync() and isync() should be expanded to their single assembly 
instruction, not a function call. The whole point of calling those is that we 
are in an inconsistent hardware state and need to sync up before continuing 
execution)

If there isn't a way to force inlining, we will have to change to using 
preprocessor macros in cpufunc.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D87791: [CUDA][HIP] Fix -gsplit-dwarf option

2020-09-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In D87791#2279821 , @tra wrote:

> In D87791#2278417 , @yaxunl wrote:
>
>> Therefore in either case there is no need to rename the intermediate .o 
>> files since they are temporary files which have unique names.
>>
>> The .dwo files are not temporary files. They are supposed to be shipped with 
>> .o files for debugging info.
>
> Ack.  
> BTW, is split-dwarf useful for AMD GPUs on device side? I don't think we can 
> currently utilize DWO files on device side with CUDA at all. To think of it, 
> it's probably going to break GPU-side debugging as CUDA can only deal with 
> dwarf info embedded in the GPU binary. 
> If it does not work for AMD GPUs, perhaps we should just disable it for GPUs.

It is requested by our debugger team, so it should work with amdgpu.

>> Since .dwo files are not temporary files, it is not necessary to follow the 
>> -save-temps name convention. For the host object, we keep the original .dwo 
>> file name. For the device object, we add '_' and GPU arch to the stem, which 
>> is sufficient and concise.
>
> What will happen with `-save-temps` ? Will dwo files match object file names?

with -save-temps, the saved temporary files will be like 
test-hip-amdgcn-amd-amdhsa-gfx906.o. The dwo file will be like test_gfx906.dwo.


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

https://reviews.llvm.org/D87791

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Brandon Bergren via Phabricator via cfe-commits
Bdragon28 added a comment.

In D79916#2279863 , @Bdragon28 wrote:

> In D79916#2279816 , @jrtc27 wrote:
>
>> In D79916#2279812 , @Bdragon28 
>> wrote:
>>
>>> In D79916#2279045 , @jrtc27 wrote:
>>>
 This has significantly regressed FreeBSD's performance with the new 
 version of Clang. It seems Clang does not inline functions at -O1, unlike 
 GCC, and since FreeBSD currently compiles its kernel with -O whenever 
 debug symbols are enabled[1] (which, of course, is almost always true), 
 this results in all its `static inline` helper functions not being inlined 
 at all, a pattern that is common in the kernel, used for things like 
 `get_curthread` and the atomics implementations.

 [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
 debugger stack traces" (well, before then there was ping-ponging between 
 -O and -O2 based on concerns around correctness vs performance, but amd64 
 is an exception that has always used -O2 since r127180 it seems). Given 
 that GCC will inline at -O, at least these days, the motivation seems to 
 no longer exist, and compiling a kernel at anything other than -O2 (or 
 maybe -O3) seems like a silly thing to do, but nevertheless it's what is 
 currently done.

 Cc: @dim @trasz
>>>
>>> This is actually SUCH a bad idea that a kernel built with -O will *not work 
>>> at all* on 32 bit powerpc platforms (presumably due to allocating stack 
>>> frames in the middle of assembly fragments in the memory management that 
>>> are supposed to be inlined at all times.) I had to hack kern.pre.mk to 
>>> rquest -O2 at all times just to get a functioning kernel.
>>
>> Well, -O0, -O1, -O2 and -O should all produce working kernels, and any cases 
>> where they don't are compiler bugs (or kernel bugs if they rely on UB) that 
>> should be fixed, not worked around by tweaking the compiler flags in a 
>> fragile way until you get the behaviour relied on. Correctness and 
>> performance are very different issues here.
>
> As an example:
>
>   static __inline void
>   mtsrin(vm_offset_t va, register_t value)
>   {
>   
>   __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
>   }
>
> This code is used in the mmu when bootstrapping the cpu like so:
>
>   for (i = 0; i < 16; i++)
>   mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
>   powerpc_sync();
>   
>   sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
>   __asm __volatile("mtsdr1 %0" :: "r"(sdr));
>   isync();
>   
>   tlbia();
>
> During the loop there, we are in the middle of programming the MMU segment 
> registers in real mode, and is supposed to be doing all work out of 
> registers. (and powerpc_sync() and isync() should be expanded to their single 
> assembly instruction, not a function call. The whole point of calling those 
> is that we are in an inconsistent hardware state and need to sync up before 
> continuing execution)
>
> If there isn't a way to force inlining, we will have to change to using 
> preprocessor macros in cpufunc.h.

Actually, this is probably a bad example. Since we're in real mode it doesn't 
really matter. But I can see other places where powerpc_sync() / isync() are 
dangerous to expand to a function call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D79916#2279863 , @Bdragon28 wrote:

> In D79916#2279816 , @jrtc27 wrote:
>
>> In D79916#2279812 , @Bdragon28 
>> wrote:
>>
>>> In D79916#2279045 , @jrtc27 wrote:
>>>
 This has significantly regressed FreeBSD's performance with the new 
 version of Clang. It seems Clang does not inline functions at -O1, unlike 
 GCC, and since FreeBSD currently compiles its kernel with -O whenever 
 debug symbols are enabled[1] (which, of course, is almost always true), 
 this results in all its `static inline` helper functions not being inlined 
 at all, a pattern that is common in the kernel, used for things like 
 `get_curthread` and the atomics implementations.

 [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
 debugger stack traces" (well, before then there was ping-ponging between 
 -O and -O2 based on concerns around correctness vs performance, but amd64 
 is an exception that has always used -O2 since r127180 it seems). Given 
 that GCC will inline at -O, at least these days, the motivation seems to 
 no longer exist, and compiling a kernel at anything other than -O2 (or 
 maybe -O3) seems like a silly thing to do, but nevertheless it's what is 
 currently done.

 Cc: @dim @trasz
>>>
>>> This is actually SUCH a bad idea that a kernel built with -O will *not work 
>>> at all* on 32 bit powerpc platforms (presumably due to allocating stack 
>>> frames in the middle of assembly fragments in the memory management that 
>>> are supposed to be inlined at all times.) I had to hack kern.pre.mk to 
>>> rquest -O2 at all times just to get a functioning kernel.
>>
>> Well, -O0, -O1, -O2 and -O should all produce working kernels, and any cases 
>> where they don't are compiler bugs (or kernel bugs if they rely on UB) that 
>> should be fixed, not worked around by tweaking the compiler flags in a 
>> fragile way until you get the behaviour relied on. Correctness and 
>> performance are very different issues here.
>
> As an example:
>
>   static __inline void
>   mtsrin(vm_offset_t va, register_t value)
>   {
>   
>   __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
>   }
>
> This code is used in the mmu when bootstrapping the cpu like so:
>
>   for (i = 0; i < 16; i++)
>   mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
>   powerpc_sync();
>   
>   sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
>   __asm __volatile("mtsdr1 %0" :: "r"(sdr));
>   isync();
>   
>   tlbia();
>
> During the loop there, we are in the middle of programming the MMU segment 
> registers in real mode, and is supposed to be doing all work out of 
> registers. (and powerpc_sync() and isync() should be expanded to their single 
> assembly instruction, not a function call. The whole point of calling those 
> is that we are in an inconsistent hardware state and need to sync up before 
> continuing execution)
>
> If there isn't a way to force inlining, we will have to change to using 
> preprocessor macros in cpufunc.h.

There is, it's called `__attribute__((always_inline))` and supported by both 
GCC and Clang. But at -O0 you'll still have register allocation to deal with, 
so really that code is just fundamentally broken and should not be written in 
C. There is no way for you to guarantee stack spills are not used, it's way out 
of scope for C.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Brandon Bergren via Phabricator via cfe-commits
Bdragon28 added a comment.

In D79916#2279866 , @jrtc27 wrote:

> In D79916#2279863 , @Bdragon28 wrote:
>
>> In D79916#2279816 , @jrtc27 wrote:
>>
>>> In D79916#2279812 , @Bdragon28 
>>> wrote:
>>>
 In D79916#2279045 , @jrtc27 wrote:

> This has significantly regressed FreeBSD's performance with the new 
> version of Clang. It seems Clang does not inline functions at -O1, unlike 
> GCC, and since FreeBSD currently compiles its kernel with -O whenever 
> debug symbols are enabled[1] (which, of course, is almost always true), 
> this results in all its `static inline` helper functions not being 
> inlined at all, a pattern that is common in the kernel, used for things 
> like `get_curthread` and the atomics implementations.
>
> [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
> debugger stack traces" (well, before then there was ping-ponging between 
> -O and -O2 based on concerns around correctness vs performance, but amd64 
> is an exception that has always used -O2 since r127180 it seems). Given 
> that GCC will inline at -O, at least these days, the motivation seems to 
> no longer exist, and compiling a kernel at anything other than -O2 (or 
> maybe -O3) seems like a silly thing to do, but nevertheless it's what is 
> currently done.
>
> Cc: @dim @trasz

 This is actually SUCH a bad idea that a kernel built with -O will *not 
 work at all* on 32 bit powerpc platforms (presumably due to allocating 
 stack frames in the middle of assembly fragments in the memory management 
 that are supposed to be inlined at all times.) I had to hack kern.pre.mk 
 to rquest -O2 at all times just to get a functioning kernel.
>>>
>>> Well, -O0, -O1, -O2 and -O should all produce working kernels, and any 
>>> cases where they don't are compiler bugs (or kernel bugs if they rely on 
>>> UB) that should be fixed, not worked around by tweaking the compiler flags 
>>> in a fragile way until you get the behaviour relied on. Correctness and 
>>> performance are very different issues here.
>>
>> As an example:
>>
>>   static __inline void
>>   mtsrin(vm_offset_t va, register_t value)
>>   {
>>   
>>   __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
>>   }
>>
>> This code is used in the mmu when bootstrapping the cpu like so:
>>
>>   for (i = 0; i < 16; i++)
>>   mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
>>   powerpc_sync();
>>   
>>   sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
>>   __asm __volatile("mtsdr1 %0" :: "r"(sdr));
>>   isync();
>>   
>>   tlbia();
>>
>> During the loop there, we are in the middle of programming the MMU segment 
>> registers in real mode, and is supposed to be doing all work out of 
>> registers. (and powerpc_sync() and isync() should be expanded to their 
>> single assembly instruction, not a function call. The whole point of calling 
>> those is that we are in an inconsistent hardware state and need to sync up 
>> before continuing execution)
>>
>> If there isn't a way to force inlining, we will have to change to using 
>> preprocessor macros in cpufunc.h.
>
> There is, it's called `__attribute__((always_inline))` and supported by both 
> GCC and Clang. But at -O0 you'll still have register allocation to deal with, 
> so really that code is just fundamentally broken and should not be written in 
> C. There is no way for you to guarantee stack spills are not used, it's way 
> out of scope for C.

Is there a way to have always_inline and unused at the same time? I tried using 
always_inline and it caused warnings in things that used *parts* of cpufunc.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

(and FreeBSD has an `__always_inline` in sys/sys/cdef.s like `__inline`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


Re: [clang] 829d14e - Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"

2020-09-17 Thread Roman Lebedev via cfe-commits
On Thu, Sep 17, 2020 at 8:57 PM Yaxun Liu via cfe-commits
 wrote:
>
>
> Author: Yaxun (Sam) Liu
> Date: 2020-09-17T13:56:09-04:00
> New Revision: 829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91
>
> URL: 
> https://github.com/llvm/llvm-project/commit/829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91
> DIFF: 
> https://github.com/llvm/llvm-project/commit/829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91.diff
>
> LOG: Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"
>
> This reverts commit ee5519d323571c4a9a7d92cb817023c9b95334cd.

It is a really good idea for a commit message to actually explain what
the commit does, not just state what it is.

> Added:
>
>
> Modified:
> clang/include/clang/AST/ASTContext.h
> clang/include/clang/AST/Attr.h
> clang/include/clang/AST/CanonicalType.h
> clang/include/clang/AST/Decl.h
> clang/include/clang/AST/DeclCXX.h
> clang/include/clang/AST/DeclarationName.h
> clang/include/clang/AST/NestedNameSpecifier.h
> clang/include/clang/AST/TemplateBase.h
> clang/include/clang/AST/TemplateName.h
> clang/include/clang/AST/Type.h
> clang/include/clang/Basic/Diagnostic.h
> clang/include/clang/Basic/PartialDiagnostic.h
> clang/include/clang/Sema/Ownership.h
> clang/include/clang/Sema/ParsedAttr.h
> clang/include/clang/Sema/Sema.h
> clang/lib/AST/ASTContext.cpp
> clang/lib/AST/DeclCXX.cpp
> clang/lib/AST/TemplateBase.cpp
> clang/lib/AST/TemplateName.cpp
> clang/lib/Basic/Diagnostic.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/AST/ASTContext.h 
> b/clang/include/clang/AST/ASTContext.h
> index 397fee4d866b..de0d1198b6d4 100644
> --- a/clang/include/clang/AST/ASTContext.h
> +++ b/clang/include/clang/AST/ASTContext.h
> @@ -3064,9 +3064,8 @@ OPT_LIST(V)
>  };
>
>  /// Insertion operator for diagnostics.
> -const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase &DB,
> -   const ASTContext::SectionInfo &Section);
> +const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +const ASTContext::SectionInfo &Section);
>
>  /// Utility function for constructing a nullary selector.
>  inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {
>
> diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
> index b4dce8f41c67..b3729b2e0d99 100644
> --- a/clang/include/clang/AST/Attr.h
> +++ b/clang/include/clang/AST/Attr.h
> @@ -350,12 +350,19 @@ struct ParsedTargetAttr {
>
>  #include "clang/AST/Attrs.inc"
>
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase &DB, const Attr *At) {
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +   const Attr *At) {
>DB.AddTaggedVal(reinterpret_cast(At),
>DiagnosticsEngine::ak_attr);
>return DB;
>  }
> +
> +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
> +   const Attr *At) {
> +  PD.AddTaggedVal(reinterpret_cast(At),
> +  DiagnosticsEngine::ak_attr);
> +  return PD;
> +}
>  }  // end namespace clang
>
>  #endif
>
> diff  --git a/clang/include/clang/AST/CanonicalType.h 
> b/clang/include/clang/AST/CanonicalType.h
> index b6d9b69db09a..488284713bce 100644
> --- a/clang/include/clang/AST/CanonicalType.h
> +++ b/clang/include/clang/AST/CanonicalType.h
> @@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() 
> const {
>return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
>  }
>
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase &DB, CanQualType T) {
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +   CanQualType T) {
>DB << static_cast(T);
>return DB;
>  }
>
> diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
> index 852ba2316f82..c2511514fe72 100644
> --- a/clang/include/clang/AST/Decl.h
> +++ b/clang/include/clang/AST/Decl.h
> @@ -4513,8 +4513,14 @@ class EmptyDecl : public Decl {
>
>  /// Insertion operator for diagnostics.  This allows sending NamedDecl's
>  /// into a diagnostic with <<.
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase &PD, const NamedDecl *ND) {
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +   const NamedDecl* ND) {
> +  DB.AddTaggedVal(reinterpret_cast(ND),
> +  DiagnosticsEngine::ak_nameddecl);
> +  return DB;
> +}
> +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
> +   const NamedDecl* ND) {
>PD.AddTaggedVal(reinterpret_cast(ND),
>DiagnosticsEngine::ak_nameddecl);
>return PD;
>
>

Re: [clang-tools-extra] 772bd8a - Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"

2020-09-17 Thread Roman Lebedev via cfe-commits
Same comment about commit message, thanks

On Thu, Sep 17, 2020 at 8:56 PM Yaxun Liu via cfe-commits
 wrote:
>
>
> Author: Yaxun (Sam) Liu
> Date: 2020-09-17T13:55:31-04:00
> New Revision: 772bd8a7d99b8db899f594d393986e4b6cd85aa1
>
> URL: 
> https://github.com/llvm/llvm-project/commit/772bd8a7d99b8db899f594d393986e4b6cd85aa1
> DIFF: 
> https://github.com/llvm/llvm-project/commit/772bd8a7d99b8db899f594d393986e4b6cd85aa1.diff
>
> LOG: Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host 
> device functions"
>
> This reverts commit 7f1f89ec8d9944559042bb6d3b1132eabe3409de.
>
> This reverts commit 40df06cdafc010002fc9cfe1dda73d689b7d27a6.
>
> Added:
>
>
> Modified:
> clang-tools-extra/clangd/Diagnostics.cpp
> clang/include/clang/Basic/Diagnostic.td
> clang/include/clang/Basic/DiagnosticAST.h
> clang/include/clang/Basic/DiagnosticAnalysis.h
> clang/include/clang/Basic/DiagnosticComment.h
> clang/include/clang/Basic/DiagnosticCrossTU.h
> clang/include/clang/Basic/DiagnosticDriver.h
> clang/include/clang/Basic/DiagnosticFrontend.h
> clang/include/clang/Basic/DiagnosticIDs.h
> clang/include/clang/Basic/DiagnosticLex.h
> clang/include/clang/Basic/DiagnosticParse.h
> clang/include/clang/Basic/DiagnosticRefactoring.h
> clang/include/clang/Basic/DiagnosticSema.h
> clang/include/clang/Basic/DiagnosticSemaKinds.td
> clang/include/clang/Basic/DiagnosticSerialization.h
> clang/include/clang/Basic/LangOptions.def
> clang/include/clang/Driver/Options.td
> clang/include/clang/Sema/Sema.h
> clang/lib/Basic/DiagnosticIDs.cpp
> clang/lib/Driver/ToolChains/Cuda.cpp
> clang/lib/Driver/ToolChains/HIP.cpp
> clang/lib/Frontend/CompilerInvocation.cpp
> clang/lib/Sema/AnalysisBasedWarnings.cpp
> clang/lib/Sema/Sema.cpp
> clang/lib/Sema/SemaAttr.cpp
> clang/lib/Sema/SemaCUDA.cpp
> clang/lib/Sema/SemaDecl.cpp
> clang/lib/Sema/SemaExprObjC.cpp
> clang/lib/Sema/SemaOpenMP.cpp
> clang/lib/Sema/SemaOverload.cpp
> clang/lib/Sema/SemaSYCL.cpp
> clang/lib/Sema/SemaStmt.cpp
> clang/lib/Sema/SemaStmtAsm.cpp
> clang/lib/Sema/SemaTemplateInstantiate.cpp
> clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
> clang/lib/Sema/SemaTemplateVariadic.cpp
> clang/lib/Sema/SemaType.cpp
> clang/test/TableGen/DiagnosticBase.inc
> clang/tools/diagtool/DiagnosticNames.cpp
> clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
>
> Removed:
> clang/test/SemaCUDA/deferred-oeverload.cu
> clang/test/TableGen/deferred-diag.td
>
>
> 
> diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
> b/clang-tools-extra/clangd/Diagnostics.cpp
> index 18ff96202e0a..afa72f9d4051 100644
> --- a/clang-tools-extra/clangd/Diagnostics.cpp
> +++ b/clang-tools-extra/clangd/Diagnostics.cpp
> @@ -43,7 +43,7 @@ namespace {
>  const char *getDiagnosticCode(unsigned ID) {
>switch (ID) {
>  #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROPU, SFINAE, NOWERROR,
>   \
> - SHOWINSYSHEADER, DEFERRABLE, CATEGORY)  
>   \
> + SHOWINSYSHEADER, CATEGORY)  
>   \
>case clang::diag::ENUM:
>   \
>  return #ENUM;
>  #include "clang/Basic/DiagnosticASTKinds.inc"
>
> diff  --git a/clang/include/clang/Basic/Diagnostic.td 
> b/clang/include/clang/Basic/Diagnostic.td
> index ab2c738a2ace..48ba8c0f469f 100644
> --- a/clang/include/clang/Basic/Diagnostic.td
> +++ b/clang/include/clang/Basic/Diagnostic.td
> @@ -45,7 +45,6 @@ class TextSubstitution {
>// diagnostics
>string Component = "";
>string CategoryName = "";
> -  bit Deferrable = 0;
>  }
>
>  // Diagnostic Categories.  These can be applied to groups or individual
> @@ -84,7 +83,6 @@ class Diagnostic defaultmapping> {
>bitAccessControl = 0;
>bitWarningNoWerror = 0;
>bitShowInSystemHeader = 0;
> -  bitDeferrable = 0;
>Severity   DefaultSeverity = defaultmapping;
>DiagGroup  Group;
>string CategoryName = "";
> @@ -108,14 +106,6 @@ class SuppressInSystemHeader {
>bit ShowInSystemHeader = 0;
>  }
>
> -class Deferrable {
> -  bit Deferrable = 1;
> -}
> -
> -class NonDeferrable {
> -  bit Deferrable = 0;
> -}
> -
>  // FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
>  class Error : Diagnostic, 
> SFINAEFailure {
>bit ShowInSystemHeader = 1;
>
> diff  --git a/clang/include/clang/Basic/DiagnosticAST.h 
> b/clang/include/clang/Basic/DiagnosticAST.h
> index 76c31ad9508e..afe5f62e2012 100644
> --- a/clang/include/clang/Basic/DiagnosticAST.h
> +++ b/clang/include/clang/Basic/DiagnosticAST.h
> @@ -15,7 +15,7 @@ namespace clang {
>  namespace diag {
>  enum {
>  #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERR

[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D79916#2279871 , @Bdragon28 wrote:

> In D79916#2279866 , @jrtc27 wrote:
>
>> In D79916#2279863 , @Bdragon28 
>> wrote:
>>
>>> In D79916#2279816 , @jrtc27 wrote:
>>>
 In D79916#2279812 , @Bdragon28 
 wrote:

> In D79916#2279045 , @jrtc27 
> wrote:
>
>> This has significantly regressed FreeBSD's performance with the new 
>> version of Clang. It seems Clang does not inline functions at -O1, 
>> unlike GCC, and since FreeBSD currently compiles its kernel with -O 
>> whenever debug symbols are enabled[1] (which, of course, is almost 
>> always true), this results in all its `static inline` helper functions 
>> not being inlined at all, a pattern that is common in the kernel, used 
>> for things like `get_curthread` and the atomics implementations.
>>
>> [1] This is a dubious decision made in r140400 in 2005 to provide "truer 
>> debugger stack traces" (well, before then there was ping-ponging between 
>> -O and -O2 based on concerns around correctness vs performance, but 
>> amd64 is an exception that has always used -O2 since r127180 it seems). 
>> Given that GCC will inline at -O, at least these days, the motivation 
>> seems to no longer exist, and compiling a kernel at anything other than 
>> -O2 (or maybe -O3) seems like a silly thing to do, but nevertheless it's 
>> what is currently done.
>>
>> Cc: @dim @trasz
>
> This is actually SUCH a bad idea that a kernel built with -O will *not 
> work at all* on 32 bit powerpc platforms (presumably due to allocating 
> stack frames in the middle of assembly fragments in the memory management 
> that are supposed to be inlined at all times.) I had to hack kern.pre.mk 
> to rquest -O2 at all times just to get a functioning kernel.

 Well, -O0, -O1, -O2 and -O should all produce working kernels, and any 
 cases where they don't are compiler bugs (or kernel bugs if they rely on 
 UB) that should be fixed, not worked around by tweaking the compiler flags 
 in a fragile way until you get the behaviour relied on. Correctness and 
 performance are very different issues here.
>>>
>>> As an example:
>>>
>>>   static __inline void
>>>   mtsrin(vm_offset_t va, register_t value)
>>>   {
>>>   
>>>   __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
>>>   }
>>>
>>> This code is used in the mmu when bootstrapping the cpu like so:
>>>
>>>   for (i = 0; i < 16; i++)
>>>   mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
>>>   powerpc_sync();
>>>   
>>>   sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
>>>   __asm __volatile("mtsdr1 %0" :: "r"(sdr));
>>>   isync();
>>>   
>>>   tlbia();
>>>
>>> During the loop there, we are in the middle of programming the MMU segment 
>>> registers in real mode, and is supposed to be doing all work out of 
>>> registers. (and powerpc_sync() and isync() should be expanded to their 
>>> single assembly instruction, not a function call. The whole point of 
>>> calling those is that we are in an inconsistent hardware state and need to 
>>> sync up before continuing execution)
>>>
>>> If there isn't a way to force inlining, we will have to change to using 
>>> preprocessor macros in cpufunc.h.
>>
>> There is, it's called `__attribute__((always_inline))` and supported by both 
>> GCC and Clang. But at -O0 you'll still have register allocation to deal 
>> with, so really that code is just fundamentally broken and should not be 
>> written in C. There is no way for you to guarantee stack spills are not 
>> used, it's way out of scope for C.
>
> Is there a way to have always_inline and unused at the same time? I tried 
> using always_inline and it caused warnings in things that used *parts* of 
> cpufunc.h.

Both `__attribute__((always_inline)) __attribute__((unused))` and 
`__attribute__((always_inline, unused))` work, but really you should use 
`__always_inline __unused` in FreeBSD (which will expand to the former).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


RE: [clang] 829d14e - Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"

2020-09-17 Thread Liu, Yaxun (Sam) via cfe-commits
[AMD Public Use]

It was reverted because it caused regressions in some CUDA apps.

Is there a way for me to modify the commit message?

Thanks.

Sam

-Original Message-
From: Roman Lebedev  
Sent: Thursday, September 17, 2020 2:14 PM
To: Liu, Yaxun (Sam) ; Yaxun Liu 
Cc: cfe-commits@lists.llvm.org
Subject: Re: [clang] 829d14e - Revert "[NFC] Refactor DiagnosticBuilder and 
PartialDiagnostic"

[CAUTION: External Email]

On Thu, Sep 17, 2020 at 8:57 PM Yaxun Liu via cfe-commits 
 wrote:
>
>
> Author: Yaxun (Sam) Liu
> Date: 2020-09-17T13:56:09-04:00
> New Revision: 829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91
>
> URL: 
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> ub.com%2Fllvm%2Fllvm-project%2Fcommit%2F829d14ee0a6aa79c89f7f3d9fcd9d2
> 7d3efd2b91&data=02%7C01%7Cyaxun.liu%40amd.com%7C1165c7b467ad471f37
> 1b08d85b358dcf%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C6373596328
> 68922532&sdata=ngtA%2BYzoY8lfE1krECrmAw%2FXPytw2f8Nz%2FIqoyccX14%3
> D&reserved=0
> DIFF: 
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> ub.com%2Fllvm%2Fllvm-project%2Fcommit%2F829d14ee0a6aa79c89f7f3d9fcd9d2
> 7d3efd2b91.diff&data=02%7C01%7Cyaxun.liu%40amd.com%7C1165c7b467ad4
> 71f371b08d85b358dcf%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C63735
> 9632868922532&sdata=sJJczip6ORLkxglLBk48QiHbZkyrZ1uiKupti6H2ZPE%3D
> &reserved=0
>
> LOG: Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"
>
> This reverts commit ee5519d323571c4a9a7d92cb817023c9b95334cd.

It is a really good idea for a commit message to actually explain what the 
commit does, not just state what it is.

> Added:
>
>
> Modified:
> clang/include/clang/AST/ASTContext.h
> clang/include/clang/AST/Attr.h
> clang/include/clang/AST/CanonicalType.h
> clang/include/clang/AST/Decl.h
> clang/include/clang/AST/DeclCXX.h
> clang/include/clang/AST/DeclarationName.h
> clang/include/clang/AST/NestedNameSpecifier.h
> clang/include/clang/AST/TemplateBase.h
> clang/include/clang/AST/TemplateName.h
> clang/include/clang/AST/Type.h
> clang/include/clang/Basic/Diagnostic.h
> clang/include/clang/Basic/PartialDiagnostic.h
> clang/include/clang/Sema/Ownership.h
> clang/include/clang/Sema/ParsedAttr.h
> clang/include/clang/Sema/Sema.h
> clang/lib/AST/ASTContext.cpp
> clang/lib/AST/DeclCXX.cpp
> clang/lib/AST/TemplateBase.cpp
> clang/lib/AST/TemplateName.cpp
> clang/lib/Basic/Diagnostic.cpp
>
> Removed:
>
>
>
> ##
> ## diff  --git a/clang/include/clang/AST/ASTContext.h 
> b/clang/include/clang/AST/ASTContext.h
> index 397fee4d866b..de0d1198b6d4 100644
> --- a/clang/include/clang/AST/ASTContext.h
> +++ b/clang/include/clang/AST/ASTContext.h
> @@ -3064,9 +3064,8 @@ OPT_LIST(V)
>  };
>
>  /// Insertion operator for diagnostics.
> -const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase &DB,
> -   const ASTContext::SectionInfo &Section);
> +const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +const ASTContext::SectionInfo 
> +&Section);
>
>  /// Utility function for constructing a nullary selector.
>  inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {
>
> diff  --git a/clang/include/clang/AST/Attr.h 
> b/clang/include/clang/AST/Attr.h index b4dce8f41c67..b3729b2e0d99 
> 100644
> --- a/clang/include/clang/AST/Attr.h
> +++ b/clang/include/clang/AST/Attr.h
> @@ -350,12 +350,19 @@ struct ParsedTargetAttr {
>
>  #include "clang/AST/Attrs.inc"
>
> -inline const StreamableDiagnosticBase & -operator<<(const 
> StreamableDiagnosticBase &DB, const Attr *At) {
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +   const Attr *At) {
>DB.AddTaggedVal(reinterpret_cast(At),
>DiagnosticsEngine::ak_attr);
>return DB;
>  }
> +
> +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
> +   const Attr *At) {
> +  PD.AddTaggedVal(reinterpret_cast(At),
> +  DiagnosticsEngine::ak_attr);
> +  return PD;
> +}
>  }  // end namespace clang
>
>  #endif
>
> diff  --git a/clang/include/clang/AST/CanonicalType.h 
> b/clang/include/clang/AST/CanonicalType.h
> index b6d9b69db09a..488284713bce 100644
> --- a/clang/include/clang/AST/CanonicalType.h
> +++ b/clang/include/clang/AST/CanonicalType.h
> @@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() 
> const {
>return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
>  }
>
> -inline const StreamableDiagnosticBase & -operator<<(const 
> StreamableDiagnosticBase &DB, CanQualType T) {
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +   CanQualType T) {
>DB << static_cast(T);
>return DB;
>  }
>

[PATCH] D79916: Map -O to -O1 instead of -O2

2020-09-17 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D79916#2279875 , @jrtc27 wrote:

> In D79916#2279871 , @Bdragon28 wrote:
>
>> In D79916#2279866 , @jrtc27 wrote:
>>
>>> In D79916#2279863 , @Bdragon28 
>>> wrote:
>>>
 In D79916#2279816 , @jrtc27 wrote:

> In D79916#2279812 , @Bdragon28 
> wrote:
>
>> In D79916#2279045 , @jrtc27 
>> wrote:
>>
>>> This has significantly regressed FreeBSD's performance with the new 
>>> version of Clang. It seems Clang does not inline functions at -O1, 
>>> unlike GCC, and since FreeBSD currently compiles its kernel with -O 
>>> whenever debug symbols are enabled[1] (which, of course, is almost 
>>> always true), this results in all its `static inline` helper functions 
>>> not being inlined at all, a pattern that is common in the kernel, used 
>>> for things like `get_curthread` and the atomics implementations.
>>>
>>> [1] This is a dubious decision made in r140400 in 2005 to provide 
>>> "truer debugger stack traces" (well, before then there was ping-ponging 
>>> between -O and -O2 based on concerns around correctness vs performance, 
>>> but amd64 is an exception that has always used -O2 since r127180 it 
>>> seems). Given that GCC will inline at -O, at least these days, the 
>>> motivation seems to no longer exist, and compiling a kernel at anything 
>>> other than -O2 (or maybe -O3) seems like a silly thing to do, but 
>>> nevertheless it's what is currently done.
>>>
>>> Cc: @dim @trasz
>>
>> This is actually SUCH a bad idea that a kernel built with -O will *not 
>> work at all* on 32 bit powerpc platforms (presumably due to allocating 
>> stack frames in the middle of assembly fragments in the memory 
>> management that are supposed to be inlined at all times.) I had to hack 
>> kern.pre.mk to rquest -O2 at all times just to get a functioning kernel.
>
> Well, -O0, -O1, -O2 and -O should all produce working kernels, and any 
> cases where they don't are compiler bugs (or kernel bugs if they rely on 
> UB) that should be fixed, not worked around by tweaking the compiler 
> flags in a fragile way until you get the behaviour relied on. Correctness 
> and performance are very different issues here.

 As an example:

   static __inline void
   mtsrin(vm_offset_t va, register_t value)
   {
   
   __asm __volatile ("mtsrin %0,%1; isync" :: "r"(value), "r"(va));
   }

 This code is used in the mmu when bootstrapping the cpu like so:

   for (i = 0; i < 16; i++)
   mtsrin(i << ADDR_SR_SHFT, kernel_pmap->pm_sr[i]);
   powerpc_sync();
   
   sdr = (u_int)moea_pteg_table | (moea_pteg_mask >> 10);
   __asm __volatile("mtsdr1 %0" :: "r"(sdr));
   isync();
   
   tlbia();

 During the loop there, we are in the middle of programming the MMU segment 
 registers in real mode, and is supposed to be doing all work out of 
 registers. (and powerpc_sync() and isync() should be expanded to their 
 single assembly instruction, not a function call. The whole point of 
 calling those is that we are in an inconsistent hardware state and need to 
 sync up before continuing execution)

 If there isn't a way to force inlining, we will have to change to using 
 preprocessor macros in cpufunc.h.
>>>
>>> There is, it's called `__attribute__((always_inline))` and supported by 
>>> both GCC and Clang. But at -O0 you'll still have register allocation to 
>>> deal with, so really that code is just fundamentally broken and should not 
>>> be written in C. There is no way for you to guarantee stack spills are not 
>>> used, it's way out of scope for C.
>>
>> Is there a way to have always_inline and unused at the same time? I tried 
>> using always_inline and it caused warnings in things that used *parts* of 
>> cpufunc.h.
>
> Both `__attribute__((always_inline)) __attribute__((unused))` and 
> `__attribute__((always_inline, unused))` work, but really you should use 
> `__always_inline __unused` in FreeBSD (which will expand to the former).

But also you really should not get warnings for unused static functions in 
included headers, only ones defined in the C source file itself. We'd have 
countless warnings in the kernel across all architectures otherwise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916

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


  1   2   >