[PATCH] D133249: [libc++] Documents details of the pre-commit CI.

2022-09-09 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added inline comments.



Comment at: clang/www/hacking.html:295-296
+  directory will cause the update of the diff to start a CI run. This dummy
+  file will also add the libc++ group to the list of reviewers. The status of
+  the build will be available in Phabricator.
+

tahonermann wrote:
> ldionne wrote:
> > Mordante wrote:
> > > philnik wrote:
> > > > aaron.ballman wrote:
> > > > > I am guessing the dummy file should then be removed before landing 
> > > > > the commit and we should document that?
> > > > > 
> > > > > (FWIW, adding a dummy file feels really unclean as a design -- it's 
> > > > > mysterious behavior for new contributors, which the documentation 
> > > > > helps with a bit, but also it's a risk for checking in files that are 
> > > > > never intended to be in the tree. If there's a way to improve this 
> > > > > somehow so we don't need to trick the precommit CI into running, that 
> > > > > would be really nice and totally outside of the scope of this review.)
> > > > It would be great if just the bootstrapping build could be run on all 
> > > > clang reviews. That should show most problems with changes in clang. If 
> > > > there are any problems in libc++, fixing them would result in a full CI 
> > > > run. Having libc++ run against the patch would probably also be awesome 
> > > > as a smoke test for any clang changes.
> > > +1 to what @ldionne said.
> > > 
> > > One of the advantages would be that it's possible to test Clang against 
> > > the libc++ code base using different language versions, by defining 
> > > multiple test runs using different language versions. (Slightly related 
> > > to 
> > > https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932)
> > >  @aaron.ballman is looking at extending the Clang pre-commit CI something 
> > > worth looking into?
> > > 
> > > 
> > I agree. Let's:
> > 
> > 1. Setup a `buildkite-pipeline.yml` file that controls the jobs done for 
> > Clang. I think right now this is hardcoded somewhere in 
> > https://github.com/google/llvm-premerge-checks
> > 2. Simply add `LLVM_ENABLE_RUNTIMES=libcxx` to the config that Clang uses 
> > so they'll automatically build libc++ with the Clang that was just built 
> > anyway. That would run on Clang's own agents that are used for Clang tests, 
> > not on the libc++ CI agents. We can adjust if running the libc++ tests 
> > causes too much strain on the infrastructure running Clang CI.
> > 
> > That way, a basic bootstrapping build of libc++ will be run on every Clang 
> > change, and TBH I think all of this added documentation for Clang folks to 
> > test libc++ changes can simply go away. There really wouldn't be a reason 
> > to ever add a `.DELETE_ME` file to libc++ for a Clang patch anymore.
> This sounds like a good approach to me. This might be a bit tangential, but 
> if `libcxx` is present in `LLVM_ENABLE_RUNTIMES`, could we also have the 
> `check-all` target depend on `check-libcxx`? That would help ensure that 
> developers run libc++ tests locally before they hit the CI infrastructure. 
> Likewise for `compiler-rt` and `libcxxabi` and the `check-runtimes` target.
This is currently being implemented by https://reviews.llvm.org/D132438 and 
landed before but had to be reverted unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133249

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


[PATCH] D122620: [clang][DR] Test and mark DR1479 as complete

2022-03-28 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added a reviewer: clang-language-wg.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1479

Clang has implemented this DR as far back as I could go on compiler explorer 
(3.0). This patch simply adds a test case and needed comments for the update 
script to mark it as complete.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122620

Files:
  clang/test/CXX/drs/dr14xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8688,7 +8688,7 @@
 https://wg21.link/cwg1479";>1479
 CD3
 Literal operators and default arguments
-Unknown
+Yes
   
   
 https://wg21.link/cwg1480";>1480
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -463,6 +463,10 @@
 #endif
 } // dr1467
 
+namespace dr1479 { // dr1479: yes
+  int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal 
operator cannot have a default argument}}
+}
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8688,7 +8688,7 @@
 https://wg21.link/cwg1479";>1479
 CD3
 Literal operators and default arguments
-Unknown
+Yes
   
   
 https://wg21.link/cwg1480";>1480
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -463,6 +463,10 @@
 #endif
 } // dr1467
 
+namespace dr1479 { // dr1479: yes
+  int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal operator cannot have a default argument}}
+}
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122620: [clang][DR] Test and mark DR1479 as complete

2022-03-29 Thread Markus Böck 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 rG984554f846c4: [clang][DR] Test and mark DR1479 as complete 
(authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122620

Files:
  clang/test/CXX/drs/dr14xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8688,7 +8688,7 @@
 https://wg21.link/cwg1479";>1479
 CD3
 Literal operators and default arguments
-Unknown
+Yes
   
   
 https://wg21.link/cwg1480";>1480
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -463,6 +463,10 @@
 #endif
 } // dr1467
 
+namespace dr1479 { // dr1479: yes
+  int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal 
operator cannot have a default argument}}
+}
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8688,7 +8688,7 @@
 https://wg21.link/cwg1479";>1479
 CD3
 Literal operators and default arguments
-Unknown
+Yes
   
   
 https://wg21.link/cwg1480";>1480
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -463,6 +463,10 @@
 #endif
 } // dr1467
 
+namespace dr1479 { // dr1479: yes
+  int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal operator cannot have a default argument}}
+}
+
 namespace dr1490 {  // dr1490: 3.7 c++11
   // List-initialization from a string literal
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122674: [clang][DR] Test and mark DR1305 as complete

2022-03-29 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added a reviewer: clang-language-wg.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1305

This DR has always been implemented in all clang versions as far back as I 
could go. This patch basically just adds a test with the needed comments to 
mark it as complete.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122674

Files:
  clang/test/CXX/drs/dr13xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -3,6 +3,16 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+  struct Incomplete; // expected-note {{forward declaration of 
'dr1305::Incomplete'}}
+  struct Complete {};
+
+  int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid 
application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+  int complete = alignof(Complete(&)[]);
+}
+#endif
+
 __extension__ typedef __SIZE_TYPE__ size_t;
 
 namespace std {


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -3,6 +3,16 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+  struct Incomplete; // expected-note {{forward declaration of 'dr1305::Incomplete'}}
+  struct Complete {};
+
+  int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+  int complete = alignof(Complete(&)[]);
+}
+#endif
+
 __extension__ typedef __SIZE_TYPE__ size_t;
 
 namespace std {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122674: [clang][DR] Test and mark DR1305 as complete

2022-03-29 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 418941.
zero9178 added a comment.

Address reviewers comments: Group test nicely with the other dr namespaces.


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

https://reviews.llvm.org/D122674

Files:
  clang/test/CXX/drs/dr13xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -13,6 +13,16 @@
   };
 }
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+struct Incomplete; // expected-note {{forward declaration of 
'dr1305::Incomplete'}}
+struct Complete {};
+
+int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid 
application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+int complete = alignof(Complete(&)[]);
+}
+#endif
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' 
is a constructor name}}
   void f() {


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -13,6 +13,16 @@
   };
 }
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+struct Incomplete; // expected-note {{forward declaration of 'dr1305::Incomplete'}}
+struct Complete {};
+
+int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+int complete = alignof(Complete(&)[]);
+}
+#endif
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' is a constructor name}}
   void f() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122674: [clang][DR] Test and mark DR1305 as complete

2022-03-29 Thread Markus Böck 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 rGc1e614c8eb50: [clang][DR] Test and mark DR1305 as complete 
(authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122674

Files:
  clang/test/CXX/drs/dr13xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -13,6 +13,16 @@
   };
 }
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+struct Incomplete; // expected-note {{forward declaration of 
'dr1305::Incomplete'}}
+struct Complete {};
+
+int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid 
application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+int complete = alignof(Complete(&)[]);
+}
+#endif
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' 
is a constructor name}}
   void f() {


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7644,7 +7644,7 @@
 https://wg21.link/cwg1305";>1305
 CD3
 alignof applied to array of unknown size
-Unknown
+Yes
   
   
 https://wg21.link/cwg1306";>1306
Index: clang/test/CXX/drs/dr13xx.cpp
===
--- clang/test/CXX/drs/dr13xx.cpp
+++ clang/test/CXX/drs/dr13xx.cpp
@@ -13,6 +13,16 @@
   };
 }
 
+#if __cplusplus >= 201103L
+namespace dr1305 { // dr1305: yes
+struct Incomplete; // expected-note {{forward declaration of 'dr1305::Incomplete'}}
+struct Complete {};
+
+int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid application of 'alignof' to an incomplete type 'dr1305::Incomplete'}}
+int complete = alignof(Complete(&)[]);
+}
+#endif
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' is a constructor name}}
   void f() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122682: [clang][DR] Add test for DR1227 and mark it as complete

2022-03-29 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added a reviewer: clang-language-wg.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1227

This DR has been implemented in Clang as far back as I could check. This patch 
simply adds a test and comment to mark it as complete.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122682

Files:
  clang/test/CXX/drs/dr12xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7176,7 +7176,7 @@
 https://wg21.link/cwg1227";>1227
 CD3
 Mixing immediate and non-immediate contexts in deduction failure
-Unknown
+Yes
   
   
 https://wg21.link/cwg1228";>1228
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -27,6 +27,21 @@
 #endif
 }
 
+#if __cplusplus >= 201103L
+namespace dr1227 { // dr1227: yes
+template  struct A { using X = typename T::X; }; // expected-error 
{{type 'int' cannot be used prior to '::' because it has no members}}
+template  typename T::X f(typename A::X);
+template  void f(...) { }
+template  auto g(typename A::X) -> typename T::X; // expected-note 
{{in instantiation of template class 'dr1227::A' requested here}}
+template  void g(...) { }
+
+void h() {
+  f(0); // OK, substituting return type causes deduction to fail
+  g(0); // expected-note {{while substituting explicitly-specified 
template arguments into function template 'g'}}
+}
+}
+#endif
+
 namespace dr1250 { // dr1250: 3.9
 struct Incomplete;
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7176,7 +7176,7 @@
 https://wg21.link/cwg1227";>1227
 CD3
 Mixing immediate and non-immediate contexts in deduction failure
-Unknown
+Yes
   
   
 https://wg21.link/cwg1228";>1228
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -27,6 +27,21 @@
 #endif
 }
 
+#if __cplusplus >= 201103L
+namespace dr1227 { // dr1227: yes
+template  struct A { using X = typename T::X; }; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
+template  typename T::X f(typename A::X);
+template  void f(...) { }
+template  auto g(typename A::X) -> typename T::X; // expected-note {{in instantiation of template class 'dr1227::A' requested here}}
+template  void g(...) { }
+
+void h() {
+  f(0); // OK, substituting return type causes deduction to fail
+  g(0); // expected-note {{while substituting explicitly-specified template arguments into function template 'g'}}
+}
+}
+#endif
+
 namespace dr1250 { // dr1250: 3.9
 struct Incomplete;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122682: [clang][DR] Add test for DR1227 and mark it as complete

2022-03-30 Thread Markus Böck 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 rGe59335e89110: [clang][DR] Add test for DR1227 and mark it as 
complete (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122682

Files:
  clang/test/CXX/drs/dr12xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7176,7 +7176,7 @@
 https://wg21.link/cwg1227";>1227
 CD3
 Mixing immediate and non-immediate contexts in deduction failure
-Unknown
+Yes
   
   
 https://wg21.link/cwg1228";>1228
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -27,6 +27,21 @@
 #endif
 }
 
+#if __cplusplus >= 201103L
+namespace dr1227 { // dr1227: yes
+template  struct A { using X = typename T::X; }; // expected-error 
{{type 'int' cannot be used prior to '::' because it has no members}}
+template  typename T::X f(typename A::X);
+template  void f(...) { }
+template  auto g(typename A::X) -> typename T::X; // expected-note 
{{in instantiation of template class 'dr1227::A' requested here}}
+template  void g(...) { }
+
+void h() {
+  f(0); // OK, substituting return type causes deduction to fail
+  g(0); // expected-note {{while substituting explicitly-specified 
template arguments into function template 'g'}}
+}
+}
+#endif
+
 namespace dr1250 { // dr1250: 3.9
 struct Incomplete;
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7176,7 +7176,7 @@
 https://wg21.link/cwg1227";>1227
 CD3
 Mixing immediate and non-immediate contexts in deduction failure
-Unknown
+Yes
   
   
 https://wg21.link/cwg1228";>1228
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -27,6 +27,21 @@
 #endif
 }
 
+#if __cplusplus >= 201103L
+namespace dr1227 { // dr1227: yes
+template  struct A { using X = typename T::X; }; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
+template  typename T::X f(typename A::X);
+template  void f(...) { }
+template  auto g(typename A::X) -> typename T::X; // expected-note {{in instantiation of template class 'dr1227::A' requested here}}
+template  void g(...) { }
+
+void h() {
+  f(0); // OK, substituting return type causes deduction to fail
+  g(0); // expected-note {{while substituting explicitly-specified template arguments into function template 'g'}}
+}
+}
+#endif
+
 namespace dr1250 { // dr1250: 3.9
 struct Incomplete;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124312: [Driver] Call hasFlag instead of hasArg

2022-04-22 Thread Markus Böck via Phabricator via cfe-commits
zero9178 accepted this revision.
zero9178 added a comment.
This revision is now accepted and ready to land.

Ouch! Two bugs, and the one in the testsuite covered up the former one. Thank 
you for noticing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124312

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


[PATCH] D109975: [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES

2021-09-17 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: phosek, hans, MaskRay, compnerd.
Herald added subscribers: arphaman, mgorny.
zero9178 requested review of this revision.
Herald added projects: clang, LLDB.
Herald added subscribers: lldb-commits, cfe-commits.

Linking against the LibXml2::LibXml2 target has the advantage of not only 
importing the library, but also adding the include path as well as any 
definitions the library requires. In case of a static build of libxml2, eg. a 
define is set on Windows to remove any DLL imports and export.

LLVM already makes use of the target, but c-index-test and lldb were still 
linking against the library only.

The workaround for Mac OS-X that I removed seems to have also been made 
redundant since https://reviews.llvm.org/D84563 I believe


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109975

Files:
  clang/tools/c-index-test/CMakeLists.txt
  lldb/source/Host/CMakeLists.txt


Index: lldb/source/Host/CMakeLists.txt
===
--- lldb/source/Host/CMakeLists.txt
+++ lldb/source/Host/CMakeLists.txt
@@ -137,7 +137,7 @@
   list(APPEND EXTRA_LIBS kvm)
 endif()
 if (LLDB_ENABLE_LIBXML2)
-  list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES})
+  list(APPEND EXTRA_LIBS LibXml2::LibXml2)
 endif()
 if (HAVE_LIBDL)
   list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
Index: clang/tools/c-index-test/CMakeLists.txt
===
--- clang/tools/c-index-test/CMakeLists.txt
+++ clang/tools/c-index-test/CMakeLists.txt
@@ -40,12 +40,7 @@
 
 # If libxml2 is available, make it available for c-index-test.
 if (CLANG_HAVE_LIBXML)
-  if ((CMAKE_OSX_SYSROOT) AND (EXISTS 
${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}))
-include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})
-  else()
-include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
-  endif()
-  target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
+  target_link_libraries(c-index-test PRIVATE LibXml2::LibXml2)
 endif()
 
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)


Index: lldb/source/Host/CMakeLists.txt
===
--- lldb/source/Host/CMakeLists.txt
+++ lldb/source/Host/CMakeLists.txt
@@ -137,7 +137,7 @@
   list(APPEND EXTRA_LIBS kvm)
 endif()
 if (LLDB_ENABLE_LIBXML2)
-  list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES})
+  list(APPEND EXTRA_LIBS LibXml2::LibXml2)
 endif()
 if (HAVE_LIBDL)
   list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
Index: clang/tools/c-index-test/CMakeLists.txt
===
--- clang/tools/c-index-test/CMakeLists.txt
+++ clang/tools/c-index-test/CMakeLists.txt
@@ -40,12 +40,7 @@
 
 # If libxml2 is available, make it available for c-index-test.
 if (CLANG_HAVE_LIBXML)
-  if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}))
-include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})
-  else()
-include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
-  endif()
-  target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
+  target_link_libraries(c-index-test PRIVATE LibXml2::LibXml2)
 endif()
 
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109975: [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES

2021-09-17 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D109975#3006580 , @Quuxplusone 
wrote:

> Serendipitously, I just yesterday upgraded from OSX 10.14 to 10.15, and have 
> been unable to build clang because, even with a totally-empty-and-brand-new 
> build directory, CMake says:
>
>   CMake Error in lib/WindowsManifest/CMakeLists.txt:
> Imported target "LibXml2::LibXml2" includes non-existent path
>   
> "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/libxml2"
> in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
> * The path was deleted, renamed, or moved to another location.
> * An install or uninstall procedure did not complete successfully.
> * The installation package was faulty and references files it does not
> provide.
>   -- Generating done
>   CMake Generate step failed.  Build files cannot be regenerated correctly.
>
> Do you think this PR would fix that issue on OSX 10.15?
> (IMHO it's also weird that OSX would even be trying to build anything with 
> `Windows` in the name.)

Since there is nothing platform specific in the code of WindowsManifest it'd 
make sense to build it on any OS; At the very least for cross compile setups.

I sadly am not very accustomed to Macs so I don't know the details, but I don't 
think this patch would change anything about your situation.

Could it maybe be related to the `CMAKE_OSX_SYSROOT` variable somehow? CMake 
seems to use it to lookup packages from the platform SDK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109975

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


[PATCH] D109975: [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES

2021-09-25 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b61f43b6096: [CMake] Consistently use the LibXml2::LibXml2 
target instead of… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109975

Files:
  clang/tools/c-index-test/CMakeLists.txt
  lldb/source/Host/CMakeLists.txt


Index: lldb/source/Host/CMakeLists.txt
===
--- lldb/source/Host/CMakeLists.txt
+++ lldb/source/Host/CMakeLists.txt
@@ -137,7 +137,7 @@
   list(APPEND EXTRA_LIBS kvm)
 endif()
 if (LLDB_ENABLE_LIBXML2)
-  list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES})
+  list(APPEND EXTRA_LIBS LibXml2::LibXml2)
 endif()
 if (HAVE_LIBDL)
   list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
Index: clang/tools/c-index-test/CMakeLists.txt
===
--- clang/tools/c-index-test/CMakeLists.txt
+++ clang/tools/c-index-test/CMakeLists.txt
@@ -40,12 +40,7 @@
 
 # If libxml2 is available, make it available for c-index-test.
 if (CLANG_HAVE_LIBXML)
-  if ((CMAKE_OSX_SYSROOT) AND (EXISTS 
${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}))
-include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})
-  else()
-include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
-  endif()
-  target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
+  target_link_libraries(c-index-test PRIVATE LibXml2::LibXml2)
 endif()
 
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)


Index: lldb/source/Host/CMakeLists.txt
===
--- lldb/source/Host/CMakeLists.txt
+++ lldb/source/Host/CMakeLists.txt
@@ -137,7 +137,7 @@
   list(APPEND EXTRA_LIBS kvm)
 endif()
 if (LLDB_ENABLE_LIBXML2)
-  list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES})
+  list(APPEND EXTRA_LIBS LibXml2::LibXml2)
 endif()
 if (HAVE_LIBDL)
   list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
Index: clang/tools/c-index-test/CMakeLists.txt
===
--- clang/tools/c-index-test/CMakeLists.txt
+++ clang/tools/c-index-test/CMakeLists.txt
@@ -40,12 +40,7 @@
 
 # If libxml2 is available, make it available for c-index-test.
 if (CLANG_HAVE_LIBXML)
-  if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}))
-include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})
-  else()
-include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
-  endif()
-  target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
+  target_link_libraries(c-index-test PRIVATE LibXml2::LibXml2)
 endif()
 
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-12 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, russell.gallop.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When targeting a MSVC triple, --dependant-libs with the name of the clang 
runtime library for profiling is added to the command line args. In it's 
current implementations clang_rt.profile- is chosen as the name. When 
building a distribution using LLVM_ENABLE_PER_TARGET_RUNTIME_DIR this fails, 
due to the runtime file names not having an architecture suffix in the filename.

This patch instead uses getCompilerRT which is used in other parts of the 
compiler to possibly find the right library name first, or fall back to the old 
behaviour if not.

If accepted I would need this patch to be committed for me:
Username: zero9178
email: markus.boec...@gmail.com


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96638

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/instrprof-ld.c


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: 
"--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: 
"--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -58,11 +58,11 @@
 
 // RUN: %clang_cl -### /FA -fprofile-instr-generate -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-INSTR-GENERATE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- 
%s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-INSTR-GENERATE-FILE %s
-// CHECK-PROFILE-INSTR-GENERATE: "-fprofile-instrument=clang" 
"--dependent-lib=clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-PROFILE-INSTR-GENERATE: "-fprofile-instrument=clang" 
"--dependent-lib=clang_rt.profile{{[^"]*}}.lib"
 // CHECK-PROFILE-INSTR-GENERATE-FILE: 
"-fprofile-instrument-path=/tmp/somefile.profraw"
 
 // RUN: %clang_cl -### /FA -fprofile-generate -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE %s
-// CHECK-PROFILE-GENERATE: "-fprofile-instrument=llvm" 
"--dependent-lib=clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-PROFILE-GENERATE: "-fprofile-instrument=llvm" 
"--dependent-lib=clang_rt.profile{{[^"]*}}.lib"
 
 // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use -- %s 
2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use=file 
-- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -792,8 +792,9 @@
 CmdArgs.push_back("-fprofile-instrument=clang");
 if (TC.getTriple().isWindowsMSVCEnvironment()) {
   // Add dependent lib for clang_rt.profile
+  std::string ClangRtProfilePath = TC.getCompilerRT(Args, "profile");
   CmdArgs.push_back(Args.MakeArgString(
-  "--dependent-lib=" + TC.getCompilerRTBasename(Args, "profile")));
+  "--dependent-lib=" + llvm::sys::path::filename(ClangRtProfilePath)));
 }
   }
 


Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonica

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

Friendly bump :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96638

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


[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 325868.
zero9178 added a comment.
Herald added a subscriber: mstorsjo.

Refactored getCompilerRTBasename. It now simply refers to getCompilerRT, which 
gathers a full path to the specified runtime library. getCompilerRTBasename 
then simply returns only the filename component. The previous contents of 
getCompilerRTBasename have been refactored into a static function used by 
getCompilerRT. Only users of either of the two functions has been in clang-cl 
specific code and besides getCompilerRT, the AddArch parameter has never been 
explicitly specified. As it is now autodetected I think it makes sense to 
remove the parameter off of getCompilerRTBasename altogether as well.


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

https://reviews.llvm.org/D96638

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/cl-options.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -666,16 +666,16 @@
 // RUN: -target x86_64-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN64 %s
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client-x86_64.lib"
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats-x86_64.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client{{(-x86_64)?}}.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
 // CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target i686-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN32 %s
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client-i386.lib"
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats-i386.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client{{(-i386)?}}.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats{{(-i386)?}}.lib"
 // CHECK-CFI-STATS-WIN32: "--linker-option=/include:___sanitizer_stats_register"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -20,17 +20,17 @@
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-MSVC
 // RUN: %clang -target x86_64-w64-mingw32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN64-MINGW
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-WIN-CXX,CHECK-UNDEFINED-MSVC
-// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib"
-// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
-// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a"
+// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
+// CHECK-UNDEFINED

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-23 Thread Markus Böck 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 rG7f9d5d6e444c: [Driver][Windows] Support per-target runtimes 
dir layout for profile instr… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96638

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/cl-options.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -666,16 +666,16 @@
 // RUN: -target x86_64-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN64 %s
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client-x86_64.lib"
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats-x86_64.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client{{(-x86_64)?}}.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
 // CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target i686-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN32 %s
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client-i386.lib"
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats-i386.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client{{(-i386)?}}.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats{{(-i386)?}}.lib"
 // CHECK-CFI-STATS-WIN32: "--linker-option=/include:___sanitizer_stats_register"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -20,17 +20,17 @@
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-MSVC
 // RUN: %clang -target x86_64-w64-mingw32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN64-MINGW
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-WIN-CXX,CHECK-UNDEFINED-MSVC
-// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib"
-// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
-// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a"
+// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
+// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-x86_64)?}}.lib"
+// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone{{(-x86_64)?}}.a"
 // CHECK-UNDEFINED-WIN-CXX: "--dependent-lib={{[^"]*}}ubsan_standalone_cxx{{[^"]*}}.lib"
 // CHECK-UNDEFINED-MSVC-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|align

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 326022.
zero9178 added a comment.

Undid refactoring of getCompilerRTBasename. Previous diffs introduced a new 
internal function that built the basename. In that version 
getCompilerRTBasename simply called getCompilerRT and extracted the filename 
component.

This lead to issues as Toolchains such as Baremetal override 
getCompilerRTBasename to provide a different basename then default.

This diff now instead changes the default implementation of 
getCompilerRTBasename to also auto detect whether an architecture suffix should 
be used or not. Therefore callers of getCompilerRTBasename can rely on it 
picking the right filenames as well. getCompilerRT still calls into 
getCompilerRTBasename to get the filename, allowing Toolchains to override the 
virtual function.

There is now sadly a bit of repetition as both getCompilerRT and 
getCompilerRTBasename have to look through the library path but this should not 
cause any issues I believe.

Sorry for the inconvenience and the test failure.


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

https://reviews.llvm.org/D96638

Files:
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -22,6 +22,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/XRayArgs.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
@@ -413,12 +414,21 @@
   return std::string(Path.str());
 }
 
-static std::string buildCompilerRTBasename(const ToolChain &toolchain,
-   const ArgList &Args,
-   StringRef Component,
-   ToolChain::FileType Type,
-   bool AddArch) {
-  const llvm::Triple &TT = toolchain.getTriple();
+static Optional findInLibraryPath(const ToolChain &TC,
+   StringRef filename) {
+  for (const auto &LibPath : TC.getLibraryPaths()) {
+SmallString<128> P(LibPath);
+llvm::sys::path::append(P, filename);
+if (TC.getVFS().exists(P))
+  return std::string(P.str());
+  }
+  return llvm::None;
+}
+
+std::string ToolChain::getCompilerRTBasename(const ArgList &Args,
+ StringRef Component,
+ FileType Type) const {
+  const llvm::Triple &TT = getTriple();
   bool IsITANMSVCWindows =
   TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
 
@@ -433,44 +443,35 @@
 Suffix = IsITANMSVCWindows ? ".lib" : ".a";
 break;
   case ToolChain::FT_Shared:
-Suffix = TT.isOSWindows()
- ? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
+Suffix = Triple.isOSWindows()
+ ? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
  : ".so";
 break;
   }
 
-  std::string ArchAndEnv;
-  if (AddArch) {
-StringRef Arch = getArchNameForCompilerRTLib(toolchain, Args);
-const char *Env = TT.isAndroid() ? "-android" : "";
-ArchAndEnv = ("-" + Arch + Env).str();
+  std::string CRTWithoutArch =
+  (Prefix + Twine("clang_rt.") + Component + Suffix).str();
+  if (findInLibraryPath(*this, CRTWithoutArch).hasValue()) {
+return CRTWithoutArch;
   }
-  return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str();
-}
 
-std::string ToolChain::getCompilerRTBasename(const ArgList &Args,
- StringRef Component,
- FileType Type) const {
-  std::string absolutePath = getCompilerRT(Args, Component, Type);
-  return llvm::sys::path::filename(absolutePath).str();
+  StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
+  const char *Env = TT.isAndroid() ? "-android" : "";
+  std::string ArchAndEnv = ("-" + Arch + Env).str();
+
+  return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str();
 }
 
 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
  FileType Type) const {
   // Check for runtime files in the new layout without the architecture first.
-  std::string CRTBasename =
-  buildCompilerRTBasename(*this, Args, Component, Type, /*AddArch=*/false);
-  for (const auto &LibPath : getLibraryPaths()) {
-SmallString<128> P(LibPath);
-llvm::sys::path::append(P, CRTBasename);
-if (getVFS().exists(P))
-  return std::string(P.str());
+  std::string CRTBasename = getCompilerRTBasename(Args, Component, Type);
+  if (auto value = findInLibraryPath(*this, CRTBasename)) {
+return value.getValue();
   }
 
   // Fall back to the old expected compiler-rt name if the new one does n

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 requested review of this revision.
zero9178 added a comment.

I think this change, while functionality fixing the same as my previous diff, 
but also fixing the test failure, does deviate a bit from the original review, 
so I'd like it to be reviewed again if that isn't a problem.


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

https://reviews.llvm.org/D96638

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


[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 326178.
zero9178 added a comment.

Addressed one of the reviewer requests and also uploaded additional files part 
of the patch that were accidently left out.


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

https://reviews.llvm.org/D96638

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/cl-options.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -666,16 +666,16 @@
 // RUN: -target x86_64-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN64 %s
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client-x86_64.lib"
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats-x86_64.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client{{(-x86_64)?}}.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
 // CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target i686-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN32 %s
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client-i386.lib"
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats-i386.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client{{(-i386)?}}.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats{{(-i386)?}}.lib"
 // CHECK-CFI-STATS-WIN32: "--linker-option=/include:___sanitizer_stats_register"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -20,17 +20,17 @@
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-MSVC
 // RUN: %clang -target x86_64-w64-mingw32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN64-MINGW
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-WIN-CXX,CHECK-UNDEFINED-MSVC
-// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib"
-// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
-// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a"
+// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
+// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-x86_64)?}}.lib"
+// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone{{(-x86_64)?}}.a"
 // CHECK-UNDEFINED-WIN-CXX: "--dependent-lib={{[^"]*}}ubsan_standalone_cxx{{[^"]*}}.lib"
 // CHECK-UNDEFINED-MSVC-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked an inline comment as done.
zero9178 added inline comments.



Comment at: clang/lib/Driver/ToolChain.cpp:468-469
   // Check for runtime files in the new layout without the architecture first.
-  std::string CRTBasename =
-  buildCompilerRTBasename(*this, Args, Component, Type, /*AddArch=*/false);
-  for (const auto &LibPath : getLibraryPaths()) {
-SmallString<128> P(LibPath);
-llvm::sys::path::append(P, CRTBasename);
-if (getVFS().exists(P))
-  return std::string(P.str());
+  std::string CRTBasename = getCompilerRTBasename(Args, Component, Type);
+  if (auto value = findInLibraryPath(*this, CRTBasename)) {
+return value.getValue();

rnk wrote:
> This does twice as many stat syscalls as we need. That seems worth 
> optimizing. First, in getCompilerRTBasename, we search the library path, we 
> return a result, and then we search it again here. I think the nicest 
> solution is probably to have one shared implementation that takes a boolean 
> and returns the full path or the basename.
Refactoring the current implementation out of getCompilerRTBasename is 
currently not possible as that would break the BareMetal toolchain as it 
overrides getCompilerRTBasename to build up a different scheme for it's runtime 
libraries. Not calling getCompilerRTBasename is what caused the test failure 
previously.

Unless you mean that I should add an optional boolean operand to 
getCompilerRTBasename that would get either the absolute path if possible or 
always return a relative path? That could work and would change getCompilerRT 
to not go through the library path but to instead check if that path is 
absolute and return if it is already. 






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

https://reviews.llvm.org/D96638

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


[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 326200.
zero9178 added a comment.

Avoid going through the library directories, checking for the existence of a 
runtime library, twice by having getCompilerRTBasename call getCompilerRT and 
simply extract the filename component. To allow other ToolChains to override 
the names of runtime libraries, getCompilerRT now calls the virtual function 
buildCompilerRTBasename. This is used by the BareMetal toolchain.

I chose the name buildCompilerRTBasename as the call chain 
getCompilerRTBasename -> getCompilerRT -> getCompilerRTBasenameImpl would be a 
bit confusing. I am not too attached to the name though if better suggestions 
come along.


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

https://reviews.llvm.org/D96638

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/cl-options.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -666,16 +666,16 @@
 // RUN: -target x86_64-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN64 %s
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client-x86_64.lib"
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats-x86_64.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client{{(-x86_64)?}}.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
 // CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target i686-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN32 %s
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client-i386.lib"
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats-i386.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client{{(-i386)?}}.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats{{(-i386)?}}.lib"
 // CHECK-CFI-STATS-WIN32: "--linker-option=/include:___sanitizer_stats_register"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -20,17 +20,17 @@
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-MSVC
 // RUN: %clang -target x86_64-w64-mingw32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN64-MINGW
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-WIN-CXX,CHECK-UNDEFINED-MSVC
-// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib"
-// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
-// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a"
+// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
+// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ub

[PATCH] D96638: [Driver][Windows] Support per-target runtimes dir layout for profile instr generate

2021-02-24 Thread Markus Böck 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 rG9f1b832331e3: Reland "[Driver][Windows] Support 
per-target runtimes dir layout for profile… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96638

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/cl-options.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -666,16 +666,16 @@
 // RUN: -target x86_64-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN64 %s
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client-x86_64.lib"
-// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats-x86_64.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats_client{{(-x86_64)?}}.lib"
+// CHECK-CFI-STATS-WIN64: "--dependent-lib=clang_rt.stats{{(-x86_64)?}}.lib"
 // CHECK-CFI-STATS-WIN64: "--linker-option=/include:__sanitizer_stats_register"
 
 // RUN: %clang -fsanitize=cfi -fsanitize-stats %s -### -o %t.o 2>&1 \
 // RUN: -target i686-pc-windows \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-CFI-STATS-WIN32 %s
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client-i386.lib"
-// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats-i386.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats_client{{(-i386)?}}.lib"
+// CHECK-CFI-STATS-WIN32: "--dependent-lib=clang_rt.stats{{(-i386)?}}.lib"
 // CHECK-CFI-STATS-WIN32: "--linker-option=/include:___sanitizer_stats_register"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
Index: clang/test/Driver/instrprof-ld.c
===
--- clang/test/Driver/instrprof-ld.c
+++ clang/test/Driver/instrprof-ld.c
@@ -112,7 +112,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-I386 %s
 //
 // CHECK-WINDOWS-I386: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile-i386.lib"
+// CHECK-WINDOWS-I386: "{{.*}}clang_rt.profile{{(-i386)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-pc-win32 -fprofile-instr-generate \
@@ -120,7 +120,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64 %s
 //
 // CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
-// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
+// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile{{(-x86_64)?}}.lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-mingw32 -fprofile-instr-generate -fuse-ld=ld \
@@ -136,7 +136,7 @@
 // RUN: -fprofile-instr-generate 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
 //
-// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
+// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile{{[^"]*}}.lib"
 //
 // RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
 // RUN: -fprofile-instr-generate 2>&1 \
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -20,17 +20,17 @@
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-MSVC
 // RUN: %clang -target x86_64-w64-mingw32 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-WIN64-MINGW
 // RUN: %clang -target x86_64-pc-win32 -fsanitize=undefined -x c++ %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-UNDEFINED-WIN64,CHECK-UNDEFINED-WIN-CXX,CHECK-UNDEFINED-MSVC
-// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone-i386.lib"
-// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
-// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone-x86_64.a"
+// CHECK-UNDEFINED-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
+// CHECK-UNDEFINED-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-x86_64)?}}.lib"
+// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone{{(-x86_64)?}}.a"
 // CHECK-UNDEFINED-WIN-CXX: "--dependent-lib={{[^"]*}}ubsan_standalone_cxx{{[^"]*}}.lib"
 // CHECK-UNDEFINED-MSVC-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|ali

[PATCH] D103749: [clang][driver] Add -foperator-names

2021-06-05 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: MaskRay, thakis, hans.
Herald added a subscriber: dang.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds the command line option -foperator-names which acts as the 
opposite of -fno-operator-names. With this command line option it is possible 
to reenable C++ operator keywords on the command line if -fno-operator-names 
had previously been passed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103749

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cxx-operator-names.cpp


Index: clang/test/Driver/cxx-operator-names.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx-operator-names.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-1 %s
+// CHECK-1: "-fno-operator-names"
+
+// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-2 %s
+// CHECK-2-NOT: "-fno-operator-names"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5655,11 +5655,14 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
 
+  if (Args.hasFlag(options::OPT_fno_operator_names,
+   options::OPT_foperator_names, false))
+CmdArgs.push_back("-fno-operator-names");
+
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
-  Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2217,9 +2217,10 @@
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group, 
Flags<[CC1Option]>;
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
-def fno_operator_names : Flag<["-"], "fno-operator-names">, Group,
-  HelpText<"Do not treat C++ operator name keywords as synonyms for 
operators">,
-  Flags<[CC1Option]>, 
MarshallingInfoNegativeFlag, cplusplus.KeyPath>;
+defm operator_names : BoolFOption<"operator-names",
+  LangOpts<"CXXOperatorNames">, Default,
+  NegFlag,
+  PosFlag>;
 def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, 
Group,
   Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in 
diagnostics">,
   MarshallingInfoFlag>;


Index: clang/test/Driver/cxx-operator-names.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx-operator-names.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-1 %s
+// CHECK-1: "-fno-operator-names"
+
+// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-2 %s
+// CHECK-2-NOT: "-fno-operator-names"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5655,11 +5655,14 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
 
+  if (Args.hasFlag(options::OPT_fno_operator_names,
+   options::OPT_foperator_names, false))
+CmdArgs.push_back("-fno-operator-names");
+
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
-  Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2217,9 +2217,10 @@
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group, Flags<[CC1Option]>;
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group;
-def fno_operator_names : Flag<["-"], "fno-operator-names">, Group,
-  HelpText<"

[PATCH] D103771: [clang][msvc] Define _HAS_STATIC_RTTI to 0, when compiling with -fno-rtti

2021-06-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, thakis, hans.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When using the -fno-rtti option of the GCC style clang++, using typeid results 
in an error. The MSVC STL however kindly provides a define flag called 
_HAS_STATIC_RTTI, which either enables or disables uses of typeid throughout 
the STL. By default, if undefined, it is set to 1, enabling the use of typeid.

With this patch, _HAS_STATIC_RTTI is set to 0 when -fno-rtti is specified. This 
way various headers of the MSVC STL like functional can be consumed without 
compilation failures.



Some context: I was first made aware of this define in this bug report 
regarding twoPhase lookup: 
https://bugs.chromium.org/p/chromium/issues/detail?id=996675
Back then however there was still a usage of typeid left unguarded, which has 
since been fixed in this commit https://github.com/microsoft/STL/issues/340. 
Since that is November 2019, so a rather recent version of MSVC, this will not 
work in versions prior to this fix. 
For compat one could maybe allow `typeid(void)`, but that is beyond the scope 
of this patch either way I think.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103771

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/test/Driver/msvc-static-rtti.cpp


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | 
FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck 
%s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1555,3 +1555,11 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1555,3 +1555,11 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.ll

[PATCH] D103772: [clang-cl] Reenable /Zc:twoPhase by default if targetting MSVC 2017 Update 3 or newer

2021-06-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, hans, thakis.
Herald added a subscriber: dang.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch effectively relands https://reviews.llvm.org/D66394, which back then 
sadly had to be reverted due to build failures. The summary given in the commit 
is already great, but just to summarize: Since MSVC 2017 Update 3 (or 19.11, so 
beyond the 19.14 minimum that clang-cl supports), two phase template parsing 
had been enabled by default. This patch enables two phase lookup by default in 
clang-cl as well, when the MSVC compatibility version is 19.11 or higher.

The patch previously had to be reverted due to issues when executed with the 
GCC style driver and -fno-rtti as can be seen here 
https://bugs.chromium.org/p/chromium/issues/detail?id=996675. 
https://reviews.llvm.org/D103771, which this patch depends on, implements one 
of the resolutions given in the report, by defining _HAS_STATIC_RTTI. For older 
MSVC STL versions that had a missing guard in the functional header, 
-fno-rtti-data may have to passed instead of -fno-rtti, as soon as 
std::function is instantiated, regardless of whether two phase lookup is 
enabled or not.

Depends on https://reviews.llvm.org/D103771


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103772

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -329,13 +329,19 @@
 
 // We recognize -f[no-]delayed-template-parsing.
 // /Zc:twoPhase[-] has the opposite meaning.
-// RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDDEFAULT 
%s
-// DELAYEDDEFAULT: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDON %s
-// RUN: %clang_cl -c /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 -### -- %s 2>&1 | FileCheck 
-check-prefix=OLDDELAYEDDEFAULT %s
+// OLDDELAYEDDEFAULT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1911 -### -- %s 2>&1 | FileCheck 
-check-prefix=NEWDELAYEDDEFAULT %s
+// NEWDELAYEDDEFAULT-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1910 -fdelayed-template-parsing -### -- %s 
2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fdelayed-template-parsing -### -- %s 
2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase- -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase- -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDON %s
 // DELAYEDON: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDOFF %s
-// RUN: %clang_cl -c /Zc:twoPhase -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 -fno-delayed-template-parsing -### -- 
%s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fno-delayed-template-parsing -### -- 
%s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDOFF %s
 // DELAYEDOFF-NOT: "-fdelayed-template-parsing"
 
 // RUN: %clang_cl -c -### /std:c++latest -- %s 2>&1 | FileCheck -check-prefix 
CHECK-LATEST-CHAR8_T %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6127,12 +6127,14 @@
 !IsWindowsMSVC || IsMSVC2015Compatible))
 CmdArgs.push_back("-fno-threadsafe-statics");
 
-  // -fno-delayed-template-parsing is default, except when targeting MSVC.
-  // Many old Windows SDK versions require this to parse.
-  // FIXME: MSVC introduced /Zc:twoPhase- to disable this behavior in their
-  // compiler. We should be able to disable this by default at some point.
+  // -fno-delayed-template-parsing is default, except when targeting MSVC
+  // earlier than MSVC 2017 15.3 (_MSC_VER 1911). Windows SDK versions
+  // 10.0.15063.0 (Creators Update or Redstone 2) and earlier require this to
+  // parse.
+  bool IsMSVCBefore2017Update3 = !MSVT.empty() && MSVT < VersionTuple(19, 11);
   if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
-   options::OPT_fno_delayed_template_parsing, IsWindowsMSVC))
+   options::OPT_fno_delayed_template_parsing,
+   

[PATCH] D103771: [clang][msvc] Define _HAS_STATIC_RTTI to 0, when compiling with -fno-rtti

2021-06-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 350123.
zero9178 added a comment.

Rebase & add comment in source code explaining the purpose of the define


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

https://reviews.llvm.org/D103771

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/test/Driver/msvc-static-rtti.cpp


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | 
FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck 
%s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1539,3 +1539,13 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  // MSVC STL kindly allows removing all usages of typeid by defining
+  // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1539,3 +1539,13 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  // MSVC STL kindly allows removing all usages of typeid by defining
+  // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103772: [clang-cl] Reenable /Zc:twoPhase by default if targetting MSVC 2017 Update 3 or newer

2021-06-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 350125.
zero9178 added a comment.

Rebased onto main


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

https://reviews.llvm.org/D103772

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -329,13 +329,19 @@
 
 // We recognize -f[no-]delayed-template-parsing.
 // /Zc:twoPhase[-] has the opposite meaning.
-// RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDDEFAULT 
%s
-// DELAYEDDEFAULT: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDON %s
-// RUN: %clang_cl -c /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 -### -- %s 2>&1 | FileCheck 
-check-prefix=OLDDELAYEDDEFAULT %s
+// OLDDELAYEDDEFAULT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1911 -### -- %s 2>&1 | FileCheck 
-check-prefix=NEWDELAYEDDEFAULT %s
+// NEWDELAYEDDEFAULT-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1910 -fdelayed-template-parsing -### -- %s 
2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fdelayed-template-parsing -### -- %s 
2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase- -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase- -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDON %s
 // DELAYEDON: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDOFF %s
-// RUN: %clang_cl -c /Zc:twoPhase -### -- %s 2>&1 | FileCheck 
-check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 -fno-delayed-template-parsing -### -- 
%s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fno-delayed-template-parsing -### -- 
%s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase -### -- %s 2>&1 | 
FileCheck -check-prefix=DELAYEDOFF %s
 // DELAYEDOFF-NOT: "-fdelayed-template-parsing"
 
 // RUN: %clang_cl -c -### /std:c++latest -- %s 2>&1 | FileCheck -check-prefix 
CHECK-LATEST-CHAR8_T %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6124,12 +6124,14 @@
 !IsWindowsMSVC || IsMSVC2015Compatible))
 CmdArgs.push_back("-fno-threadsafe-statics");
 
-  // -fno-delayed-template-parsing is default, except when targeting MSVC.
-  // Many old Windows SDK versions require this to parse.
-  // FIXME: MSVC introduced /Zc:twoPhase- to disable this behavior in their
-  // compiler. We should be able to disable this by default at some point.
+  // -fno-delayed-template-parsing is default, except when targeting MSVC
+  // earlier than MSVC 2017 15.3 (_MSC_VER 1911). Windows SDK versions
+  // 10.0.15063.0 (Creators Update or Redstone 2) and earlier require this to
+  // parse.
+  bool IsMSVCBefore2017Update3 = !MSVT.empty() && MSVT < VersionTuple(19, 11);
   if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
-   options::OPT_fno_delayed_template_parsing, IsWindowsMSVC))
+   options::OPT_fno_delayed_template_parsing,
+   IsMSVCBefore2017Update3))
 CmdArgs.push_back("-fdelayed-template-parsing");
 
   // -fgnu-keywords default varies depending on language; only pass if
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6008,10 +6008,10 @@
 def _SLASH_Zc_trigraphs_off : CLFlag<"Zc:trigraphs-">,
   HelpText<"Disable trigraphs (default)">, Alias;
 def _SLASH_Zc_twoPhase : CLFlag<"Zc:twoPhase">,
-  HelpText<"Enable two-phase name lookup in templates">,
+  HelpText<"Enable two-phase name lookup in templates (default)">,
   Alias;
 def _SLASH_Zc_twoPhase_ : CLFlag<"Zc:twoPhase-">,
-  HelpText<"Disable two-phase name lookup in templates (default)">,
+  HelpText<"Disable two-phase name lookup in templates">,
   Alias;
 def _SLASH_Z7 : CLFlag<"Z7">,
   HelpText<"Enable CodeView debug information in object files">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
 Windows Support
 ---
 
+- clang-cl now def

[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, thakis, hans, mstorsjo.
Herald added a subscriber: dang.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds the command line options /permissive and /permissive- to 
clang-cl. These flags are used in MSVC to enable various /Zc language 
conformance options at once. In particular, /permissive is used to enable the 
various non standard behaviour of MSVC, while /permissive- is the opposite.

When either of two command lines are specified they are simply expanded to the 
various underlying /Zc options. In particular when /permissive is passed it 
currently expands to:

- /Zc:twoPhase- (disable two phase lookup)
- -fno-operator-names (disable C++ operator keywords)

/permissive- expands to the opposites of these flags + /Zc:strictStrings 
(/Zc:strictStrings- does not currently exist). In the future, if any more MSVC 
workarounds are ever added they can easily be added to the expansion. One is 
also able to override settings done by permissive. Specifying /permissive- 
/Zc:twoPhase- will apply the settings from permissive minus, but disables two 
phase lookup.

Motivation for this patch was mainly parity with MSVC as well as compatibility 
with Windows SDK headers. The /permissive page from MSVC documents various 
workarounds that have to be done for the Windows SDK headers [1], when MSVC is 
used with /permissive-. In these, Microsoft often recommends simply compiling 
with /permissive for the specified source files. Since some of these also apply 
to clang-cl (which acts like /permissive- by default mostly), and some are 
currently implemented as "hacks" within clang that I'd like to remove, adding 
/permissive and /permissive- to be in full parity with MSVC and Microsofts 
documentation made sense to me.

[1] 
https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160#windows-header-issues

Depends on https://reviews.llvm.org/D103749 for the -foperator-names CLI option


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103773

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-permissive.c


Index: clang/test/Driver/cl-permissive.c
===
--- /dev/null
+++ clang/test/Driver/cl-permissive.c
@@ -0,0 +1,17 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// RUN: %clang_cl /permissive -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE %s
+// PERMISSIVE: "-fno-operator-names"
+// PERMISSIVE: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS %s
+// PERMISSIVE-MINUS-NOT: "-fno-operator-names"
+// PERMISSIVE-MINUS-NOT: "-fdelayed-template-parsing"
+
+// The switches set by permissive may then still be manually enabled or 
disabled
+// RUN: %clang_cl /permissive /Zc:twoPhase -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-OVERWRITE %s
+// PERMISSIVE-OVERWRITE: "-fno-operator-names"
+// PERMISSIVE-OVERWRITE-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS-OVERWRITE %s
+// PERMISSIVE-MINUS-OVERWRITE-NOT: "-fno-operator-names"
+// PERMISSIVE-MINUS-OVERWRITE: "-fdelayed-template-parsing"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1489,6 +1489,20 @@
   DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
 }
 
+static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL,
+const OptTable &Opts) {
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
+  // There is currently no /Zc:strictStrings- in clang-cl
+}
+
+static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL,
+ const OptTable &Opts) {
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_strictStrings));
+}
+
 llvm::opt::DerivedArgList *
 MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
  StringRef BoundArch,
@@ -1531,6 +1545,12 @@
 } else if (A->getOption().matches(options::OPT_D)) {
   // Translate -Dfoo#bar into -Dfoo=bar.
   TranslateDArg(A, *DAL, Opts);
+} else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
+  // Expand /permissive
+  TranslatePermissive(A, *DAL, Opts);
+} else if (A->getOption().matche

[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-07 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

> I think adding /permissive- to make things more conforming is great. The docs 
> say "Starting in Visual Studio 2019 version 16.8, the /std:c++latest option 
> implicitly sets the /permissive- option." so maybe we should do that too 
> (doesn't have to be in this patch).

That's a very good idea, didn't think of that. Should definitely be done.

> Since things seem to mostly work without /permissive (without the -) I'm not 
> sure if we should add support for that. It'll make clang-cl less conforming, 
> and in practice things seem to be fine as-is (…right?). Part of the reason 
> why /permissive- doesn't expand to more flags in clang-cl 
> (https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160
>  lists a whole bunch more) I imagine is because clang-cl already has the 
> stricter defaults there – which it can do because it's a newer compiler that 
> needs to support less old code.

clang-cl definitely has stricter defaults, and I think it should absolutely 
stay that way. Whether more of the /Zc: conformance options should be added, I 
don't know. But I think /permissive should be there to group them, at least for 
`/Zc:twoPhase`- and `-fno-operator-names`.

Regarding the later, there is actually no equivalent flag for the GNU style 
`-fno-operator-names` in clang-cl currently. In MSVC it's done via /permissive 
and /permissive-. The C++ operator keywords are one of the reason I wrote this 
patch. There is a Windows sdk header, Query.h, which due to a workaround inside 
of clang-cl can be included, but not fully used. It includes a struct that 
looks like the following (from Microsoft Docs):

  c
  struct tagRESTRICTION
  {
   ULONG rt;
   ULONG weight;
   /* [switch_is][switch_type] */ union _URes
   {
   /* [case()] */ NODERESTRICTION ar;
   /* [case()] */ NODERESTRICTION or;  // error C2059: syntax error: 
'||'
   /* [case()] */ NODERESTRICTION pxr;
   /* [case()] */ VECTORRESTRICTION vr;
   /* [case()] */ NOTRESTRICTION nr;
   /* [case()] */ CONTENTRESTRICTION cr;
   /* [case()] */ NATLANGUAGERESTRICTION nlr;
   /* [case()] */ PROPERTYRESTRICTION pr;
   /* [default] */  /* Empty union arm */
   } res;
  };

It includes a field called `or`. A short program that simply has `#include 
` will still compile with clang-cl, but that is due to a sort of 
"hack" here: 
https://github.com/llvm/llvm-project/blob/4f8bc7caf4e5fcc1620b3fd4980ec8d671e9345b/clang/lib/Lex/Preprocessor.cpp#L720.
 Basically any C++ operator keywords inside a system header is treated as 
identifier instead. This has caused quite a lot of issues as can be seen here:
https://bugs.llvm.org/show_bug.cgi?id=42427 and here 
https://github.com/nlohmann/json/issues/1818. It has also caused issues in 
libc++ which contains `and` and `or` in headers, and marks them as system 
header using `#pragma GCC system_header`. 
Additionally, in the Query.h example, if one where to try to access the `or` 
field in the above struct, one will instead get an error, as `or` is treated as 
a keyword in the source file. The MSVC documented way of fixing this would be 
/permissive. 
To be fully transparent however, in the header there is a macro called 
`QUERY_H_RESTRICTION_PERMISSIVE` which allows one to rename the field. This is 
sadly undocumented anywhere else but the header tho.

My intentions with /permissive were to be more consistent with MSVC as well as 
the advice given for the various SDK headers and make it possible to remove the 
above hack. I was going to put that into an additional patch however, as that 
is probably worth a discussion in itself since it's a possibly breaking change 
for users of Query.h.

> Details:
> docs say "You can pass specific /Zc options after /permissive- on the command 
> line to override this behavior" – does that work with this approach? We 
> should have a test for that

The test I added contains tests overwriting `/Zc:twoPhase` for both 
`/permissive` and `/permissive-` at line 11 on wards. I could add more tests if 
needed however.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103773

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


[PATCH] D103772: [clang-cl] Reenable /Zc:twoPhase by default if targetting MSVC 2017 Update 3 or newer

2021-06-07 Thread Markus Böck via Phabricator via cfe-commits
zero9178 abandoned this revision.
zero9178 added a comment.

Thanks for the info, seems like I was mislead after testing it again.


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

https://reviews.llvm.org/D103772

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


[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-07 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

I shall do that.

I do have commit access, but thanks for asking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103773

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


[PATCH] D103749: [clang][driver] Add -foperator-names

2021-06-10 Thread Markus Böck 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 rG9833b57981c4: [clang][driver] Add -foperator-names (authored 
by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103749

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cxx-operator-names.cpp


Index: clang/test/Driver/cxx-operator-names.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx-operator-names.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-1 %s
+// CHECK-1: "-fno-operator-names"
+
+// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-2 %s
+// CHECK-2-NOT: "-fno-operator-names"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5654,11 +5654,14 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
 
+  if (Args.hasFlag(options::OPT_fno_operator_names,
+   options::OPT_foperator_names, false))
+CmdArgs.push_back("-fno-operator-names");
+
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
-  Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2221,9 +2221,10 @@
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group, 
Flags<[CC1Option]>;
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
-def fno_operator_names : Flag<["-"], "fno-operator-names">, Group,
-  HelpText<"Do not treat C++ operator name keywords as synonyms for 
operators">,
-  Flags<[CC1Option]>, 
MarshallingInfoNegativeFlag, cplusplus.KeyPath>;
+defm operator_names : BoolFOption<"operator-names",
+  LangOpts<"CXXOperatorNames">, Default,
+  NegFlag,
+  PosFlag>;
 def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, 
Group,
   Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in 
diagnostics">,
   MarshallingInfoFlag>;


Index: clang/test/Driver/cxx-operator-names.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx-operator-names.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-1 %s
+// CHECK-1: "-fno-operator-names"
+
+// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-2 %s
+// CHECK-2-NOT: "-fno-operator-names"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5654,11 +5654,14 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
 
+  if (Args.hasFlag(options::OPT_fno_operator_names,
+   options::OPT_foperator_names, false))
+CmdArgs.push_back("-fno-operator-names");
+
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
-  Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2221,9 +2221,10 @@
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group, Flags<[CC1Option]>;
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group;
-def fno_operator_names : Flag<["-"], "fno-operator-names">, Group,
-  HelpText<"Do not treat C++ operator name keywords as synonyms for operators">,
-  Flags<[CC1Option]>, MarshallingInfoNegativeFlag, cplusplus.KeyPath>;
+defm operator_names : BoolFOption<"operator-names",
+  Lan

[PATCH] D103771: [clang][msvc] Define _HAS_STATIC_RTTI to 0, when compiling with -fno-rtti

2021-06-10 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG936d6756ccfb: [clang][msvc] Define _HAS_STATIC_RTTI to 0, 
when compiling with -fno-rtti (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103771

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/test/Driver/msvc-static-rtti.cpp


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | 
FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck 
%s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1573,3 +1573,13 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  // MSVC STL kindly allows removing all usages of typeid by defining
+  // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}


Index: clang/test/Driver/msvc-static-rtti.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-static-rtti.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF
+// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF-NOT
+
+// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0
+// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0
Index: clang/lib/Driver/ToolChains/MSVC.h
===
--- clang/lib/Driver/ToolChains/MSVC.h
+++ clang/lib/Driver/ToolChains/MSVC.h
@@ -122,6 +122,11 @@
 
   bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1573,3 +1573,13 @@
 
   return DAL;
 }
+
+void MSVCToolChain::addClangTargetOptions(
+const ArgList &DriverArgs, ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  // MSVC STL kindly allows removing all usages of typeid by defining
+  // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
+  if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
+/*Default=*/false))
+CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-10 Thread Markus Böck 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 rGc70b0e808da8: [clang-cl] Add /permissive and /permissive- 
(authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103773

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-permissive.c


Index: clang/test/Driver/cl-permissive.c
===
--- /dev/null
+++ clang/test/Driver/cl-permissive.c
@@ -0,0 +1,17 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// RUN: %clang_cl /permissive -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE %s
+// PERMISSIVE: "-fno-operator-names"
+// PERMISSIVE: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS %s
+// PERMISSIVE-MINUS-NOT: "-fno-operator-names"
+// PERMISSIVE-MINUS-NOT: "-fdelayed-template-parsing"
+
+// The switches set by permissive may then still be manually enabled or 
disabled
+// RUN: %clang_cl /permissive /Zc:twoPhase -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-OVERWRITE %s
+// PERMISSIVE-OVERWRITE: "-fno-operator-names"
+// PERMISSIVE-OVERWRITE-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS-OVERWRITE %s
+// PERMISSIVE-MINUS-OVERWRITE-NOT: "-fno-operator-names"
+// PERMISSIVE-MINUS-OVERWRITE: "-fdelayed-template-parsing"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1523,6 +1523,20 @@
   DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
 }
 
+static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL,
+const OptTable &Opts) {
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
+  // There is currently no /Zc:strictStrings- in clang-cl
+}
+
+static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL,
+ const OptTable &Opts) {
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names));
+  DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_strictStrings));
+}
+
 llvm::opt::DerivedArgList *
 MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
  StringRef BoundArch,
@@ -1565,6 +1579,12 @@
 } else if (A->getOption().matches(options::OPT_D)) {
   // Translate -Dfoo#bar into -Dfoo=bar.
   TranslateDArg(A, *DAL, Opts);
+} else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
+  // Expand /permissive
+  TranslatePermissive(A, *DAL, Opts);
+} else if (A->getOption().matches(options::OPT__SLASH_permissive_)) {
+  // Expand /permissive-
+  TranslatePermissiveMinus(A, *DAL, Opts);
 } else if (OFK != Action::OFK_HIP) {
   // HIP Toolchain translates input args by itself.
   DAL->append(A);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6099,6 +6099,10 @@
   HelpText<"Deprecated (set output file name); use /Fe or /Fe">,
   MetaVarName<"">;
 def _SLASH_P : CLFlag<"P">, HelpText<"Preprocess to file">;
+def _SLASH_permissive : CLFlag<"permissive">,
+  HelpText<"Enable some non conforming code to compile">;
+def _SLASH_permissive_ : CLFlag<"permissive-">,
+  HelpText<"Disable non conforming code from compiling (default)">;
 def _SLASH_Tc : CLCompileJoinedOrSeparate<"Tc">,
   HelpText<"Treat  as C source file">, MetaVarName<"">;
 def _SLASH_TC : CLCompileFlag<"TC">, HelpText<"Treat all source files as C">;
@@ -6180,7 +6184,6 @@
 def _SLASH_JMC : CLIgnoredFlag<"JMC">;
 def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">;
 def _SLASH_nologo : CLIgnoredFlag<"nologo">;
-def _SLASH_permissive_ : CLIgnoredFlag<"permissive-">;
 def _SLASH_RTC : CLIgnoredJoined<"RTC">;
 def _SLASH_sdl : CLIgnoredFlag<"sdl">;
 def _SLASH_sdl_ : CLIgnoredFlag<"sdl-">;


Index: clang/test/Driver/cl-permissive.c
===
--- /dev/null
+++ clang/test/Driver/cl-permissive.c
@@ -0,0 +1,17 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// RUN: %clang_cl /permissive -### -- %s 2>&1 | FileCheck -check-prefix=PERMISSIVE %s
+// PERMISSIVE: "-fno

[PATCH] D104182: [clang][NFC] Add IsAnyDestructorNoReturn field to CXXRecord instead of calculating it on demand

2021-06-12 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: davrec, bruno, rsmith, aaron.ballman.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch addresses a performance issue I noticed when using clang-12 to 
compile projects of mine. Even though the files weren't too large (around 1k 
cpp), the compiler was taking more than a minute to compile the source file, 
much longer than either GCC or MSVC.

Using a profiler it turned out the issue was the `isAnyDestructorNoReturn` 
function in CXXRecordDecl:
F17356915: image.png 

In particular it being recursive, recalculating the property for every 
invocation, for every field and base class. This showed up in tracebacks in the 
profiler as follows:
F17356931: image.png 

This patch instead adds `IsAnyDestructorNoReturn` as a Field to the data inside 
of CXXRecord and updates when a new base class, destructor, or record field 
member is added.

After this patch the problematic file of mine went from a compile time of 81s, 
down to 12s. The hotspots now look more normal as well:
F17356944: image.png 

The patch itself should not change any functionality, just improve performance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104182

Files:
  clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/DeclCXX.cpp


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -108,7 +108,8 @@
   ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
   ImplicitCopyAssignmentHasConstParam(true),
   HasDeclaredCopyConstructorWithConstParam(false),
-  HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
+  HasDeclaredCopyAssignmentWithConstParam(false),
+  IsAnyDestructorNoReturn(false), IsLambda(false),
   IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
   HasODRHash(false), Definition(D) {}
 
@@ -424,6 +425,9 @@
 if (!BaseClassDecl->hasIrrelevantDestructor())
   data().HasIrrelevantDestructor = false;
 
+if (BaseClassDecl->isAnyDestructorNoReturn())
+  data().IsAnyDestructorNoReturn = true;
+
 // C++11 [class.copy]p18:
 //   The implicitly-declared copy assignment operator for a class X will
 //   have the form 'X& X::operator=(const X&)' if each direct base class B
@@ -836,6 +840,9 @@
   data().HasTrivialSpecialMembers &= ~SMF_Destructor;
   data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
 }
+
+if (DD->isNoReturn())
+  data().IsAnyDestructorNoReturn = true;
   }
 
   // Handle member functions.
@@ -1233,6 +1240,8 @@
   data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
 if (!FieldRec->hasIrrelevantDestructor())
   data().HasIrrelevantDestructor = false;
+if (FieldRec->isAnyDestructorNoReturn())
+  data().IsAnyDestructorNoReturn = true;
 if (FieldRec->hasObjectMember())
   setHasObjectMember(true);
 if (FieldRec->hasVolatileMember())
@@ -1888,29 +1897,6 @@
   return R.empty() ? nullptr : dyn_cast(R.front());
 }
 
-bool CXXRecordDecl::isAnyDestructorNoReturn() const {
-  // Destructor is noreturn.
-  if (const CXXDestructorDecl *Destructor = getDestructor())
-if (Destructor->isNoReturn())
-  return true;
-
-  // Check base classes destructor for noreturn.
-  for (const auto &Base : bases())
-if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl())
-  if (RD->isAnyDestructorNoReturn())
-return true;
-
-  // Check fields for noreturn.
-  for (const auto *Field : fields())
-if (const CXXRecordDecl *RD =
-Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl())
-  if (RD->isAnyDestructorNoReturn())
-return true;
-
-  // All destructors are not noreturn.
-  return false;
-}
-
 static bool isDeclContextInNamespace(const DeclContext *DC) {
   while (!DC->isTranslationUnit()) {
 if (DC->isNamespace())
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1480,7 +1480,7 @@
 
   /// Returns true if the class destructor, or any implicitly invoked
   /// destructors are marked noreturn.
-  bool isAnyDestructorNoReturn() const;
+  bool isAnyDestructorNoReturn() const { return 
data().IsAnyDestructorNoReturn; }
 
   /// If the class is a local class [class.local], returns
   /// the enclosing function declaration.
Index: clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
===
--- clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ clang/include/clang/A

[PATCH] D104182: [clang][NFC] Add IsAnyDestructorNoReturn field to CXXRecord instead of calculating it on demand

2021-06-12 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D104182#2815397 , @davrec wrote:

> Was this performance hit when using the static analyzer?  A quick search 
> suggests `isAnyDestructorNoReturn()` is only called within the analyzer, 
> whereas comparable CXXRecordDecl methods whose results are stored 
> (`hasIrrelevantDestructor()` etc.) seem to be called somewhere by Sema.
>
> So non-users of the analyzer would not benefit from this change, and will 
> incur a slight cost, IIUC.  Is that cost remotely noticeable?  Probably not, 
> but a quick test along those lines would be helpful.
>
> All in all this is probably good and advisable.

The only place where it is called in the static analyzer is in 
ExprEngineCXX.cpp:650. I was doing a normal compilation of a C++ file of mine, 
and they were coming from Analysis/CFG.cpp:1871 in `addAutomaticObjDtors` as 
well as CFG.cpp:4836 in `VisitCXXBindTemporaryForDtors`. So depending on the 
contents of the users C++ file it could improve their compilation speed as 
well. I suspect that in my case it was producing such a deep stacktrace due to 
a template class that is using a lot of layers of inheritance to preserve 
triviallity of constructors and more, tho that is just a guess. Nevertheless 
I'd wager it will more than likely improve the compile time for some other 
people as well.

As another test I just compared the compilation of X86ISelLowering.cpp from 
LLVM using clang-cl trunk, with and without this patch and could not measure 
any difference but margin of error. So it's definitely not guaranteed to be an 
improvement, but least isn't any worse.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104182

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


[PATCH] D104182: [clang][NFC] Add IsAnyDestructorNoReturn field to CXXRecord instead of calculating it on demand

2021-06-13 Thread Markus Böck 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 rG7ff3a89a7b94: [clang][NFC] Add IsAnyDestructorNoReturn field 
to CXXRecord instead of… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104182

Files:
  clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/DeclCXX.cpp


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -108,7 +108,8 @@
   ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
   ImplicitCopyAssignmentHasConstParam(true),
   HasDeclaredCopyConstructorWithConstParam(false),
-  HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
+  HasDeclaredCopyAssignmentWithConstParam(false),
+  IsAnyDestructorNoReturn(false), IsLambda(false),
   IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
   HasODRHash(false), Definition(D) {}
 
@@ -424,6 +425,9 @@
 if (!BaseClassDecl->hasIrrelevantDestructor())
   data().HasIrrelevantDestructor = false;
 
+if (BaseClassDecl->isAnyDestructorNoReturn())
+  data().IsAnyDestructorNoReturn = true;
+
 // C++11 [class.copy]p18:
 //   The implicitly-declared copy assignment operator for a class X will
 //   have the form 'X& X::operator=(const X&)' if each direct base class B
@@ -836,6 +840,9 @@
   data().HasTrivialSpecialMembers &= ~SMF_Destructor;
   data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
 }
+
+if (DD->isNoReturn())
+  data().IsAnyDestructorNoReturn = true;
   }
 
   // Handle member functions.
@@ -1233,6 +1240,8 @@
   data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
 if (!FieldRec->hasIrrelevantDestructor())
   data().HasIrrelevantDestructor = false;
+if (FieldRec->isAnyDestructorNoReturn())
+  data().IsAnyDestructorNoReturn = true;
 if (FieldRec->hasObjectMember())
   setHasObjectMember(true);
 if (FieldRec->hasVolatileMember())
@@ -1888,29 +1897,6 @@
   return R.empty() ? nullptr : dyn_cast(R.front());
 }
 
-bool CXXRecordDecl::isAnyDestructorNoReturn() const {
-  // Destructor is noreturn.
-  if (const CXXDestructorDecl *Destructor = getDestructor())
-if (Destructor->isNoReturn())
-  return true;
-
-  // Check base classes destructor for noreturn.
-  for (const auto &Base : bases())
-if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl())
-  if (RD->isAnyDestructorNoReturn())
-return true;
-
-  // Check fields for noreturn.
-  for (const auto *Field : fields())
-if (const CXXRecordDecl *RD =
-Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl())
-  if (RD->isAnyDestructorNoReturn())
-return true;
-
-  // All destructors are not noreturn.
-  return false;
-}
-
 static bool isDeclContextInNamespace(const DeclContext *DC) {
   while (!DC->isTranslationUnit()) {
 if (DC->isNamespace())
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1480,7 +1480,7 @@
 
   /// Returns true if the class destructor, or any implicitly invoked
   /// destructors are marked noreturn.
-  bool isAnyDestructorNoReturn() const;
+  bool isAnyDestructorNoReturn() const { return 
data().IsAnyDestructorNoReturn; }
 
   /// If the class is a local class [class.local], returns
   /// the enclosing function declaration.
Index: clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
===
--- clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -242,4 +242,8 @@
 /// const-qualified reference parameter or a non-reference parameter.
 FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR)
 
+/// Whether the destructor is no-return. Either explicitly, or if any
+/// base classes or fields have a no-return destructor
+FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE)
+
 #undef FIELD


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -108,7 +108,8 @@
   ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
   ImplicitCopyAssignmentHasConstParam(true),
   HasDeclaredCopyConstructorWithConstParam(false),
-  HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
+  HasDeclaredCopyAssignmentWithConstParam(false),
+  IsAnyDestructorNoReturn(false), IsLambda(false),
   IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
   HasOD

[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-15 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added inline comments.



Comment at: clang/test/Driver/cl-permissive.c:15
+// PERMISSIVE-OVERWRITE-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS-OVERWRITE %s
+// PERMISSIVE-MINUS-OVERWRITE-NOT: "-fno-operator-names"

aganea wrote:
> Hello @zero9178 !
> After this patch, the following fails:
> `// RUN: %clang_cl /permissive- -- %s`
> generates:
> `error: error reading '/Zc:strictStrings'`
> Because `/Zc:strictStrings` isn't correctly expanded to 
> `-Werror=c++11-compat-deprecated-writable-strings` as it should, but it is 
> passed as-is to cc1. You can put a breakpoint here: 
> https://github.com/llvm/llvm-project/blob/fc018ebb608ee0c1239b405460e49f1835ab6175/clang/lib/Driver/ToolChains/Clang.cpp#L5374
>  and observe before/after this line.
> Would you possibly have a chance to take a look please?
Absolutely! I will take a look as soon as possible which will be on the 
weekend. Meanwhile feel free to either revert the commit or remove the 
expansion to /Zc:strictStrings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103773

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


[PATCH] D103773: [clang-cl] Add /permissive and /permissive-

2021-06-19 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked an inline comment as done.
zero9178 added inline comments.



Comment at: clang/test/Driver/cl-permissive.c:15
+// PERMISSIVE-OVERWRITE-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl /permissive- /Zc:twoPhase- -### -- %s 2>&1 | FileCheck 
-check-prefix=PERMISSIVE-MINUS-OVERWRITE %s
+// PERMISSIVE-MINUS-OVERWRITE-NOT: "-fno-operator-names"

zero9178 wrote:
> aganea wrote:
> > Hello @zero9178 !
> > After this patch, the following fails:
> > `// RUN: %clang_cl /permissive- -- %s`
> > generates:
> > `error: error reading '/Zc:strictStrings'`
> > Because `/Zc:strictStrings` isn't correctly expanded to 
> > `-Werror=c++11-compat-deprecated-writable-strings` as it should, but it is 
> > passed as-is to cc1. You can put a breakpoint here: 
> > https://github.com/llvm/llvm-project/blob/fc018ebb608ee0c1239b405460e49f1835ab6175/clang/lib/Driver/ToolChains/Clang.cpp#L5374
> >  and observe before/after this line.
> > Would you possibly have a chance to take a look please?
> Absolutely! I will take a look as soon as possible which will be on the 
> weekend. Meanwhile feel free to either revert the commit or remove the 
> expansion to /Zc:strictStrings
I have removed the expansion to strictStrings in 
https://reviews.llvm.org/rGc9889c44ec5a4054833457c813e155f284703ef4. Apparently 
when AdAllArgs is called it does not correctly render it as I thought it would. 
The fix isn't very obvious to me, and my time is sadly limited. In hindsight it 
is also probably not a good idea to add strictStrings until strictStrings 
exists/is neeeded. 

Hope this helps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103773

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


[PATCH] D107893: [clang] [MinGW] Consider the per-target libc++ include directory too

2021-08-13 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

Any chance this patch could be backported onto the LLVM 13 branch? I have been 
using a per target runtime builds for a few versions now but the functionality 
has regressed in LLVM 13, which would force me back into a normal single target 
layout.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107893

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


[PATCH] D107893: [clang] [MinGW] Consider the per-target libc++ include directory too

2021-08-13 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D107893#2944193 , @mstorsjo wrote:

> In D107893#2943679 , @zero9178 
> wrote:
>
>> Any chance this patch could be backported onto the LLVM 13 branch? I have 
>> been using a per target runtime builds for a few versions now but the 
>> functionality has regressed in LLVM 13, which would force me back into a 
>> normal single target layout.
>
> I presume this should be pretty trivial to backport yes - can you file a bug 
> about it in bugzilla, CC @tstellar and mark it as blocking the 13.0.0 release 
> bug?
>
> In which way was this a regression - I guess clang didn't change here - did 
> libcxx start installing the `__config_site` file differently during this 
> release?

Since this release libc++ splits what was previously the `__config` header into 
`__config_site` and `__config`, where `__config_site` contains all the defines 
set at configure time by CMake and gets included by `__config`. Without this 
patch the include path to `__config_site`s directory is missing in per target 
builds and therefore including any file of libc++ causes a compilation error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107893

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


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-15 Thread Markus Böck 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 rGaf2796c76d2f: [test] Add ability to get error messages from 
CMake for errc substitution (authored by zero9178).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D98278?vs=330653&id=330769#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

Files:
  clang/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  lld/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  llvm/CMakeLists.txt
  llvm/cmake/modules/GetErrcMessages.cmake
  llvm/test/lit.site.cfg.py.in
  llvm/utils/lit/lit/llvm/config.py

Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -11,6 +11,7 @@
 from lit.llvm.subst import ToolSubst
 
 lit_path_displayed = False
+python_errc_displayed = False
 
 class LLVMConfig(object):
 
@@ -356,19 +357,24 @@
 return True
 
 def add_err_msg_substitutions(self):
-host_cxx = getattr(self.config, 'host_cxx', '')
-# On Windows, python's os.strerror() does not emit the same spelling as
-# the C++ std::error_code.  As a workaround, hardcode the Windows error
-# message.
-if (sys.platform == 'win32' and 'MSYS' not in host_cxx):
+# Python's strerror may not supply the same message
+# as C++ std::error_code. One example of such a platform is
+# Visual Studio. errc_messages may be supplied which contains the error
+# messages for ENOENT, EISDIR, EINVAL and EACCES as a semi colon
+# separated string. LLVM testsuites can use get_errc_messages in cmake
+# to automatically get the messages and pass them into lit.
+errc_messages = getattr(self.config, 'errc_messages', '')
+if len(errc_messages) != 0:
+(errc_enoent, errc_eisdir,
+ errc_einval, errc_eacces) = errc_messages.split(';')
 self.config.substitutions.append(
-('%errc_ENOENT', '\'no such file or directory\''))
+('%errc_ENOENT', '\'' + errc_enoent + '\''))
 self.config.substitutions.append(
-('%errc_EISDIR', '\'is a directory\''))
+('%errc_EISDIR', '\'' + errc_eisdir + '\''))
 self.config.substitutions.append(
-('%errc_EINVAL', '\'invalid argument\''))
+('%errc_EINVAL', '\'' + errc_einval + '\''))
 self.config.substitutions.append(
-('%errc_EACCES', '\'permission denied\''))
+('%errc_EACCES', '\'' + errc_eacces + '\''))
 else:
 self.config.substitutions.append(
 ('%errc_ENOENT', '\'' + os.strerror(errno.ENOENT) + '\''))
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -12,6 +12,7 @@
 config.llvm_shlib_ext = "@SHLIBEXT@"
 config.llvm_exe_ext = "@EXEEXT@"
 config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@")
+config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.gold_executable = "@GOLD_EXECUTABLE@"
 config.ld64_executable = "@LD64_EXECUTABLE@"
Index: llvm/cmake/modules/GetErrcMessages.cmake
===
--- /dev/null
+++ llvm/cmake/modules/GetErrcMessages.cmake
@@ -0,0 +1,39 @@
+
+# This function returns the messages of various POSIX error codes as they are returned by std::error_code.
+# The purpose of this function is to supply those error messages to llvm-lit using the errc_messages config
+# Currently supplied and needed error codes: ENOENT, EISDIR, EINVAL and EACCES
+# Messages are semi colon separated
+# Keep amount, order and tested error codes in sync with llvm/utils/lit/lit/llvm/config.py
+function(get_errc_messages outvar)
+
+set(errc_test_code ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/getErrc.cpp)
+
+file(WRITE ${errc_test_code} "
+#include 
+#include 
+#include 
+#include 
+
+std::string getMessageFor(int err) {
+return std::make_error_code(static_cast(err)).message();
+}
+
+int main() {
+std::cout << getMessageFor(ENOENT) << ';' << getMessageFor(EISDIR);
+std::cout << ';' << getMessageFor(EINVAL) << ';' << getMessageFor(EACCES);
+}
+")
+
+try_run(errc_exit_code
+errc_compiled
+${CMAKE_BINARY_DIR}
+${errc_test_code}
+RUN_OUTPUT_VARIABLE errc_result
+COMPILE_OUTPUT_VARIABLE errc_compile_errors)
+if (errc_compiled)
+set(${outvar} ${errc_result} PARENT_SCOPE

[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-25 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, CaseyCarter, hans, thakis.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since VS 2022 17.1 MSVC predefines _MSVC_EXECUTION_CHARACTER_SET to inform the 
users of the execution character set defined at compile time. The value the 
macro expands to is a Windows Code Page Identifier which are documented here: 
https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers

As clang currently only supports UTF-8 it is defined as 65001. If clang-cl were 
to support a different execution character set in the future we'd have to 
change the value.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114576

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-execution-character-set.c


Index: clang/test/Driver/cl-execution-character-set.c
===
--- /dev/null
+++ clang/test/Driver/cl-execution-character-set.c
@@ -0,0 +1,7 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// Only UTF-8 is currently supported, which has the Windows Code
+// Page Identifier 65001
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s
+// CHECK: -D_MSVC_EXECUTION_CHARACTER_SET=65001
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7327,6 +7327,14 @@
 CmdArgs.push_back("--dependent-lib=oldnames");
   }
 
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  CmdArgs.push_back("-D_MSVC_EXECUTION_CHARACTER_SET=65001");
+
   if (Arg *ShowIncludes =
   Args.getLastArg(options::OPT__SLASH_showIncludes,
   options::OPT__SLASH_showIncludes_user)) {


Index: clang/test/Driver/cl-execution-character-set.c
===
--- /dev/null
+++ clang/test/Driver/cl-execution-character-set.c
@@ -0,0 +1,7 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// Only UTF-8 is currently supported, which has the Windows Code
+// Page Identifier 65001
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s
+// CHECK: -D_MSVC_EXECUTION_CHARACTER_SET=65001
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7327,6 +7327,14 @@
 CmdArgs.push_back("--dependent-lib=oldnames");
   }
 
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  CmdArgs.push_back("-D_MSVC_EXECUTION_CHARACTER_SET=65001");
+
   if (Arg *ShowIncludes =
   Args.getLastArg(options::OPT__SLASH_showIncludes,
   options::OPT__SLASH_showIncludes_user)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-25 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 389698.
zero9178 added a comment.

Enable the macro for all MSVC targets, regardless of driver in use.


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

https://reviews.llvm.org/D114576

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-execution-character-set.c


Index: clang/test/Driver/cl-execution-character-set.c
===
--- /dev/null
+++ clang/test/Driver/cl-execution-character-set.c
@@ -0,0 +1,14 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// Only UTF-8 is currently supported, which has the Windows Code
+// Page Identifier 65001
+
+// Check this works with the clang-cl driver as well as with the GNU clang 
driver
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MSVC %s
+// RUN: %clang --target=x86_64-pc-windows-msvc -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-MSVC %s
+// CHECK-MSVC: -D_MSVC_EXECUTION_CHARACTER_SET=65001
+
+// It shouldn't be defined for any non MSVC targets
+// RUN: %clang --target=x86_64-pc-windows-gnu -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-NON-MSVC %s
+// CHECK-NON-MSVC-NOT: -D_MSVC_EXECUTION_CHARACTER_SET
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1609,4 +1609,12 @@
   if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
 /*Default=*/false))
 CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  CC1Args.push_back("-D_MSVC_EXECUTION_CHARACTER_SET=65001");
 }


Index: clang/test/Driver/cl-execution-character-set.c
===
--- /dev/null
+++ clang/test/Driver/cl-execution-character-set.c
@@ -0,0 +1,14 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// Only UTF-8 is currently supported, which has the Windows Code
+// Page Identifier 65001
+
+// Check this works with the clang-cl driver as well as with the GNU clang driver
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MSVC %s
+// RUN: %clang --target=x86_64-pc-windows-msvc -### %s 2>&1 | FileCheck -check-prefix=CHECK-MSVC %s
+// CHECK-MSVC: -D_MSVC_EXECUTION_CHARACTER_SET=65001
+
+// It shouldn't be defined for any non MSVC targets
+// RUN: %clang --target=x86_64-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK-NON-MSVC %s
+// CHECK-NON-MSVC-NOT: -D_MSVC_EXECUTION_CHARACTER_SET
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1609,4 +1609,12 @@
   if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti,
 /*Default=*/false))
 CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  CC1Args.push_back("-D_MSVC_EXECUTION_CHARACTER_SET=65001");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-25 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

Seems like this is causing failures in a test for clang-tidy if the triple used 
is an MSVC one. Let me see what I can do about it


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

https://reviews.llvm.org/D114576

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


[PATCH] D114579: [clang-tidy] Exempt _MSVC_EXECUTION_CHARACTER_SET from cppcoreguidelines-macro-usage

2021-11-25 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: MaskRay, aaron.ballman, lebedev.ri, JonasToth, hokein.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, xazax.hun, nemanjai.
zero9178 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In https://reviews.llvm.org/D114576 I am trying to add an unconditional define 
to the MSVC cc1 driver which sadly then leads to a test failure in 
`cppcoreguidelines-macro-usage-command-line-macros.cpp` with MSVC builds.

The solution is a bit hacky IMO, but there seems to already be a similar 
workaround for `__GCC_HAVE_DWARF2_CFI_ASM`. I don't know of any way to 
differentiate between defines passed on the CLI by users, and ones set by the 
driver, so this will have to do for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114579

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp


Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -47,7 +47,8 @@
   return;
 
 StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
-if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM")
+if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM" ||
+MacroName == "_MSVC_EXECUTION_CHARACTER_SET")
   return;
 if (!CheckCapsOnly && !RegExp.match(MacroName))
   Check->warnMacro(MD, MacroName);


Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -47,7 +47,8 @@
   return;
 
 StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
-if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM")
+if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM" ||
+MacroName == "_MSVC_EXECUTION_CHARACTER_SET")
   return;
 if (!CheckCapsOnly && !RegExp.match(MacroName))
   Check->warnMacro(MD, MacroName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114651: [clang-cl] Expose -Wall to clang-cl by unaliasing -Wall, keeping /Wall as alias to -Weverything

2021-11-26 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

Is the deviation from MSVC behaviour here intentional? MSVC flags allow both 
using a `/` as well as `-` as prefix. That means Both `-Wall` and `/Wall` are 
accepted by MSVC as well as clang-cl and in both compilers currently lead to 
ALL warnings being emitted. So this patch would deviate from that behaviour as 
well as add confusion as every other option behaves the same in MSVC and 
clang-cl, regardless of whether `-` or `/` is used as prefix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114651

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


[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-27 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 390156.
zero9178 added a comment.

Alternative implementation of the original patch.

Moves the defining macro from being added to the cc1 command line by the 
driver, to being a builtin macro. This should avoid the issues with clang-tidy.


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

https://reviews.llvm.org/D114576

Files:
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < 
/dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-30 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ba70d32736a: [PR52549][clang-cl] Predefine 
_MSVC_EXECUTION_CHARACTER_SET (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114576

Files:
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < 
/dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114579: [clang-tidy] Exempt _MSVC_EXECUTION_CHARACTER_SET from cppcoreguidelines-macro-usage

2021-11-30 Thread Markus Böck via Phabricator via cfe-commits
zero9178 abandoned this revision.
zero9178 added a comment.

Found another solution to the original issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114579

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


[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2021-11-30 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: dblaikie, aaron.ballman, rsmith.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`-Wdeclaration-after-statement` currently only outputs an diagnostic if the 
user is compiling in C versions older than C99, even if the warning was 
explicitly requested by the user. 
This patch makes the warning also available in later C versions. If the C 
version is C99 or later it is simply a normal warning that is disabled by 
default (as it is valid C99) and has to be enabled by users. In older versions 
it remains an extension warning, and therefore affected by -pedantic.

The above behaviour also matches GCCs behaviour.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,11 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i; /* expected-warning {{ISO C90 forbids mixing declarations and 
code}}*/
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9837,7 +9837,10 @@
 
 def ext_mixed_decls_code : Extension<
   "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  ext_mixed_decls_code.Text>,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -239,6 +239,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,11 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i; /* expected-warning {{ISO C90 forbids mixing declarations and code}}*/
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declar

[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: erichkeane, rjmccall, efriedma, asl, aaron.ballman.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A common post condition of the various visitor functions in CodeGen is that 
instructions, that do not return any values, simply return a nullptr Value as a 
sentinel. This has not been the case however for calls to some builtins 
returning void, as well as for an initializer expression of the form `void()`. 
This would then lead to ICEs in CodeGen on code relying on nullptr being 
returned for void values, which is eg. the case for conditional expressions [0].
This patch fixes that by returning nullptr Values for intrinsics known not to 
return any values as well as for a scalar initializer returning void.

Fixes https://github.com/llvm/llvm-project/issues/53127

[0] 
https://github.com/llvm/llvm-project/blob/266ec801fb23f9f5f1d61ca9466e0805fbdb78a7/clang/lib/CodeGen/CGExprScalar.cpp#L4849-L4892

-

Note:
I opted to adjust these functions as an idealistic goal to be more consistent 
with the rest of the codebase. An alternative implementation that would have 
also fixed  the above issue and would be less code is to simply handle it 
within the visit function of the conditional expression, by simply checking if 
it the type of the expression is void and returning bailing out by returning 
nullptr there instead of creating the invalid phi node. If you prefer that 
version or something of the sorts please let me know


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- clang/test/CodeGen/pr53127.cpp
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// CH

[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-23 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 470002.
zero9178 added a comment.

Rebase and boop CI


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

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// CHECK-NEXT:br label [[COND_END19]]
+// CHECK:   cond.end19:
+// CHECK-NEXT:[[CALL20:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL20]], label [[COND_TRUE21:%.*]], label [[COND_FALSE22:%.*]]
+// CHECK:   cond.true21:
+// CHECK-NEXT:call void @llvm.eh.unwind.init()
+// CHECK-NEXT:br label [[COND_END23:%.*]]
+// CHECK:   cond.false22:
+// CHECK-NEXT:br label [[COND_END23]]
+// CHECK:   cond.end23:
+// CHECK-NEXT:[[CALL24:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CALL24]] to i64
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @_ZdlPv(ptr noundef [[TMP3]]) #[[ATTR8:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void f(int* p, ...)
+{
+  e() ? __builtin_trap() : void();
+  e() ? __builtin_debugtrap() : void();
+  e() ? __builtin_assume(true) : void();
+  __builtin_va_list l;
+  e() ? __builtin_va_start(l, p) : void();
+  __builtin_va_list l2;
+  e() ? __builtin_va_copy(l, l2) : void();
+  e() ? __builtin_prefetch(p) : void();
+  e() ? __builtin_unwind_init() : void();
+  e() ? __builtin_operator_delete(p) : void();
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -467,6 +467,9 @@
 return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
   }
   Value *VisitCXXScalarVa

[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-24 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 470071.
zero9178 added a comment.

clang-format and specify target triple in test since mangling is target 
dependent


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

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// CHECK-NEXT:br label [[COND_END19]]
+// CHECK:   cond.end19:
+// CHECK-NEXT:[[CALL20:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL20]], label [[COND_TRUE21:%.*]], label [[COND_FALSE22:%.*]]
+// CHECK:   cond.true21:
+// CHECK-NEXT:call void @llvm.eh.unwind.init()
+// CHECK-NEXT:br label [[COND_END23:%.*]]
+// CHECK:   cond.false22:
+// CHECK-NEXT:br label [[COND_END23]]
+// CHECK:   cond.end23:
+// CHECK-NEXT:[[CALL24:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CALL24]] to i64
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @_ZdlPv(ptr noundef [[TMP3]]) #[[ATTR8:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void f(int* p, ...)
+{
+  e() ? __builtin_trap() : void();
+  e() ? __builtin_debugtrap() : void();
+  e() ? __builtin_assume(true) : void();
+  __builtin_va_list l;
+  e() ? __builtin_va_start(l, p) : void();
+  __builtin_va_list l2;
+  e() ? __builtin_va_copy(l, l2) : void();
+  e() ? __builtin_prefetch(p) : void();
+  e() ? __builtin_unwind_init() : void();
+  e() ? __builtin_operator_delete(p) : void();
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -467,6 +467,9 @@
 return 

[PATCH] D136548: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization

2022-10-24 Thread Markus Böck 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 rG3637dc601c49: [clang][CodeGen] Consistently return nullptr 
Values for void builtins and… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136548

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/pr53127.cpp

Index: clang/test/CodeGen/pr53127.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr53127.cpp
@@ -0,0 +1,87 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+bool e();
+
+void operator delete(void*);
+
+// CHECK-LABEL: @_Z1fPiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[L:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[L2:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
+// CHECK:   cond.true:
+// CHECK-NEXT:call void @llvm.trap()
+// CHECK-NEXT:br label [[COND_END:%.*]]
+// CHECK:   cond.false:
+// CHECK-NEXT:br label [[COND_END]]
+// CHECK:   cond.end:
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL1]], label [[COND_TRUE2:%.*]], label [[COND_FALSE3:%.*]]
+// CHECK:   cond.true2:
+// CHECK-NEXT:call void @llvm.debugtrap()
+// CHECK-NEXT:br label [[COND_END4:%.*]]
+// CHECK:   cond.false3:
+// CHECK-NEXT:br label [[COND_END4]]
+// CHECK:   cond.end4:
+// CHECK-NEXT:[[CALL5:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP0:%.*]] = zext i1 [[CALL5]] to i64
+// CHECK-NEXT:call void @llvm.assume(i1 true)
+// CHECK-NEXT:[[CALL6:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL6]], label [[COND_TRUE7:%.*]], label [[COND_FALSE8:%.*]]
+// CHECK:   cond.true7:
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:br label [[COND_END9:%.*]]
+// CHECK:   cond.false8:
+// CHECK-NEXT:br label [[COND_END9]]
+// CHECK:   cond.end9:
+// CHECK-NEXT:[[CALL10:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL10]], label [[COND_TRUE11:%.*]], label [[COND_FALSE14:%.*]]
+// CHECK:   cond.true11:
+// CHECK-NEXT:[[ARRAYDECAY12:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L]], i64 0, i64 0
+// CHECK-NEXT:[[ARRAYDECAY13:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[L2]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_copy(ptr [[ARRAYDECAY12]], ptr [[ARRAYDECAY13]])
+// CHECK-NEXT:br label [[COND_END15:%.*]]
+// CHECK:   cond.false14:
+// CHECK-NEXT:br label [[COND_END15]]
+// CHECK:   cond.end15:
+// CHECK-NEXT:[[CALL16:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL16]], label [[COND_TRUE17:%.*]], label [[COND_FALSE18:%.*]]
+// CHECK:   cond.true17:
+// CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @llvm.prefetch.p0(ptr [[TMP1]], i32 0, i32 3, i32 1)
+// CHECK-NEXT:br label [[COND_END19:%.*]]
+// CHECK:   cond.false18:
+// CHECK-NEXT:br label [[COND_END19]]
+// CHECK:   cond.end19:
+// CHECK-NEXT:[[CALL20:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:br i1 [[CALL20]], label [[COND_TRUE21:%.*]], label [[COND_FALSE22:%.*]]
+// CHECK:   cond.true21:
+// CHECK-NEXT:call void @llvm.eh.unwind.init()
+// CHECK-NEXT:br label [[COND_END23:%.*]]
+// CHECK:   cond.false22:
+// CHECK-NEXT:br label [[COND_END23]]
+// CHECK:   cond.end23:
+// CHECK-NEXT:[[CALL24:%.*]] = call noundef zeroext i1 @_Z1ev()
+// CHECK-NEXT:[[TMP2:%.*]] = zext i1 [[CALL24]] to i64
+// CHECK-NEXT:[[TMP3:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// CHECK-NEXT:call void @_ZdlPv(ptr noundef [[TMP3]]) #[[ATTR8:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void f(int* p, ...)
+{
+  e() ? __builtin_trap() : void();
+  e() ? __builtin_debugtrap() : void();
+  e() ? __builtin_assume(true) : void();
+  __builtin_va_list l;
+  e() ? __builtin_va_start(l, p) : void();
+  __builtin_va_list l2;
+  e() ? __builtin_va_copy(l, l2) : void();
+  e() ? __builtin_prefetch(p) : void();
+  e() ? __builtin_unwind_init() : void();
+  e() ? __builtin_operator_delete(p) : void();
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
==

[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-01-26 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added inline comments.



Comment at: clang/lib/Driver/ToolChains/LazyDetector.h:26
+
+  mutable std::optional Detector;
+

Any reason this is `mutable`? I don't see it being used a non-const way in a 
const method


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-02 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added inline comments.



Comment at: clang/lib/Driver/ToolChains/LazyDetector.h:26
+
+  mutable std::optional Detector;
+

serge-sans-paille wrote:
> zero9178 wrote:
> > Any reason this is `mutable`? I don't see it being used a non-const way in 
> > a const method
> yeah, `T const *operator->() const` updates the optional by actually creating 
> the value. (`std::optional::empalce` is not const)
Your `T const *operator->() const` method does not do so, `T *operator->()` 
does, which is non-const and hence can call `emplace` without issues. 
So as far as C++ goes it is not required. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

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


[PATCH] D75153: [ThinLTO] Allow usage of all SMT threads in the system

2020-03-28 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

This patch seems to break when disabling threading (aka LLVM_ENABLE_THREADS == 
0) as get_threadpool_strategy is undefined therefore creating linker failures 
in clang. (Tested on Windows)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75153



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


[PATCH] D146422: [NFC] Fix typo in comment

2023-03-21 Thread Markus Böck via Phabricator via cfe-commits
zero9178 accepted this revision.
zero9178 added a comment.
This revision is now accepted and ready to land.

LGTM. The Windows CI failure you can probably ignore, seems to be just a flaky 
test or maybe some other recent change that caused it. Do


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146422

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


[PATCH] D146422: [NFC] Fix typo in comment

2023-03-21 Thread Markus Böck 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 rG64276eec7ed0: [clang][NFC] Fix typo in comment (authored by 
1lyasm, committed by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146422

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5437,7 +5437,7 @@
   }
 
   // Not all of the args have been processed, so there must've been more args
-  // then were required to initialize the element.
+  // than were required to initialize the element.
   if (ArgIndexToProcess < Args.size()) {
 Sequence.SetFailed(InitializationSequence::FK_ParenthesizedListInitFailed);
 if (!VerifyOnly) {


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5437,7 +5437,7 @@
   }
 
   // Not all of the args have been processed, so there must've been more args
-  // then were required to initialize the element.
+  // than were required to initialize the element.
   if (ArgIndexToProcess < Args.size()) {
 Sequence.SetFailed(InitializationSequence::FK_ParenthesizedListInitFailed);
 if (!VerifyOnly) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118386: [Support][NFC] Fix generic `ChildrenGetterTy` of `IDFCalculatorBase`

2022-01-27 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: Szelethus, jmorse, kuhar.
Herald added subscribers: Chia-hungDuan, dexonsmith, rriddle, hiraditya.
zero9178 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer.
Herald added projects: clang, LLVM.

Both `IDFCalculatorBase` and its accompanying `DominatorTreeBase` only supports 
pointer nodes. The template argument is the block type itself and any uses of 
`GraphTraits` is therefore done via a pointer to the node type. 
However, the `ChildrenGetterTy` type of `IDFCalculatorBase` has a use on just 
the node type instead of a pointer to the node type. Various parts of the 
monorepo has worked around this issue by providing specializations of 
`GraphTraits` for the node type directly, or not been affected by using 
specializations instead of the generic case. These are unnecessary however and 
instead the generic code should be fixed instead.

An example from within Tree is eg. A use of IDFCalculatorBase in 
InstrRefBasedImpl.cpp. It basically instantiates a 
`IDFCalculatorBase` but due to the bug above then 
goes on to specialize `GraphTraits` although 
`GraphTraits` exists (and should be used instead).

Similar dead code exists in clang which defines redundant GraphTraits to work 
around this bug.

This patch fixes both the original issue and removes the dead code that was 
used to work around the issue.

As a side node, my own motivation was when using MLIR and using `mlir::Block`s 
as nodes. As MLIR correctly only provides `GraphTraits` I was not 
able to use `IDFCalculatorBase`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118386

Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
  clang/include/clang/Analysis/CFG.h
  llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2212,40 +2212,6 @@
   // redundant PHIs.
 }
 
-// Boilerplate for feeding MachineBasicBlocks into IDF calculator. Provide
-// template specialisations for graph traits and a successor enumerator.
-namespace llvm {
-template <> struct GraphTraits {
-  using NodeRef = MachineBasicBlock *;
-  using ChildIteratorType = MachineBasicBlock::succ_iterator;
-
-  static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
-  static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
-  static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
-};
-
-template <> struct GraphTraits {
-  using NodeRef = const MachineBasicBlock *;
-  using ChildIteratorType = MachineBasicBlock::const_succ_iterator;
-
-  static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
-  static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
-  static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
-};
-
-using MachineDomTreeBase = DomTreeBase::NodeType;
-using MachineDomTreeChildGetter =
-typename IDFCalculatorDetail::ChildrenGetterTy;
-
-namespace IDFCalculatorDetail {
-template <>
-typename MachineDomTreeChildGetter::ChildrenTy
-MachineDomTreeChildGetter::get(const NodeRef &N) {
-  return {N->succ_begin(), N->succ_end()};
-}
-} // namespace IDFCalculatorDetail
-} // namespace llvm
-
 void InstrRefBasedLDV::BlockPHIPlacement(
 const SmallPtrSetImpl &AllBlocks,
 const SmallPtrSetImpl &DefBlocks,
@@ -2253,8 +2219,7 @@
   // Apply IDF calculator to the designated set of location defs, storing
   // required PHIs into PHIBlocks. Uses the dominator tree stored in the
   // InstrRefBasedLDV object.
-  IDFCalculatorDetail::ChildrenGetterTy foo;
-  IDFCalculatorBase IDF(DomTree->getBase(), foo);
+  IDFCalculatorBase IDF(DomTree->getBase());
 
   IDF.setLiveInBlocks(AllBlocks);
   IDF.setDefiningBlocks(DefBlocks);
Index: llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
===
--- llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
+++ llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
@@ -37,7 +37,7 @@
 /// May be specialized if, for example, one wouldn't like to return nullpointer
 /// successors.
 template  struct ChildrenGetterTy {
-  using NodeRef = typename GraphTraits::NodeRef;
+  using NodeRef = typename GraphTraits::NodeRef;
   using ChildrenTy = SmallVector;
 
   ChildrenTy get(const NodeRef &N);
Index: clang/include/clang/Analysis/CFG.h
===
--- clang/include/clang/Analysis/CFG.h
+++ clang/include/clang/Analysis/CFG.h
@@ -1494,9 +1494,6 @@
   static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
 };
 
-template <> struct GraphTraits
-: GraphTraits

[PATCH] D118386: [Support][NFC] Fix generic `ChildrenGetterTy` of `IDFCalculatorBase`

2022-01-30 Thread Markus Böck 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 rGe0b11c7659f8: [Support][NFC] Fix generic `ChildrenGetterTy` 
of `IDFCalculatorBase` (authored by zero9178).

Changed prior to commit:
  https://reviews.llvm.org/D118386?vs=403668&id=404408#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118386

Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
  clang/include/clang/Analysis/CFG.h
  llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2212,40 +2212,6 @@
   // redundant PHIs.
 }
 
-// Boilerplate for feeding MachineBasicBlocks into IDF calculator. Provide
-// template specialisations for graph traits and a successor enumerator.
-namespace llvm {
-template <> struct GraphTraits {
-  using NodeRef = MachineBasicBlock *;
-  using ChildIteratorType = MachineBasicBlock::succ_iterator;
-
-  static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
-  static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
-  static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
-};
-
-template <> struct GraphTraits {
-  using NodeRef = const MachineBasicBlock *;
-  using ChildIteratorType = MachineBasicBlock::const_succ_iterator;
-
-  static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
-  static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
-  static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
-};
-
-using MachineDomTreeBase = DomTreeBase::NodeType;
-using MachineDomTreeChildGetter =
-typename IDFCalculatorDetail::ChildrenGetterTy;
-
-namespace IDFCalculatorDetail {
-template <>
-typename MachineDomTreeChildGetter::ChildrenTy
-MachineDomTreeChildGetter::get(const NodeRef &N) {
-  return {N->succ_begin(), N->succ_end()};
-}
-} // namespace IDFCalculatorDetail
-} // namespace llvm
-
 void InstrRefBasedLDV::BlockPHIPlacement(
 const SmallPtrSetImpl &AllBlocks,
 const SmallPtrSetImpl &DefBlocks,
@@ -2253,8 +2219,7 @@
   // Apply IDF calculator to the designated set of location defs, storing
   // required PHIs into PHIBlocks. Uses the dominator tree stored in the
   // InstrRefBasedLDV object.
-  IDFCalculatorDetail::ChildrenGetterTy foo;
-  IDFCalculatorBase IDF(DomTree->getBase(), foo);
+  IDFCalculatorBase IDF(DomTree->getBase());
 
   IDF.setLiveInBlocks(AllBlocks);
   IDF.setDefiningBlocks(DefBlocks);
Index: llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
===
--- llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
+++ llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
@@ -37,7 +37,7 @@
 /// May be specialized if, for example, one wouldn't like to return nullpointer
 /// successors.
 template  struct ChildrenGetterTy {
-  using NodeRef = typename GraphTraits::NodeRef;
+  using NodeRef = typename GraphTraits::NodeRef;
   using ChildrenTy = SmallVector;
 
   ChildrenTy get(const NodeRef &N);
Index: clang/include/clang/Analysis/CFG.h
===
--- clang/include/clang/Analysis/CFG.h
+++ clang/include/clang/Analysis/CFG.h
@@ -1494,9 +1494,6 @@
   static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
 };
 
-template <> struct GraphTraits
-: GraphTraits {};
-
 template <> struct GraphTraits< const ::clang::CFGBlock *> {
   using NodeRef = const ::clang::CFGBlock *;
   using ChildIteratorType = ::clang::CFGBlock::const_succ_iterator;
@@ -1506,9 +1503,6 @@
   static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
 };
 
-template <> struct GraphTraits
-: GraphTraits {};
-
 template <> struct GraphTraits> {
   using NodeRef = ::clang::CFGBlock *;
   using ChildIteratorType = ::clang::CFGBlock::const_pred_iterator;
@@ -1521,9 +1515,6 @@
   static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
 };
 
-template <> struct GraphTraits>
-: GraphTraits {};
-
 template <> struct GraphTraits> {
   using NodeRef = const ::clang::CFGBlock *;
   using ChildIteratorType = ::clang::CFGBlock::const_pred_iterator;
@@ -1536,9 +1527,6 @@
   static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
 };
 
-template <> struct GraphTraits>
-: GraphTraits {};
-
 // Traits for: CFG
 
 template <> struct GraphTraits< ::clang::CFG* >
Index: clang/include/clang/Analysis/Analyses/Dominators.h
===
--- clang/include/clang/Analysis/Analyses/Dominators.h

[PATCH] D116485: [clang][MinGW] Explicitly ignore `-fPIC` & friends

2022-01-01 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: mstorsjo, compnerd, mati865.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC on Windows ignores this flag completely [0] which some build systems sadly 
rely on when compiling for Windows using MinGW. The current behaviour of clang 
however is to error out as `-fPIC` & friends has no effect on Windows.

This patch instead changes the behaviour for MinGW to ignore the option for the 
sake of compatibility

Fixes https://github.com/llvm/llvm-project/issues/52947

[0] https://gcc.gnu.org/legacy-ml/gcc-patches/2015-08/msg00836.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116485

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/pic.c
  clang/test/Driver/windows-pic.cpp


Index: clang/test/Driver/windows-pic.cpp
===
--- clang/test/Driver/windows-pic.cpp
+++ clang/test/Driver/windows-pic.cpp
@@ -16,15 +16,6 @@
 // RUN: %clang -### -target i686-windows-itanium -fPIE -fno-pie %s
 // RUN: %clang -### -target i686-windows-itanium -fpie -fno-pie %s
 
-// RUN: %clang -### -target i686-windows-gnu -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fpie %s 2>&1 | FileCheck 
-check-prefix CHECK-pie-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fPIC -fno-pic %s
-// RUN: %clang -### -target i686-windows-gnu -Fpic -fno-pic %s
-// RUN: %clang -### -target i686-windows-gnu -fPIE -fno-pie %s
-// RUN: %clang -### -target i686-windows-gnu -fpie -fno-pie %s
-
 // RUN: %clang -### -target x86_64-windows -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
 // RUN: %clang -### -target x86_64-windows -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
 // RUN: %clang -### -target x86_64-windows -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
@@ -43,15 +34,6 @@
 // RUN: %clang -### -target x86_64-windows-itanium -fPIE -fno-pie %s
 // RUN: %clang -### -target x86_64-windows-itanium -fpie -fno-pie %s
 
-// RUN: %clang -### -target x86_64-windows-gnu -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpie %s 2>&1 | FileCheck 
-check-prefix CHECK-pie-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIC -fno-pic %s
-// RUN: %clang -### -target x86_64-windows-gnu -Fpic -fno-pic %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIE -fno-pie %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpie -fno-pie %s
-
 // CHECK-PIC-ERROR: unsupported option '-fPIC' for target '{{.*}}
 // CHECK-pic-ERROR: unsupported option '-fpic' for target '{{.*}}
 // CHECK-PIE-ERROR: unsupported option '-fPIE' for target '{{.*}}
Index: clang/test/Driver/pic.c
===
--- clang/test/Driver/pic.c
+++ clang/test/Driver/pic.c
@@ -301,3 +301,13 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 // RUN: %clang -c %s -target aarch64-windows-gnu -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+//
+// On MinGW, allow specifying -fPIC & friends but ignore them
+// RUN: %clang -fno-PIC -c %s -target x86_64-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang -fPIC -c %s -target i686-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+// RUN: %clang -fno-PIC -c %s -target aarch64-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -487,8 +487,7 @@
 }
 
 bool toolchains::MinGW::isPICDefaultForced() const {
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return true;
 }
 
 llvm::ExceptionHandling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1186,10 +1186,9 @@
 options::OPT_fpic, options::OPT_fno_pic,
 options::OPT_fPIE, options::OPT_fno_PI

[PATCH] D116485: [clang][MinGW] Explicitly ignore `-fPIC` & friends

2022-01-02 Thread Markus Böck 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 rGdbeeb136abcb: [clang][MinGW] Explicitly ignore `-fPIC` & 
friends (authored by zero9178).

Changed prior to commit:
  https://reviews.llvm.org/D116485?vs=396884&id=396916#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116485

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/pic.c
  clang/test/Driver/windows-pic.cpp


Index: clang/test/Driver/windows-pic.cpp
===
--- clang/test/Driver/windows-pic.cpp
+++ clang/test/Driver/windows-pic.cpp
@@ -16,15 +16,6 @@
 // RUN: %clang -### -target i686-windows-itanium -fPIE -fno-pie %s
 // RUN: %clang -### -target i686-windows-itanium -fpie -fno-pie %s
 
-// RUN: %clang -### -target i686-windows-gnu -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fpie %s 2>&1 | FileCheck 
-check-prefix CHECK-pie-ERROR %s
-// RUN: %clang -### -target i686-windows-gnu -fPIC -fno-pic %s
-// RUN: %clang -### -target i686-windows-gnu -Fpic -fno-pic %s
-// RUN: %clang -### -target i686-windows-gnu -fPIE -fno-pie %s
-// RUN: %clang -### -target i686-windows-gnu -fpie -fno-pie %s
-
 // RUN: %clang -### -target x86_64-windows -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
 // RUN: %clang -### -target x86_64-windows -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
 // RUN: %clang -### -target x86_64-windows -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
@@ -43,15 +34,6 @@
 // RUN: %clang -### -target x86_64-windows-itanium -fPIE -fno-pie %s
 // RUN: %clang -### -target x86_64-windows-itanium -fpie -fno-pie %s
 
-// RUN: %clang -### -target x86_64-windows-gnu -fPIC %s 2>&1 | FileCheck 
-check-prefix CHECK-PIC-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpic %s 2>&1 | FileCheck 
-check-prefix CHECK-pic-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIE %s 2>&1 | FileCheck 
-check-prefix CHECK-PIE-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpie %s 2>&1 | FileCheck 
-check-prefix CHECK-pie-ERROR %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIC -fno-pic %s
-// RUN: %clang -### -target x86_64-windows-gnu -Fpic -fno-pic %s
-// RUN: %clang -### -target x86_64-windows-gnu -fPIE -fno-pie %s
-// RUN: %clang -### -target x86_64-windows-gnu -fpie -fno-pie %s
-
 // CHECK-PIC-ERROR: unsupported option '-fPIC' for target '{{.*}}
 // CHECK-pic-ERROR: unsupported option '-fpic' for target '{{.*}}
 // CHECK-PIE-ERROR: unsupported option '-fPIE' for target '{{.*}}
Index: clang/test/Driver/pic.c
===
--- clang/test/Driver/pic.c
+++ clang/test/Driver/pic.c
@@ -301,3 +301,13 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 // RUN: %clang -c %s -target aarch64-windows-gnu -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+//
+// On MinGW, allow specifying -fPIC & friends but ignore them
+// RUN: %clang -fno-PIC -c %s -target x86_64-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang -fPIC -c %s -target i686-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+// RUN: %clang -fno-PIC -c %s -target aarch64-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -486,10 +486,7 @@
   return false;
 }
 
-bool toolchains::MinGW::isPICDefaultForced() const {
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
-}
+bool toolchains::MinGW::isPICDefaultForced() const { return true; }
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1186,10 +1186,9 @@
 options::OPT_fpic, options::OPT_fno_pic,
 options::OPT_fPIE, options::OPT_fno_PIE,
 options::OPT_fpie, options::OPT_fno_pie);
-  if (Triple.isOSWindows() && LastPICArg &&
-  La

[PATCH] D116020: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling

2022-01-03 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

Friendly bump :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116020

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


[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-03 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D114787#3188735 , @aaron.ballman 
wrote:

> https://reviews.llvm.org/D115094 is a review for doing effectively the same 
> fix. Can you coordinate with the other patch author to determine who will 
> drive this fix?

I sent an email to the author on December 13th but have yet to hear back from 
them. Should we move forward with this version of the patch then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114787

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


[PATCH] D116020: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling

2022-01-03 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D116020#3218453 , @majnemer wrote:

> I wonder if we should have different behavior for MSVC targets.
>
> If I do:
>
>   class Incomplete;
>   extern "C" int __stdcall Fn(int, Incomplete, long long);
>   auto fnptr = &Fn;
>
> MSVC generates:
>
>   EXTRN   _Fn@12:PROC
>
> It appears that they skip over incomplete types.
>
> Should the behavior for incomplete types depend on the target?

That's actually a good point! I originally failed to get MSVC to generate a 
symbol for just the function declaration and thought it might just be 
irrelevant for MSVC. I didn't think of just using the function as you did lol. 
In the case of MinGW it always gets through the mangled as debug info is 
generated for the whole class, including just the method declaration.

I experimented a bit with your code and found a few interesting things:
clang actually refuses taking the address of a stdcall function if it has an 
incomplete type parameter:

  clang-cl test.cpp test2.cpp --target=i686-pc-windows-msvc
  test.cpp(3,15): error: parameter '' must have a complete type to use function 
'Fn' with the stdcall calling convention
  auto fnptr = &Fn;
^
  test.cpp(1,7): note: forward declaration of 'Incomplete'
  class Incomplete;
^
  1 error generated.

Meanwhile cl will compile but fail to link with another object file that calls 
`fnptr`:

  test.obj : error LNK2001: unresolved external symbol _Fn@12
Hint on symbols that are defined and could potentially match:
  _Fn@16
  test.exe : fatal error LNK1120: 1 unresolved externals

As both of them error out one way I am guessing it simply doesn't matter how 
the incomplete stdcall gets mangled. One cannot create calls to the function 
while the parameter type is incomplete and therefore no references to it are 
created.

How DWARF debuggers handle the "wrong" declarations in the debug info I have no 
clue about however. Given that GCC works the same however I am guessing gdb 
handles it correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116020

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


[PATCH] D116020: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling

2022-01-05 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 397524.
zero9178 added a comment.

Update test according to reviewers comment


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

https://reviews.llvm.org/D116020

Files:
  clang/lib/AST/Mangle.cpp
  clang/test/CodeGen/pr52782-stdcall-func-decl.cpp


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm 
-debug-info-kind=constructor %s | FileCheck %s
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: 
"\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4"
+  nsresult __stdcall InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s | FileCheck %s
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: "\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4"
+  nsresult __stdcall InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116020: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling

2022-01-05 Thread Markus Böck 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 rG782791ee84d2: [clang][#52782] Bail on incomplete parameter 
type in stdcall name mangling (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116020

Files:
  clang/lib/AST/Mangle.cpp
  clang/test/CodeGen/pr52782-stdcall-func-decl.cpp


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm 
-debug-info-kind=constructor %s | FileCheck %s
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: 
"\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4"
+  nsresult __stdcall InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s | FileCheck %s
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: "\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4"
+  nsresult __stdcall InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 397857.
zero9178 added a comment.

Addressed reviewer comments: Added tests for cases when the diagnostic should 
not be emitted.


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

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,23 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i; /* expected-warning {{ISO C90 forbids mixing declarations and 
code}}*/
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9863,7 +9863,10 @@
 
 def ext_mixed_decls_code : Extension<
   "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  ext_mixed_decls_code.Text>,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,23 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i; /* expected-warning {{ISO C90 forbids mixing declarations and code}}*/
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked an inline comment as done.
zero9178 added inline comments.



Comment at: clang/test/Sema/warn-mixed-decls.c:1-4
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */

aaron.ballman wrote:
> I'd also like to see RUN lines for when we expect the diagnostic to not be 
> enabled:
> ```
> /* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s */
> /* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s */
> /* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
> -Wdeclaration-after-statement %s */
> 
> /* none-no-diagnostics */
> ```
> I should note that the last RUN line will give different behavior between 
> Clang and GCC: https://godbolt.org/z/o1PKo7dhM, but I think that's a more 
> general issue that doesn't need to be addressed in this patch. (We don't have 
> a way to flag a diagnostic as requiring a particular language mode.)
The `*/`  on the next line seems to be necessary so as lit seems to otherwise 
add `*/` to the command line of the `RUN` command. At least this is the case on 
my Windows machine.  


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

https://reviews.llvm.org/D114787

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


[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 397971.
zero9178 marked an inline comment as done.
zero9178 added a comment.

Improved error messages and adjusted tests accordingly


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

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with 
standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9862,8 +9862,11 @@
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9865
 def ext_mixed_decls_code : Extension<
   "ISO C90 forbids mixing declarations and code">,
+  InGroup;

aaron.ballman wrote:
> In the other review, I left a comment about the diagnostic text: 
> https://reviews.llvm.org/D115094#3176985
> 
> Since we're cleaning this up, I think we should reword this diagnostic so it 
> follows newer conventions. I think the extension diagnostic should read: 
> `mixing declarations and code is a C99 extension` and the default ignore 
> warning should read `mixing declarations and code is incompatible with 
> standards before C99`. (This also helpfully removes the `ISO C90` wording, 
> which is confused about the name of the standard.)
> 
> Typically, we'd put the default ignore warning under a new `CPre99Compat` 
> diagnostic group (spelled `pre-c99-compat`) as we do with other precompat 
> diagnostics, but the goal here is to match GCC's behavior and so the existing 
> warning group seems fine to me (I don't think we want warnings in multiple 
> groups, but that's possibly an option if it matters in the future).
A `CPre99Compat` diagnostic group sounds like a good idea if more such warnings 
would be requested by users. 


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

https://reviews.llvm.org/D114787

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


[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-06 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: Quuxplusone, aaron.ballman, rsmith.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prior to this patch, clang might suggest a deprecated name of a declaration 
over another name as the only mechanism for resolving two typo corrections 
referring to the same underlying declaration has previously been an 
alphabetical sort.

This patch adjusts this resolve by also taking into account whether one of two 
declarations are deprecated. If the new one is deprecated it may not replace a 
previous correction with a non-deprecated correction and a previous deprecated 
correction always gets replaced by a non-deprecated new correction.

Fixes https://github.com/llvm/llvm-project/issues/47272


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116775

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


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,17 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+
+namespace PR47272
+{
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global 
namespace; did you mean 'Views::Take'?}}
+}
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4310,15 +4310,38 @@
 std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
 for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
  RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
+  if (RI->getCorrectionDecl() != NewND)
+continue;
+
+  // The Correction refers to a decl already in the list. No insertion is
+  // necessary and all further cases will return.
+
+  auto IsDeprecated = [](Decl *decl) {
+while (decl) {
+  if (decl->isDeprecated())
+return true;
+  decl = llvm::dyn_cast_or_null(decl->getDeclContext());
+}
+return false;
+  };
+
+  // If the Correction in the result list is deprecated and the new one
+  // isn't always replace it with the new Correction.
+  // Additionally, don't allow a new deprecated Correction to overwrite
+  // an old not-deprecated one.
+  auto newIsDeprecated = IsDeprecated(Correction.getFoundDecl());
+  auto oldIsDeprecated = IsDeprecated(RI->getFoundDecl());
+  if (oldIsDeprecated && !newIsDeprecated) {
+*RI = Correction;
 return;
   }
+  if (newIsDeprecated && !oldIsDeprecated)
+return;
+
+  // Otherwise, simply sort them alphabetically.
+  if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
+*RI = Correction;
+  return;
 }
   }
   if (CList.empty() || Correction.isResolved())


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,17 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+
+namespace PR47272
+{
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
+}
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4310,15 +4310,38 @@
 std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
 for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
  RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidat

[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-07 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 398151.
zero9178 added a comment.

Utilize operator< of std::pair to simplify the comparison A LOT, simplify using 
llvm::find_if and add additional test case


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

https://reviews.llvm.org/D116775

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


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace B {
+int pr47272();  // expected-note{{'B::pr47272' declared here}}
+}
+
+namespace [[deprecated]] A {
+using B::pr47272;
+}
+
+namespace [[deprecated]] C {
+using B::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global 
namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272(); // expected-error{{no member named 'pr47272' in the 
global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
-return;
-  }
+auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &typoCorr) {
+  return typoCorr.getCorrectionDecl() == NewND;
+});
+if (RI != CList.end()) {
+  // The Correction refers to a decl already in the list. No insertion is
+  // necessary and all further cases will return.
+
+  auto IsDeprecated = [](Decl *decl) {
+while (decl) {
+  if (decl->isDeprecated())
+return true;
+  decl = llvm::dyn_cast_or_null(decl->getDeclContext());
+}
+return false;
+  };
+
+  // Prefer non deprecated Corrections over deprecated and only then
+  // sort using an alphabetical order
+  std::pair newKey = {
+  IsDeprecated(Correction.getFoundDecl()),
+  Correction.getAsString(SemaRef.getLangOpts())};
+
+  std::pair prevKey = {
+  IsDeprecated(RI->getFoundDecl()),
+  RI->getAsString(SemaRef.getLangOpts())};
+
+  if (newKey < prevKey)
+*RI = Correction;
+  return;
 }
   }
   if (CList.empty() || Correction.isResolved())


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace B {
+int pr47272();  // expected-note{{'B::pr47272' declared here}}
+}
+
+namespace [[deprecated]] A {
+using B::pr47272;
+}
+
+namespace [[deprecated]] C {
+using B::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272(); // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing 

[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-07 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked 2 inline comments as done.
zero9178 added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:4345
+  return;
 }
   }

Quuxplusone wrote:
> It seems like this code is overdue for a "compare these two corrections" 
> //predicate//. The simple version would be
> ```
> auto IsBetter = [&](const TypoCorrection& TC1, const TypoCorrection& TC2) {
> std::pair Key1 = { IsDeprecated(TC1.getFoundDecl()), 
> TC1.getAsString(SemaRef.getLangOpts()) };
> std::pair Key2 = { IsDeprecated(TC2.getFoundDecl()), 
> TC2.getAsString(SemaRef.getLangOpts()) };
> return Key1 < Key2;  // prefer non-deprecated, alphabetically earlier 
> declarations
> };
> for (TypoCorrection& TC : CList) {
> if (IsBetter(Correction, TC))
> TC = Correction;
> }
> ```
> Actually, you could even replicate the hoisting of the loop-invariant stuff, 
> the way the old code did:
> ```
> std::pair CorrectionKey = { 
> IsDeprecated(Correction.getFoundDecl()), 
> Correction.getAsString(SemaRef.getLangOpts()) };
> auto CorrectionIsBetterThan = [&](const TypoCorrection& TC) {
> std::pair Key = { IsDeprecated(TC.getFoundDecl()), 
> TC.getAsString(SemaRef.getLangOpts()) };
> return CorrectionKey < Key;  // prefer non-deprecated, alphabetically 
> earlier declarations
> };
> for (TypoCorrection& TC : CList) {
> if (CorrectionIsBetterThan(TC))
> TC = Correction;
> }
> ```
Thanks I really liked the idea of using std::pairs comparison for that. 
I chose to separate the concerns, by first finding the declaration in the list 
and only then using the comparison of the found decl and the new correction. 


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

https://reviews.llvm.org/D116775

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


[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-11 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 398962.
zero9178 added a comment.

Addressed reviewer nits:

- Used proper naming conventions
- Adjusted tests


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

https://reviews.llvm.org/D116775

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


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked 
deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} 
expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global 
namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the 
global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
-return;
-  }
+auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) {
+  return TypoCorr.getCorrectionDecl() == NewND;
+});
+if (RI != CList.end()) {
+  // The Correction refers to a decl already in the list. No insertion is
+  // necessary and all further cases will return.
+
+  auto IsDeprecated = [](Decl *D) {
+while (D) {
+  if (D->isDeprecated())
+return true;
+  D = llvm::dyn_cast_or_null(D->getDeclContext());
+}
+return false;
+  };
+
+  // Prefer non deprecated Corrections over deprecated and only then
+  // sort using an alphabetical order.
+  std::pair NewKey = {
+  IsDeprecated(Correction.getFoundDecl()),
+  Correction.getAsString(SemaRef.getLangOpts())};
+
+  std::pair PrevKey = {
+  IsDeprecated(RI->getFoundDecl()),
+  RI->getAsString(SemaRef.getLangOpts())};
+
+  if (NewKey < PrevKey)
+*RI = Correction;
+  return;
 }
   }
   if (CList.empty() || Correction.isResolved())


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.

[PATCH] D116775: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction

2022-01-11 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6479f03daec1: [clang][#47272] Avoid suggesting deprecated 
version of a declaration over… (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116775

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


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked 
deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} 
expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global 
namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the 
global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts());
-for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
- RI != RIEnd; ++RI) {
-  // If the Correction refers to a decl already in the result list,
-  // replace the existing result if the string representation of Correction
-  // comes before the current result alphabetically, then stop as there is
-  // nothing more to be done to add Correction to the candidate set.
-  if (RI->getCorrectionDecl() == NewND) {
-if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts()))
-  *RI = Correction;
-return;
-  }
+auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) {
+  return TypoCorr.getCorrectionDecl() == NewND;
+});
+if (RI != CList.end()) {
+  // The Correction refers to a decl already in the list. No insertion is
+  // necessary and all further cases will return.
+
+  auto IsDeprecated = [](Decl *D) {
+while (D) {
+  if (D->isDeprecated())
+return true;
+  D = llvm::dyn_cast_or_null(D->getDeclContext());
+}
+return false;
+  };
+
+  // Prefer non deprecated Corrections over deprecated and only then
+  // sort using an alphabetical order.
+  std::pair NewKey = {
+  IsDeprecated(Correction.getFoundDecl()),
+  Correction.getAsString(SemaRef.getLangOpts())};
+
+  std::pair PrevKey = {
+  IsDeprecated(RI->getFoundDecl()),
+  RI->getAsString(SemaRef.getLangOpts())};
+
+  if (NewKey < PrevKey)
+*RI = Correction;
+  return;
 }
   }
   if (CList.empty() || Correction.isResolved())


Index: clang/test/SemaCXX/typo-correction.cpp
===
--- clang/test/SemaCXX/typo-correction.cpp
+++ clang/test/SemaCXX/typo-correction.cpp
@@ -757,3 +757,34 @@
 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
   };
 }
+
+namespace PR47272
+{
+
+namespace Views {
+int Take(); // expected-note{{'Views::Take' declared here}}
+}
+
+namespace [[deprecated("use Views instead")]] View {
+using Views::Take;
+}
+
+namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}}
+int pr47272;
+}
+
+namespace B {
+using A::pr47272;  // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}}
+}
+
+namespace [[deprecated]] C {
+using A::pr47272;
+}
+
+void function() {
+  int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
+  int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}
+}
+}
+
+
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4307,18 +4307,35 @@
   if (!CList.empty() && !CList.back().isResolved())
 CList.pop_back();
   if (NamedDecl *NewND = Correction.getCorrectionDecl()) {
-std::string CorrectionStr = Correction.getAsStrin

[PATCH] D114787: [clang][PR51931] Enable `-Wdeclaration-after-statement` for all C versions

2022-01-12 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG118f966b46cf: [clang][#51931] Enable 
`-Wdeclaration-after-statement` for all C versions (authored by zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114787

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/warn-mixed-decls.c


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 
-Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ 
-Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with 
standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -410,9 +410,10 @@
ArrayRef Elts, bool isStmtExpr) {
   const unsigned NumElts = Elts.size();
 
-  // If we're in C89 mode, check that we don't have any decls after stmts.  If
-  // so, emit an extension diagnostic.
-  if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) {
+  // If we're in C mode, check that we don't have any decls after stmts.  If
+  // so, emit an extension diagnostic in C89 and potentially a warning in later
+  // versions.
+  if (!getLangOpts().CPlusPlus) {
 // Note that __extension__ can be around a decl.
 unsigned i = 0;
 // Skip over all declarations.
@@ -425,7 +426,8 @@
 
 if (i != NumElts) {
   Decl *D = *cast(Elts[i])->decl_begin();
-  Diag(D->getLocation(), diag::ext_mixed_decls_code);
+  Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code
+: diag::warn_mixed_decls_code);
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9861,8 +9861,11 @@
   "argument to %0 must be a constant integer">;
 
 def ext_mixed_decls_code : Extension<
-  "ISO C90 forbids mixing declarations and code">,
-  InGroup>;
+  "mixing declarations and code is a C99 extension">,
+  InGroup;
+def warn_mixed_decls_code : Warning<
+  "mixing declarations and code is incompatible with standards before C99">,
+  InGroup, DefaultIgnore;
 
 def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -241,6 +241,7 @@
 
 def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
+def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;


Index: clang/test/Sema/warn-mixed-decls.c
===
--- /dev/null
+++ clang/test/Sema/warn-mixed-decls.c
@@ -0,0 +1,28 @@
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s
+ */
+
+/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s
+ */
+/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s
+ */
+
+/* none-no-diagnostics */
+
+int foo(int i)
+{
+  i += 1;
+  int f = i;
+#if __STDC_VERSION__ < 199901L
+  /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/
+#else
+  /* expected-warning@-4 {{mixing declarations and code is incompatible with standards before C99}}*/
+#endif
+  return f;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===

[PATCH] D115576: [clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing'

2021-12-11 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: Szelethus, aaron.ballman, alexfh, hokein, whisperity.
Herald added subscribers: carlosgalvezp, rnkovacs, xazax.hun.
zero9178 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The purpose of this checker is to flag a missing throw keyword, and does so by 
checking for the construction of an exception class that is then unused. 
This works great except that placement new expressions are also flagged as 
those lead to the construction of an object as well, even though they are not 
temporary (as that is dependent on the storage). 
This patch fixes the issue by exempting the match if it is within a 
placement-new.

Fixes https://github.com/llvm/llvm-project/issues/51939


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115576

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -175,3 +175,14 @@
 void exceptionRAIITest() {
   ExceptionRAII E;
 }
+
+namespace std {
+typedef decltype(sizeof(void*)) size_t;
+}
+
+void* operator new(std::size_t, void*);
+
+void placeMentNewTest() {
+  alignas(RegularException) unsigned char expr[sizeof(RegularException)];
+  new (expr) RegularException{};
+}
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -24,11 +24,13 @@
   cxxConstructExpr(
   hasType(cxxRecordDecl(
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-  unless(anyOf(hasAncestor(stmt(
-   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
-   allOf(hasAncestor(CtorInitializerList),
- unless(hasAncestor(cxxCatchStmt()))
+  unless(anyOf(
+  hasAncestor(
+  stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+  hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
+  hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
+  allOf(hasAncestor(CtorInitializerList),
+unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
   this);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -175,3 +175,14 @@
 void exceptionRAIITest() {
   ExceptionRAII E;
 }
+
+namespace std {
+typedef decltype(sizeof(void*)) size_t;
+}
+
+void* operator new(std::size_t, void*);
+
+void placeMentNewTest() {
+  alignas(RegularException) unsigned char expr[sizeof(RegularException)];
+  new (expr) RegularException{};
+}
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -24,11 +24,13 @@
   cxxConstructExpr(
   hasType(cxxRecordDecl(
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-  unless(anyOf(hasAncestor(stmt(
-   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
-   allOf(hasAncestor(CtorInitializerList),
- unless(hasAncestor(cxxCatchStmt()))
+  unless(anyOf(
+  hasAncestor(
+  stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+  hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
+  hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
+  allOf(hasAncestor(CtorInitializerList),
+unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115576: [clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing'

2021-12-15 Thread Markus Böck via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7d55771ce3e: [clang-tidy][#51939] Exempt placement-new 
expressions from 'bugprone-throw… (authored by zero9178).

Changed prior to commit:
  https://reviews.llvm.org/D115576?vs=393671&id=394575#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115576

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -175,3 +175,14 @@
 void exceptionRAIITest() {
   ExceptionRAII E;
 }
+
+namespace std {
+typedef decltype(sizeof(void*)) size_t;
+}
+
+void* operator new(std::size_t, void*);
+
+void placeMentNewTest() {
+  alignas(RegularException) unsigned char expr[sizeof(RegularException)];
+  new (expr) RegularException{};
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -148,6 +148,10 @@
 
 - Fixed a false positive in :doc:`fuchsia-trailing-return
   ` for C++17 deduction guides.
+  
+- Fixed a false positive in :doc:`bugprone-throw-keyword-missing
+  ` when creating an 
exception object
+  using placement new
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -24,11 +24,13 @@
   cxxConstructExpr(
   hasType(cxxRecordDecl(
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-  unless(anyOf(hasAncestor(stmt(
-   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
-   allOf(hasAncestor(CtorInitializerList),
- unless(hasAncestor(cxxCatchStmt()))
+  unless(anyOf(
+  hasAncestor(
+  stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+  hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
+  hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(),
+  allOf(hasAncestor(CtorInitializerList),
+unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
   this);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -175,3 +175,14 @@
 void exceptionRAIITest() {
   ExceptionRAII E;
 }
+
+namespace std {
+typedef decltype(sizeof(void*)) size_t;
+}
+
+void* operator new(std::size_t, void*);
+
+void placeMentNewTest() {
+  alignas(RegularException) unsigned char expr[sizeof(RegularException)];
+  new (expr) RegularException{};
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -148,6 +148,10 @@
 
 - Fixed a false positive in :doc:`fuchsia-trailing-return
   ` for C++17 deduction guides.
+  
+- Fixed a false positive in :doc:`bugprone-throw-keyword-missing
+  ` when creating an exception object
+  using placement new
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -24,11 +24,13 @@
   cxxConstructExpr(
   hasType(cxxRecordDecl(
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
-  unless(anyOf(hasAncestor(stmt(
-   anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
-   allOf(hasAncestor(CtorInitializerList),
- unless(hasAncestor(cxxCatchStmt()))
+  unless(anyOf(
+  hasAncestor(
+  stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))

[PATCH] D115576: [clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing'

2021-12-15 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D115576#3194944 , @aaron.ballman 
wrote:

> LGTM! Can you also add a release note about the fix?

Addressed in the final commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115576

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


[PATCH] D116020: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling

2021-12-20 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: mstorsjo, rnk.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

stdcall name mangling requires a suffix with the number equal to the sum of the 
byte count of all parameter types. In the case of a function prototype that has 
a parameter type of an incomplete type it is impossible to get the size of the 
type. While such a function is not callable or able to be defined in the TU, it 
may still be mangled when generating debug info, which would previously lead to 
a crash. 
This patch fixes that by simply bailing out of the loop and using the so far 
accumulated byte count. This matches GCCs behaviour as well: 
https://github.com/gcc-mirror/gcc/blob/bc8d6c60137f8bbf173b86ddf31b15d7ba2a33dd/gcc/config/i386/winnt.c#L203

Fixes https://github.com/llvm/llvm-project/issues/52782


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116020

Files:
  clang/lib/AST/Mangle.cpp
  clang/test/CodeGen/pr52782-stdcall-func-decl.cpp


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm 
-debug-info-kind=constructor %s
+
+#define NS_IMETHOD_(type) type __stdcall
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  NS_IMETHOD_(nsresult) InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 


Index: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s
+
+#define NS_IMETHOD_(type) type __stdcall
+
+enum nsresult {};
+
+class NotNull;
+
+class nsICanvasRenderingContextInternal {
+  NS_IMETHOD_(nsresult) InitializeWithDrawTarget(NotNull);
+} nsTBaseHashSet;
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -225,11 +225,17 @@
   if (const CXXMethodDecl *MD = dyn_cast(FD))
 if (!MD->isStatic())
   ++ArgWords;
-  for (const auto &AT : Proto->param_types())
+  for (const auto &AT : Proto->param_types()) {
+// If an argument type is incomplete there is no way to get its size to
+// correctly encode into the mangling scheme.
+// Follow GCCs behaviour by simply breaking out of the loop.
+if (AT->isIncompleteType())
+  break;
 // Size should be aligned to pointer size.
 ArgWords +=
 llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
 TI.getPointerWidth(0);
+  }
   Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-16 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked an inline comment as done.
zero9178 added inline comments.



Comment at: llvm/cmake/modules/GetErrcMessages.cmake:3-6
+# The purpose of this function is to supply those error messages to llvm-lit 
using the errc_messages config
+# Currently supplied and needed error codes: ENOENT, EISDIR, EINVAL and EACCES
+# Messages are semi colon separated
+# Keep amount, order and tested error codes in sync with 
llvm/utils/lit/lit/llvm/config.py

jhenderson wrote:
> Each of these lines look like they need a trailing full stop added.
Just to double check, that means adding a `.` at the end of the lines right?



Comment at: llvm/utils/lit/lit/llvm/config.py:14
 lit_path_displayed = False
+python_errc_displayed = False
 

jhenderson wrote:
> Seems like this variable is unused and got leftover from an experiment at 
> some point?
Correct, that was accidently left in. I immediately followed up with a commit 
removing it here: 
https://reviews.llvm.org/rG68e4084bf68ae7517491a6a0cbfd6d3b6f93cef7


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-16 Thread Markus Böck via Phabricator via cfe-commits
zero9178 marked 4 inline comments as done.
zero9178 added a comment.

I addressed your comments in 
https://reviews.llvm.org/rG4a17ac0387f078529da02e355a24df99f645d364. Hope it 
should be alright now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-16 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D98278#2628477 , @uabelho wrote:

> Hi,
>
> I'm seeing a problem with this. Compiling with gcc 9.3.0 the compilation of 
> the test program works, but then when I run it I get
>
>   
> /repo/uabelho/master-github/llvm/build-all-bbigcc/CMakeFiles/CMakeTmp/cmTC_00188:
>  /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by 
> /repo/uabelho/master-github/llvm/build-all-bbigcc/CMakeFiles/CMakeTmp/cmTC_00188)
>
> and this causes everything to fail with
>
>   llvm-lit: 
> /repo/uabelho/master-github/llvm/utils/lit/lit/TestingConfig.py:100: fatal: 
> unable to parse config file 
> '/repo/uabelho/master-github/llvm/build-all-bbigcc/tools/clang/test/lit.site.cfg.py',
>  traceback: Traceback (most recent call last):
> File 
> "/repo/uabelho/master-github/llvm/build-all-bbigcc/bin/../../utils/lit/lit/TestingConfig.py",
>  line 89, in load_from_path
>   exec(compile(data, path, 'exec'), cfg_globals, None)
> File 
> "/repo/uabelho/master-github/llvm/build-all-bbigcc/tools/clang/test/lit.site.cfg.py",
>  line 19
>   config.errc_messages = 
> "/repo/uabelho/master-github/llvm/build-all-bbigcc/CMakeFiles/CMakeTmp/cmTC_00188:
>  /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by 
> /repo/uabelho/master-github/llvm/build-all-bbigcc/CMakeFiles/CMakeTmp/cmTC_00188)
>
> so perhaps there should be some additional error handling when running the 
> compiled program doesn't work?

Could you try changing line 32 of llvm/cmake/modules/GetErrcMessages.cmake from 
`if (errc_compiled)` to `if (errc_compiled AND "${errc_test_code}" STREQUAL 
"0")` and report back if it changes anything? I think that should fix your 
issue, although it'll fall back to using python's strerror messages. Indeed an 
oversight of mine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-16 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D98278#2628527 , @uabelho wrote:

> In D98278#2628482 , @zero9178 wrote:
>
>> In D98278#2628477 , @uabelho wrote:
>>
>>> so perhaps there should be some additional error handling when running the 
>>> compiled program doesn't work?
>>
>> Could you try changing line 32 of llvm/cmake/modules/GetErrcMessages.cmake 
>> from `if (errc_compiled)` to `if (errc_compiled AND "${errc_exit_code}" 
>> STREQUAL "0")` and report back if it changes anything? I think that should 
>> fix your issue, although it'll fall back to using python's strerror 
>> messages. Indeed an oversight of mine.
>
> Yes that helps, please submit. Thanks!

Pushed in https://reviews.llvm.org/rG953bb5e5c8f60dc769942a3615d800fe166ffd1d


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98868: [Driver] Add -print-runtime-dir

2021-03-18 Thread Markus Böck via Phabricator via cfe-commits
zero9178 created this revision.
zero9178 added reviewers: rnk, phosek, MaskRay.
Herald added subscribers: jansvoboda11, dang.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a new command line option to clang which outputs the directory 
containing clangs runtime libraries to stdout.

The primary use case for this command line flag is for build systems using 
clang-cl. Build systems when using clang-cl invoke the linker, that is either 
link or lld-link in this case, directly instead of invoking the compiler for 
the linking process as is common with the other drivers. This leads to issues 
when runtime libraries of clang, such as sanitizers or profiling, have to be 
linked in as the compiler cannot communicate the link directory to the linker.

Using this flag, build systems would be capable of getting the directory 
containing all of clang's runtime libraries and add it to the linker path.

One such implementation is in LLVM's CMake scripts which currently gets the 
path to the builtins library and uses the containing directory. This also has 
issues however when the builtins library does not exist, which AFAIK is not a 
prerequisite to using clang-cl. More info here: https://reviews.llvm.org/D98786


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98868

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/Inputs/resource_dir/lib/windows/clang_rt.builtins-x86_64.lib
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-windows-msvc/clang_rt.builtins.lib
  clang/test/Driver/immediate-options.c


Index: clang/test/Driver/immediate-options.c
===
--- clang/test/Driver/immediate-options.c
+++ clang/test/Driver/immediate-options.c
@@ -17,3 +17,15 @@
 // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown.
 // RUN: %clang -print-resource-dir | FileCheck %s 
-check-prefix=PRINT-RESOURCE-DIR
 // PRINT-RESOURCE-DIR: {{.+}}
+
+// Default resource-dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}windows
+
+// Per target dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s
+// PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1824,6 +1824,15 @@
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
+if (auto RuntimePath = TC.getRuntimePath()) {
+  llvm::outs() << *RuntimePath << '\n';
+  return false;
+}
+llvm::outs() << TC.getCompilerRTPath() << '\n';
+return false;
+  }
+
   // FIXME: The following handlers should use a callback mechanism, we don't
   // know what the client would like to do.
   if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3567,6 +3567,8 @@
   HelpText<"Print the registered targets">;
 def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">,
   HelpText<"Print the paths used for finding ROCm installation">;
+def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">,
+  HelpText<"Print the directory pathname containing clangs runtime libraries">;
 def private__bundle : Flag<["-"], "private_bundle">;
 def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",


Index: clang/test/Driver/immediate-options.c
===
--- clang/test/Driver/immediate-options.c
+++ clang/test/Driver/immediate-options.c
@@ -17,3 +17,15 @@
 // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown.
 // RUN: %clang -print-resource-dir | FileCheck %s -check-prefix=PRINT-RESOURCE-DIR
 // PRINT-RESOURCE-DIR: {{.+}}
+
+// Default resource-dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}windows
+
+// Per target dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s
+// PRINT-RUNTIME-DIR-PER

[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-18 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D98278#2635190 , @ashi1 wrote:

> In D98278#2618936 , @zero9178 wrote:
>
>> In D98278#2616932 , @mstorsjo wrote:
>>
>>> In D98278#2616916 , @zero9178 
>>> wrote:
>>>
 Add GetErrcMessages.cmake, which contains a cmake function to 
 automatically get the error messages of various posix error codes needed 
 by lit by running a small C++ program.
 Currently ENOENT, EISDIR, EINVAL and EACCES are supplied. 
 These error messages are then currently supplied to clang, llvm and lld as 
 the errc_messages config parameter.

 Regarding Cross compiling: the function uses try_run which when cross 
 compiling may use the CMAKE_CROSSCOMPILING_EMULATOR to run the code.
>>>
>>> How does it behave if such a thing isn't hooked up? Ideally it'd fall back 
>>> silently and these parts of tests would just fail, but not block things 
>>> overall.
>>
>> It will fall back to using Python's strerror, potentially failing if pythons 
>> strerror would not return the same strings (only the case for MSVC I 
>> believe).
>
> Hi, this patch is causing a failure when cmake runs `try_run()` with a 
> `CMAKE_TOOLCHAIN_FILE` defined. It seems related to having a fall back if the 
> try_run fails.
> Here is the error, and the build uses MSVC. What do you think we could do 
> about this? Thanks.
>
>   [06:48:06][Step 1/4] CMake Error: TRY_RUN() invoked in cross-compiling 
> mode, please set the following cache variables appropriately:
>   [06:48:06][Step 1/4]errc_exit_code (advanced)
>   [06:48:06][Step 1/4]errc_exit_code__TRYRUN_OUTPUT (advanced)
>   [06:48:06][Step 1/4] For details see /TryRunResults.cmake

Hello! There is actually an ongoing discussion about this here 
https://reviews.llvm.org/D98861. For the time being you have two options if you 
have a cross compiling setup that can't natively run Windows programs.

1. Set CMAKE_CROSSCOMPILING_EMULATOR to an emulator that could execute the 
Windows program on your host. Wine comes to my mind as an example
2. You should be able to set the variables `errc_exit_code` to the value 0 and 
then set `errc_exit_code__TRYRUN_OUTPUT` to the stdout of the Windows program 
(alternatively leave it empty, but a few tests will fail)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98868: [Driver] Add -print-runtime-dir

2021-03-19 Thread Markus Böck 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 rGaafc3f7be804: [Driver] Add -print-runtime-dir (authored by 
zero9178).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98868

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/Inputs/resource_dir/lib/windows/clang_rt.builtins-x86_64.lib
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-windows-msvc/clang_rt.builtins.lib
  clang/test/Driver/immediate-options.c


Index: clang/test/Driver/immediate-options.c
===
--- clang/test/Driver/immediate-options.c
+++ clang/test/Driver/immediate-options.c
@@ -17,3 +17,15 @@
 // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown.
 // RUN: %clang -print-resource-dir | FileCheck %s 
-check-prefix=PRINT-RESOURCE-DIR
 // PRINT-RESOURCE-DIR: {{.+}}
+
+// Default resource-dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}windows
+
+// Per target dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s
+// PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1824,6 +1824,15 @@
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
+if (auto RuntimePath = TC.getRuntimePath()) {
+  llvm::outs() << *RuntimePath << '\n';
+  return false;
+}
+llvm::outs() << TC.getCompilerRTPath() << '\n';
+return false;
+  }
+
   // FIXME: The following handlers should use a callback mechanism, we don't
   // know what the client would like to do.
   if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3566,6 +3566,8 @@
   HelpText<"Print the registered targets">;
 def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">,
   HelpText<"Print the paths used for finding ROCm installation">;
+def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">,
+  HelpText<"Print the directory pathname containing clangs runtime libraries">;
 def private__bundle : Flag<["-"], "private_bundle">;
 def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",


Index: clang/test/Driver/immediate-options.c
===
--- clang/test/Driver/immediate-options.c
+++ clang/test/Driver/immediate-options.c
@@ -17,3 +17,15 @@
 // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown.
 // RUN: %clang -print-resource-dir | FileCheck %s -check-prefix=PRINT-RESOURCE-DIR
 // PRINT-RESOURCE-DIR: {{.+}}
+
+// Default resource-dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}windows
+
+// Per target dir layout
+// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \
+// RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s
+// PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1824,6 +1824,15 @@
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
+if (auto RuntimePath = TC.getRuntimePath()) {
+  llvm::outs() << *RuntimePath << '\n';
+  return false;
+}
+llvm::outs() << TC.getCompilerRTPath() << '\n';
+return false;
+  }
+
   // FIXME: The following handlers should use a callback mechanism, we don't
   // know what the client would like to do.
   if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3566,6 +3566,8 @@
   HelpText<"Print the registered targets">;
 def print_rocm_search_dirs : Flag<

[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-19 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D98278#2637826 , @mstorsjo wrote:

> Btw, while this change does explain _what_ it does, it doesn't actually say 
> the exact reason _why_. Cleanliness? Sure, that's nice... Or is it a case 
> where e.g. some translations produce different error messages?

Now that you mention it, it's indeed not as clear as I thought. But yes, in the 
case of MSVCs STL, the messages from `std::error_codes` which are used by 
various LLVM tools produce different strings then using `strerror` (the C 
function also called by Python) with the same error codes (Specifically, it has 
different casing).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D98278: [test] Add ability to get error messages from CMake for errc substitution

2021-03-20 Thread Markus Böck via Phabricator via cfe-commits
zero9178 added a comment.

In D98278#2638005 , @mstorsjo wrote:

> In D98278#2637866 , @zero9178 wrote:
>
>> In D98278#2637826 , @mstorsjo wrote:
>>
>>> Btw, while this change does explain _what_ it does, it doesn't actually say 
>>> the exact reason _why_. Cleanliness? Sure, that's nice... Or is it a case 
>>> where e.g. some translations produce different error messages?
>>
>> Now that you mention it, it's indeed not as clear as I thought. But yes, in 
>> the case of MSVCs STL, the messages from `std::error_codes` which are used 
>> by various LLVM tools produce different strings then using `strerror` (the C 
>> function also called by Python) with the same error codes (Specifically, it 
>> has different casing).
>
> Ok, but would e.g. a case insensitive comparison have worked instead of this?
>
> And didn't the python script have hardcoded strings, specifically for the 
> MSVC case? Why weren't they written with the right casing for the case that 
> they're supposed to match? I.e. was it an issue with the existing hardcoded 
> strings, or did they work in one case but not another one?

Changes in this patch are based on this one https://reviews.llvm.org/D97472. In 
the discussion there it was deemed not a good solution to use case insensitive 
comparison as that would make any other matches case insensitive as well, which 
might be a source of bugs.

In D98278#2638023 , @mstorsjo wrote:

> In D98278#2637866 , @zero9178 wrote:
>
>> In D98278#2637826 , @mstorsjo wrote:
>>
>>> Btw, while this change does explain _what_ it does, it doesn't actually say 
>>> the exact reason _why_. Cleanliness? Sure, that's nice... Or is it a case 
>>> where e.g. some translations produce different error messages?
>>
>> Now that you mention it, it's indeed not as clear as I thought. But yes, in 
>> the case of MSVCs STL, the messages from `std::error_codes` which are used 
>> by various LLVM tools produce different strings then using `strerror` (the C 
>> function also called by Python) with the same error codes (Specifically, it 
>> has different casing).
>
> Or turning the question another way around: We have a couple different bots 
> that build and run the tests, successfully, with MSVC configurations. Are 
> there tests that failed for you in your configuration, that succeed in the 
> setup of the bots? Or are there other tests that aren't run as part of bots 
> that you're fixing? It's all still very vague to me.

Prior to this patch it worke with an MSVC configuration already as the strings 
were correctly hardcoded for the MSVC STL. Problem was when using any other 
compiler configuration on Windows. In my case I am using your llvm-mingw 
distribution to build all of LLVM and since it uses libc++ it produces 
different error messages from the one in MSVC STL. I observed the same problem 
when using GCC on Windows and if one were to theoretically use libc++ with 
clang-cl in a MSVC environment, tests would be failing as well due to a 
mismatch in error strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98278

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


[PATCH] D108720: Effectively revert 33c3d8a916c / D33782

2021-08-25 Thread Markus Böck via Phabricator via cfe-commits
zero9178 accepted this revision.
zero9178 added a comment.

Thanks a lot for the patch :) Wanted this bit of code to be removed for quite 
some time.

> Since D103773 , clang-cl's default mode 
> completely disables C++ operator
> names. That means that query.h compiles out of the box without this hack
> in the pre-processor. For users who are using /permissive-, they must
> set the QUERY_H_RESTRICTION_PERMISSIVE macro to rename this problematic
> or field.

Just a heads up, the patch added `/permissive` and `/permissive-`, but made 
neither the default as to not be a breaking change. That means that clang-cl 
still parses operator keywords and also does delayed template parsing, as it 
did before the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108720

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