[clang] 7ac658a - [WebAssembly] assert(false) -> llvm_unreachable

2023-02-18 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-02-18T09:38:18+01:00
New Revision: 7ac658a07b9a2937f1a9319a47a9cec6afae2370

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

LOG: [WebAssembly] assert(false) -> llvm_unreachable

Avoids warnings in -asserts builds.

ASTContext.cpp:4098:1: error: non-void function does not return a value in all 
control paths [-Werror,-Wreturn-type]
}
^

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a22c21779e1c..9b0d7b2b4b5a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4093,8 +4093,8 @@ QualType ASTContext::getWebAssemblyExternrefType() const {
 return SingletonId;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
   }
-  assert(false &&
- "shouldn't try to generate type externref outside WebAssembly 
target");
+  llvm_unreachable(
+  "shouldn't try to generate type externref outside WebAssembly target");
 }
 
 /// getScalableVectorType - Return the unique reference to a scalable vector



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


[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeGen/enum2.c:30
+// CHECK: ![[E]] = !DIEnumerator(name: "b0", value: 
24197857203266734864629346612071973665, isUnsigned: true)
+

delete the trailing blank line


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

https://reviews.llvm.org/D144157

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


[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-18 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 498571.
zhouyizhou added a comment.

delete the trailing blank line

Thank you all ;-)

I have no access write to LLVM, could you commit it for me when you are not 
busy?

Thanks a lot
Cheers
Zhouyi

Zhouyi Zhou 


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

https://reviews.llvm.org/D144157

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/enum2.c
  clang/test/Sema/enum.c


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify 
-pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator 
values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // 
expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts 
enumerator values to range of 'int'}}
   C = -4, D = 12456 };
Index: clang/test/CodeGen/enum2.c
===
--- clang/test/CodeGen/enum2.c
+++ clang/test/CodeGen/enum2.c
@@ -1,15 +1,29 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited 
-emit-llvm -o - | FileCheck %s
 
 int v;
 enum e { MAX };
+enum b {
+   b0 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL,
+};
+__uint128_t v1;
 
 void foo (void)
 {
   v = MAX;
+  // CHECK: store i32 0, ptr @v, align 4
+  v1 = b0;
+  // CHECK: store i128 24197857203266734864629346612071973665, ptr @v1, align 
16
 }
+
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-SAME: baseType: ![[LONG:[0-9]+]]
 // CHECK-SAME: elements: ![[ELTS:[0-9]+]]
 // CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: 
DW_ATE_unsigned)
 // CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
 // CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[BTYPE:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[BTYPE]] = !DIBasicType(name: "unsigned __int128", size: 128, 
encoding: DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[E:[0-9]+]]}
+// CHECK: ![[E]] = !DIEnumerator(name: "b0", value: 
24197857203266734864629346612071973665, isUnsigned: true)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19568,9 +19568,6 @@
 return;
   }
 
-  // TODO: If the result value doesn't fit in an int, it must be a long or long
-  // long value.  ISO C does not support this, but GCC does as an extension,
-  // emit a warning.
   unsigned IntWidth = Context.getTargetInfo().getIntWidth();
   unsigned CharWidth = Context.getTargetInfo().getCharWidth();
   unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
@@ -19690,14 +19687,24 @@
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongTy : Context.LongTy;
-} else {
+} else if (NumPositiveBits <= Context.getTargetInfo().getLongLongWidth()) {
   BestWidth = Context.getTargetInfo().getLongLongWidth();
-  assert(NumPositiveBits <= BestWidth &&
- "How could an initializer get larger than ULL?");
   BestType = Context.UnsignedLongLongTy;
   BestPromotionType
 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
? Context.UnsignedLongLongTy : Context.LongLongTy;
+} else {
+  BestWidth = 128;
+  assert(NumPositiveBits <= BestWidth &&
+ "How could an initializer get larger than 128-bit?");
+  assert(Context.getTargetInfo().hasInt128Type() &&
+ "How could an initializer get larger than ULL in target without "
+ "128-bit interger type support?");
+  BestType = Context.UnsignedInt128Ty;
+  BestPromotionType =
+  (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
+  ? Context.UnsignedInt128Ty
+  : Context.Int128Ty;
 }
   }
 


Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -1,4 +1,9 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
+enum b {
+   b0 = (__uint128_t)-1, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+   b1 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL, // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+};
+
 enum e {A,
 B = 42LL << 32,// expected-warning {{ISO C restricts

[PATCH] D143825: [clang-format] Put ports on separate lines in Verilog module headers

2023-02-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2665
+if (Style.isVerilog() && Precedence == prec::Comma &&
+VerilogFirstOfType != nullptr) {
+  addFakeParenthesis(VerilogFirstOfType, prec::Comma);

And other places as well.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2808
+FormatToken *PreviousComma) {
+if (Current == nullptr)
+  return nullptr;

And other places too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143825

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 498573.
cor3ntin marked 2 inline comments as done.
cor3ntin added a comment.

- Reword Release note
- Restore dependent instantiation tests using Richard's suggestion
- Add additional test to check that diagnostics for static_assert are emitted 
once per instantiation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/SemaCXX/access-base-class.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.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
@@ -14915,7 +14915,7 @@
 https://wg21.link/cwg2518";>2518
 review
 Conformance requirements and #error/#warning
-Not resolved
+Clang 17
   
   
 https://wg21.link/cwg2519";>2519
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -37,8 +37,8 @@
   template using indirect_void_t = typename indirect_void_t_imp::type;
 
   template void foo() {
-static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+int check1[__is_void(indirect_void_t) == 0 ? 1 : -1]; // "ok", dependent
+int check2[__is_void(void_t) == 0 ? 1 : -1]; // expected-error {{array with a negative size}}
   }
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,9 +31,9 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note {{evaluates to '1 == 0'}}
+int check[a == 0 ? 1 : -1]; // expected-error {{array with a negative size}}
   }
+
 }
 
 namespace PR24483 {
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -52,9 +52,11 @@
 
 template struct AlwaysFails {
   // Only give one error here.
-  static_assert(false, ""); // expected-error {{static assertion failed}}
+  static_assert(false, ""); // expected-error 2{{static assertion failed}}
 };
-AlwaysFails alwaysFails;
+AlwaysFails alwaysFails; // expected-note {{instantiation}}
+AlwaysFails alwaysFails2; // expected-note {{instantiation}}
+
 
 template struct StaticAssertProtected {
   static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}}
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1309,7 +1309,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1288,7 +1288,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/access-base-class.cpp
===
--- clang/test/SemaCXX/access-base-class.cpp
+++ clang/test/SemaCXX/access-base-class.cpp
@@ -96,14 +96,14 @@
 };
 
 template 
-struct trait : flag {};
+struct trait : flag {}; // expected-note 2{{here}}
 
-template ::value>
+template ::value> // expected-note {{here}}
 struct a {};
 
 template 
 class b {
-  a x;
+  a x; // expected-note {{here}}
   using U = a;
 };
 
@@ -113,5 +113,5 @@
 };
 
 // verify "no member named 'value'" bogus diagnostic is not emitte

[PATCH] D144157: Add 128-bit integer support to enum element

2023-02-18 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:19571-19573
-  // TODO: If the result value doesn't fit in an int, it must be a long or long
-  // long value.  ISO C does not support this, but GCC does as an extension,
-  // emit a warning.

That comment is still relevant AFAICT, at least partially (the ISO C 
restrictions are still there, GCC still extends it)


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

https://reviews.llvm.org/D144157

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


[PATCH] D143112: [clang] Support parsing comments without ASTContext

2023-02-18 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 498586.
tom-anders added a comment.
Herald added a subscriber: arphaman.
Herald added a project: clang-tools-extra.

- Move to free function in CodeCompletionStrings.h
- Add back comment markers before parsing (Index stores comments without 
markers, but the comment lexer expects them)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143112

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang/include/clang/Basic/SourceManager.h


Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1944,7 +1944,7 @@
 };
 
 /// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
-/// single in-memorty file.
+/// single in-memory file.
 class SourceManagerForFile {
 public:
   /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).
Index: clang-tools-extra/clangd/CodeCompletionStrings.h
===
--- clang-tools-extra/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -19,6 +19,11 @@
 namespace clang {
 class ASTContext;
 
+namespace comments {
+class CommandTraits;
+class FullComment;
+} // namespace comments
+
 namespace clangd {
 
 /// Gets a minimally formatted documentation comment of \p Result, with comment
@@ -61,6 +66,12 @@
 /// is usually the return type of a function.
 std::string getReturnType(const CodeCompletionString &CCS);
 
+/// Parse the \p Comment, storing the result in \p Allocator, assuming
+/// that comment markers have already been stripped (e.g. via getDocComment())
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator &Allocator,
+comments::CommandTraits &Traits);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -8,6 +8,9 @@
 
 #include "CodeCompletionStrings.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentLexer.h"
+#include "clang/AST/CommentParser.h"
+#include "clang/AST/CommentSema.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -279,5 +282,26 @@
   return "";
 }
 
+comments::FullComment *parseComment(llvm::StringRef Comment,
+llvm::BumpPtrAllocator &Allocator,
+comments::CommandTraits &Traits) {
+  // The comment lexer expects markers, so add them back
+  auto CommentWithMarkers = "/*" + Comment.str() + "*/";
+
+  SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers);
+  SourceManager &SourceMgr = SourceMgrForFile.get();
+
+  comments::Lexer L(Allocator, SourceMgr.getDiagnostics(), Traits,
+SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+CommentWithMarkers.data(),
+CommentWithMarkers.data() + CommentWithMarkers.size());
+  comments::Sema S(Allocator, SourceMgr, SourceMgr.getDiagnostics(), Traits,
+   nullptr);
+  comments::Parser P(L, S, Allocator, SourceMgr, SourceMgr.getDiagnostics(),
+ Traits);
+
+  return P.parseFullComment();
+}
+
 } // namespace clangd
 } // namespace clang


Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1944,7 +1944,7 @@
 };
 
 /// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
-/// single in-memorty file.
+/// single in-memory file.
 class SourceManagerForFile {
 public:
   /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).
Index: clang-tools-extra/clangd/CodeCompletionStrings.h
===
--- clang-tools-extra/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -19,6 +19,11 @@
 namespace clang {
 class ASTContext;
 
+namespace comments {
+class CommandTraits;
+class FullComment;
+} // namespace comments
+
 namespace clangd {
 
 /// Gets a minimally formatted documentation comment of \p Result, with comment
@@ -61,6 +66,12 @@
 /// is usually the return type of a function.
 std::string getReturnType(const CodeCompletionString &CCS);
 
+/// Parse the \p Comment, storing the result in \p Allocator, assuming
+/// that comment markers have already been stripped (

[PATCH] D143112: [clang] Support parsing comments without ASTContext

2023-02-18 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders marked an inline comment as done.
tom-anders added inline comments.



Comment at: clang/lib/AST/RawCommentList.cpp:227
+  
SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()),
+  Allocator, SourceMgr.getDiagnostics(), Traits);
+}

kadircet wrote:
> tom-anders wrote:
> > I wasn't sure if it's worth making the `Diagnostics` parameter optional 
> > here - Our `SourceMgr` already has it anyway, does it impact performance 
> > significantly to use it, even though we don't need it (yet)?
> as things stand, Lexer, Sema and Parser expect a non-null diagnosticsengine 
> so we have to pass something (i guess that's what you meant by making it 
> optional).
> 
> the performance implications comes from two places:
> 1- extra analysis being performed in the face of malformed comments to 
> produce "useful" diagnostics
> 2- creation cost of diagnostic itself, as all the data about ranges, decls 
> etc. are copied around when constructing a diagnostic.
> 
> i don't know how costly the first action is today, it's unfortunately the 
> case that would require a lot of code changes, if it's happening quite often 
> in practice (especially when we're in codebases without proper doxygen 
> comments)
> the latter is somewhat easier to address by providing our own "mock" 
> diagnostics engine, that'll just drop all of these extra diagnostic data on 
> the floor instead of copying around.
> 
> i think taking a look at the codebase for the first (searching for `Diag(...) 
> <<` patterns in Comment{Lexer,Sema,Parser}.cpp should give some ideas) and 
> assessing whether we're performing any extra complicated analysis would be a 
> good start. i would expect us not to, and if that's the case i think we can 
> leave it at that and don't try to make code changes.
> the latter we can address easily and we should.
1 - At first glance it indeed seems like there's no significant extra analysis 
performed, so I think we're good for now.
2 - I think this is already taken care of by `SourceManagerForFile` which just 
passes `nullptr` as the `DiagnosticConsumer`, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143112

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D141569#4136493 , @ccotter wrote:

> @PiotrZSL I added an option to allow disabling the strict behavior. It should 
> address many of your examples (e.g., moving subobjects) . Let me know if you 
> have more feedback.

I will re-test this on Monday/Tuesday. and comeback to you if I find something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D115103: Leak Sanitizer port to Windows

2023-02-18 Thread Clemens Wasser via Phabricator via cfe-commits
clemenswasser added a comment.

I am currently unable to progress as all of my interceptors are not working.
The interceptors are failing, because the `GetInstructionSize` function fails.
For example, the `CreateThread` Win32 function starts on my Windows 11 
installation with `4c 8b dc mov r11,rsp` (in little-endian hex: `0xdc8b4c`).
I get this exact value when using the Visual Studio Watch Window with the 
expression: `0x00FF & *(uint32_t*)address` while debugging 
`GetInstructionSize`.
This was then verified by me again in the Visual Studio Disassembly View of 
`CreateThread` and a third time via this simple test program:

  #include 
  #include 
  #include 
  int main() {
auto* ptr = CreateThread;
printf("CreateThread: %p\n", ptr);
printf("CreateThread first bytes: %s\n", 
std::to_string(*(int*)ptr).c_str());
  }

This exact instruction is correctly handled by the following switch in 
`GetInstructionSize`:

  switch (0x00FF & *(u32*)address) {
...
case 0xdc8b4c:// 4c 8b dc : mov r11, rsp
  return 3;

But `GetInstructionSize` never returns 3 as the switch condition reads 
`0xdc8bcc` from address which is != `0xdc8b4c` and instead encodes:

  0:  cc  int3
  1:  8b dc   movebx,esp

I don't really understand why this would read this **obviously wrong** value 
when my similar test program reads it correctly.
Does anyone of you know why this might be happening and how I could fix this?
(BTW. Asan also intercepts CreateThreads and that seems to work...)


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

https://reviews.llvm.org/D115103

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


[PATCH] D144136: Add a "remark" to report on array accesses

2023-02-18 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

This appears to be working for me. For before/after changes, the other half is 
still needed, i.e. a "accessing array of unknown size" and eventually splitting 
the dynamic sizing check off of that one (once -fsanitize=bounds checks 
__builtin_dynamic_object_size).

For example, comparing various development builds over time, if some source had 
49 array accesses:

initial code: fixed:5 unknown:44
code refactored: fixed:10 unknown:39
bdos added to bounds checker: fixed:10 dynamic:4 unknown:35
code refactoring: fixed:10 dynamic:28 unknown:11


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144136

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


[PATCH] D144136: Add a "remark" to report on array accesses

2023-02-18 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

Here's a test-case. I'd expect 6 remarks from building this:

  /* Build with -Wall -O2 -fstrict-flex-arrays=3 -fsanitize=bounds 
-Rarray-bounds */
  #include 
  #include 
  #include 
  #include 
  
  #define report_size(p, index)  do {\
  const size_t bdos = __builtin_dynamic_object_size(p, 1); \
  \
  if (__builtin_constant_p(bdos)) { \
  if (bdos == SIZE_MAX) { \
  printf(#p " has unknowable size\n"); \
  } else { \
  printf(#p " has a fixed size: %zu\n", bdos); \
  } \
  } else { \
  printf(#p " has a dynamic size: %zu\n", bdos); \
  } \
  printf(#p "[" #index "] assignment: %d\n", (p)[index] = 15); \
  } while (0)
  
  struct fixed {
  unsigned long flags;
  size_t foo;
  int array[16];
  };
  
  /* should emit "fixed" */
  void do_fixed(struct fixed *p, int index)
  {
  report_size(p->array, 0);
  report_size(p->array, index);
  }
  
  struct flex {
  unsigned long flags;
  size_t foo;
  int array[];
  };
  
  /* should emit "dynamic" */
  void do_dynamic(unsigned char count, int index)
  {
  /* malloc() is marked with __attribute__((alloc_size(1))) */
  struct flex *p = malloc(sizeof(*p) + count * sizeof(*p->array));
  report_size(p->array, 0);
  report_size(p->array, index);
  free(p);
  }
  
  /* should emit "unknowable" */
  void do_unknown(struct flex *p, int index)
  {
  report_size(p->array, 0);
  report_size(p->array, index);
  }

Currently, it only emits once for the compile-time known index with a 
compile-time known array size:

  array.c:31:17: remark: accessing fixed sized array 'int[16]' by 0 
[-Rarray-bounds]  
  report_size(p->array, 0); 
  ^ 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144136

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


[PATCH] D144320: [Clang][OpenMP] Update tests using update_cc_test_checks.py

2023-02-18 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 498610.
tianshilei1992 added a comment.

unify check prefix(es)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144320

Files:
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp

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


[PATCH] D144317: [clang-format] Fix handling of TypeScript tuples with optional last member

2023-02-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan added reviewers: krasimir, HazardyKnusperkeks, rymiel.
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTestJS.cpp:2826
+TEST_F(FormatTestJS, TupleTypeWithOptionalLastElement) {
+  verifyFormat("type T = [number?];");
+}

Can you move it into the `OptionalTypes` test above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144317

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


[clang] c31bc7b - [clang-format] Handle tabs in file path for git-clang-format

2023-02-18 Thread Owen Pan via cfe-commits

Author: Michael Kirk
Date: 2023-02-18T12:56:46-08:00
New Revision: c31bc7bdf8108fae490585763bf69a1b51327954

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

LOG: [clang-format] Handle tabs in file path for git-clang-format

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 054978c3dbdf3..695545d9e3255 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -347,7 +347,7 @@ def extract_lines(patch_file):
 line = convert_string(line)
 match = re.search(r'^\+\+\+\ [^/]+/(.*)', line)
 if match:
-  filename = match.group(1).rstrip('\r\n')
+  filename = match.group(1).rstrip('\r\n\t')
 match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
 if match:
   start_line = int(match.group(1))



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


[PATCH] D126365: [git-clang-format] Stop ignoring changes for files with space in path

2023-02-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan closed this revision.
owenpan added a comment.

Landed in c31bc7bdf810 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126365

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


[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: clang-language-wg, aaron.ballman, rsmith, nikic.
Herald added a subscriber: StephenFan.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang already supports assumes for optimizing. Now it is standardized
in C++2b via a new attribute - https://wg21.link/p1774r8.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144334

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
  clang/test/CodeGenCXX/cxx2b-assume.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1501,7 +1501,7 @@
 
   Portable assumptions
   https://wg21.link/P1774R8";>P1774R8
-  No
+  Clang 17
 
 
   Support for UTF-8 as a portable source file encoding
Index: clang/test/CodeGenCXX/cxx2b-assume.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-assume.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -disable-llvm-passes -DUSE_ASSUME | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 | FileCheck --check-prefixes=CHECK-OPT-NOASSUME %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 -DUSE_ASSUME | FileCheck --check-prefixes=CHECK-OPT %s
+
+// CHECK-LABEL: @_Z12divide_by_32i
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %x, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp sge i32 %0, 0
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[DIV:.*]] = sdiv i32 %1, 32
+// CHECK-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   %[[DIV:.*]] = sdiv i32 %x, 32
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp sgt i32 %x, -1
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   %[[DIV:.*]] = lshr i32 %x, 5
+// CHECK-OPT-NEXT:   ret i32 %[[DIV]]
+//
+int divide_by_32(int x) {
+#ifdef USE_ASSUME
+[[assume(x >= 0)]];
+#endif
+return x/32;
+}
+
+// CHECK-LABEL: @_Z9incrementi
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %y, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[VARP1:.*]] = add nsw i32 %0, 1
+// CHECK-NEXT:   store i32 %[[VARP1]], ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp eq i32 %[[VARP1]], 43
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   ret i32 %1
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z9incrementi
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %y
+//
+// CHECK-OPT-LABEL: @_Z9incrementi
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp eq i32 %y, 42
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   ret i32 43
+//
+int increment(int y) {
+#ifdef USE_ASSUME
+[[assume(++y == 43)]];
+#endif
+return y;
+}
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c++2b -verify %s
+
+int divide_by_32(int x) {
+[[assume(x >= 0)]];
+return x/32;
+}
+
+int increment(int y) {
+[[assume(++y == 43)]];
+return y;
+}
+
+[[assume(true)]] int incorrects(int y) { // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] int x = 0; // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] x = 0; // expected-error {{'assume' attribute only applies to empty statements}}
+[[assume(++y == 43 && ++y == 44)]];
+[[assume(++y == 43, ++y == 43)]]; // expected-error {{'assume' attribute takes one argument}}
+[[assume]]; // expected-error {{'assume' attribute takes one argument}}
+return y;
+}
Index: clang/test/AST/ast-dump-attr.cpp
===

[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 498622.
Izaron added a comment.

A small fix for `def FutureAttrs`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144334

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
  clang/test/CodeGenCXX/cxx2b-assume.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1501,7 +1501,7 @@
 
   Portable assumptions
   https://wg21.link/P1774R8";>P1774R8
-  No
+  Clang 17
 
 
   Support for UTF-8 as a portable source file encoding
Index: clang/test/CodeGenCXX/cxx2b-assume.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-assume.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -disable-llvm-passes -DUSE_ASSUME | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 | FileCheck --check-prefixes=CHECK-OPT-NOASSUME %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 -DUSE_ASSUME | FileCheck --check-prefixes=CHECK-OPT %s
+
+// CHECK-LABEL: @_Z12divide_by_32i
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %x, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp sge i32 %0, 0
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[DIV:.*]] = sdiv i32 %1, 32
+// CHECK-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   %[[DIV:.*]] = sdiv i32 %x, 32
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp sgt i32 %x, -1
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   %[[DIV:.*]] = lshr i32 %x, 5
+// CHECK-OPT-NEXT:   ret i32 %[[DIV]]
+//
+int divide_by_32(int x) {
+#ifdef USE_ASSUME
+[[assume(x >= 0)]];
+#endif
+return x/32;
+}
+
+// CHECK-LABEL: @_Z9incrementi
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %y, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[VARP1:.*]] = add nsw i32 %0, 1
+// CHECK-NEXT:   store i32 %[[VARP1]], ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp eq i32 %[[VARP1]], 43
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   ret i32 %1
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z9incrementi
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %y
+//
+// CHECK-OPT-LABEL: @_Z9incrementi
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp eq i32 %y, 42
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   ret i32 43
+//
+int increment(int y) {
+#ifdef USE_ASSUME
+[[assume(++y == 43)]];
+#endif
+return y;
+}
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c++2b -verify %s
+
+int divide_by_32(int x) {
+[[assume(x >= 0)]];
+return x/32;
+}
+
+int increment(int y) {
+[[assume(++y == 43)]];
+return y;
+}
+
+[[assume(true)]] int incorrects(int y) { // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] int x = 0; // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] x = 0; // expected-error {{'assume' attribute only applies to empty statements}}
+[[assume(++y == 43 && ++y == 44)]];
+[[assume(++y == 43, ++y == 43)]]; // expected-error {{'assume' attribute takes one argument}}
+[[assume]]; // expected-error {{'assume' attribute takes one argument}}
+return y;
+}
Index: clang/test/AST/ast-dump-attr.cpp
===
--- clang/test/AST/ast-dump-attr.cpp
+++ clang/test/AST/ast-dump-attr.cpp
@@ -259,3 +259,14 @@
 // CHECK-NEXT: AnnotateAttr{{.*}} Inherited
 // CHECK-NEXT: UnusedAttr
 // CHECK-NEXT: NoThreadSafetyAnalysisAttr
+
+namespace TestAssume {
+  in

[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1448
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Documentation = [AssumeDocs];

Honestly I don't have a clue what these numbers `202302` (apparently the 
`mm` format) would mean :( I'd be grateful if you could help me with the 
right value for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144334

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


[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1448
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Documentation = [AssumeDocs];

Izaron wrote:
> Honestly I don't have a clue what these numbers `202302` (apparently the 
> `mm` format) would mean :( I'd be grateful if you could help me with the 
> right value for this.
https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
 has generally the correct values for this. In this case it's `202207`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144334

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


[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 498625.
Izaron added a comment.

More thorough AST test.

Set the right macros number - thanks to @philnik!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144334

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
  clang/test/CodeGenCXX/cxx2b-assume.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1501,7 +1501,7 @@
 
   Portable assumptions
   https://wg21.link/P1774R8";>P1774R8
-  No
+  Clang 17
 
 
   Support for UTF-8 as a portable source file encoding
Index: clang/test/CodeGenCXX/cxx2b-assume.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-assume.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -disable-llvm-passes -DUSE_ASSUME | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 | FileCheck --check-prefixes=CHECK-OPT-NOASSUME %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - -triple x86_64-linux-gnu -O3 -DUSE_ASSUME | FileCheck --check-prefixes=CHECK-OPT %s
+
+// CHECK-LABEL: @_Z12divide_by_32i
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %x, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp sge i32 %0, 0
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[DIV:.*]] = sdiv i32 %1, 32
+// CHECK-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   %[[DIV:.*]] = sdiv i32 %x, 32
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %[[DIV]]
+//
+// CHECK-OPT-LABEL: @_Z12divide_by_32i
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp sgt i32 %x, -1
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   %[[DIV:.*]] = lshr i32 %x, 5
+// CHECK-OPT-NEXT:   ret i32 %[[DIV]]
+//
+int divide_by_32(int x) {
+#ifdef USE_ASSUME
+[[assume(x >= 0)]];
+#endif
+return x/32;
+}
+
+// CHECK-LABEL: @_Z9incrementi
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %[[VAR:.*]] = alloca i32, align 4
+// CHECK-NEXT:   store i32 %y, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %0 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[VARP1:.*]] = add nsw i32 %0, 1
+// CHECK-NEXT:   store i32 %[[VARP1]], ptr %[[VAR]], align 4
+// CHECK-NEXT:   %[[CMP:.*]] = icmp eq i32 %[[VARP1]], 43
+// CHECK-NEXT:   call void @llvm.assume(i1 %[[CMP]])
+// CHECK-NEXT:   %1 = load i32, ptr %[[VAR]], align 4
+// CHECK-NEXT:   ret i32 %1
+//
+// CHECK-OPT-NOASSUME-LABEL: @_Z9incrementi
+// CHECK-OPT-NOASSUME-NEXT: entry:
+// CHECK-OPT-NOASSUME-NEXT:   ret i32 %y
+//
+// CHECK-OPT-LABEL: @_Z9incrementi
+// CHECK-OPT-NEXT: entry:
+// CHECK-OPT-NEXT:   %[[CMP:.*]] = icmp eq i32 %y, 42
+// CHECK-OPT-NEXT:   tail call void @llvm.assume(i1 %[[CMP]])
+// CHECK-OPT-NEXT:   ret i32 43
+//
+int increment(int y) {
+#ifdef USE_ASSUME
+[[assume(++y == 43)]];
+#endif
+return y;
+}
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.assume/p1.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c++2b -verify %s
+
+int divide_by_32(int x) {
+[[assume(x >= 0)]];
+return x/32;
+}
+
+int increment(int y) {
+[[assume(++y == 43)]];
+return y;
+}
+
+[[assume(true)]] int incorrects(int y) { // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] int x = 0; // expected-error {{'assume' attribute cannot be applied to a declaration}}
+[[assume(++y == 43)]] x = 0; // expected-error {{'assume' attribute only applies to empty statements}}
+[[assume(++y == 43 && ++y == 44)]];
+[[assume(++y == 43, ++y == 43)]]; // expected-error {{'assume' attribute takes one argument}}
+[[assume]]; // expected-error {{'assume' attribute takes one argument}}
+return y;
+}
Index: clang/test/AST/ast-dump-attr.cpp
===
--- clang/test/AST/ast-dump-attr.cpp
+++ clang/test/AST/ast-dump-attr.cpp
@@ -259,3 +259,18 @@
 // CHECK-NEXT: AnnotateAttr{{.*}} Inherited
 // CHECK-NEXT: UnusedAttr
 // CHECK-NEXT: NoThreadSafetyAna

[PATCH] D144334: [Clang] Add C++2b attribute [[assume(expression)]]

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

If you are not familiar with the `[[assume(expr]]` concept and want to know 
more, I wrote a small article about it recently, with a lot of additional links 
(including to the author of the proposal) - 
https://izaron.github.io/posts/assume/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144334

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


[PATCH] D118743: [clang-tidy] Add `modernize-use-inline-const-variables-in-headers` check

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 498637.
Izaron added a comment.

Use the common `isInAnonymousNamespace` matcher.

Split the test into two files.

Thanks to @carlosgalvezp for advices!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118743

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/UseInlineConstVariablesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseInlineConstVariablesInHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize/use-inline-const-variables-in-headers.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-extern.hpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-non-inline.hpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-non-inline.hpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-non-inline.hpp
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy %s -std=c++17 modernize-use-inline-const-variables-in-headers %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: modernize-use-inline-const-variables-in-headers.CheckNonInline, value: true}, \
+// RUN:  {key: modernize-use-inline-const-variables-in-headers.CheckExtern, value: false}]}"
+
+const int ConstFoo = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: global constant 'ConstFoo' should be marked as 'inline' [modernize-use-inline-const-variables-in-headers]
+// CHECK-FIXES: {{^}}inline const int ConstFoo = 1;{{$}}
+
+namespace N {
+constexpr int NamespaceFoo = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: global constant 'NamespaceFoo' should be marked as 'inline' [modernize-use-inline-const-variables-in-headers]
+// CHECK-FIXES: {{^}}inline constexpr int NamespaceFoo = 1;{{$}}
+} // namespace N
+
+struct S {
+  // no warning: the variable is not at file scope
+  static const int StructFoo = 1;
+};
+
+// no warning: non-const global variables have external linkage
+int NonConstFoo = 1;
+
+// no warning: volatile global variables have external linkage
+const volatile int VolatileFoo = 1;
+
+// no warning: templates and their instantiations have external linkage
+template 
+const auto TemplateFoo = sizeof(T);
+
+// no warning: already fixed
+inline const int InlineFoo = 1;
+
+// no warning: C has no 'inline variables'
+extern "C" {
+const int CFoo0 = 1;
+}
+
+// no warning: 'inline' is invisible when within an unnamed namespace
+namespace {
+const int AnonNamespaceFoo = 1;
+} // namespace
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-extern.hpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers-extern.hpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s -std=c++17 modernize-use-inline-const-variables-in-headers %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: modernize-use-inline-const-variables-in-headers.CheckNonInline, value: false}, \
+// RUN:  {key: modernize-use-inline-const-variables-in-headers.CheckExtern, value: true}]}"
+
+extern const int ExternFoo;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: global constant 'ExternFoo' should be converted to C++17 'inline variable' [modernize-use-inline-const-variables-in-headers]
+
+// no warning: C has no 'inline variables'
+extern "C" const int CFoo1 = 1;
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-inline-const-variables-in-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-inline-const-variables-in-headers.rst
@@ -0,0 +1,68 @@
+.. title:: clang-tidy - modernize-use-inline-const-variables-in-headers
+
+modernize-use-inline-const-variables-in-headers
+===
+
+Suggests switching to C++17 ``inline variables`` for non-inline const
+variable definitions and extern const variable declarations in header files.
+Non-inline const variables make a separate instance of the variable for each
+translation unit that includes the header, which can lead to subtle violation
+of the ODR. Extern const variables are a deprecated way to define a constant
+since C++17.
+
+.. code-block:: c++
+
+   // Foo.h
+   const int ConstFoo = 1; // Warning: should be marked as 'inline'
+
+   namespace N {
+ constexpr int NamespaceFoo = 1; // Warning: should be marked as 'inline'
+   }
+
+   extern const int ExternFoo; // Warnin

[PATCH] D118743: [clang-tidy] Add `modernize-use-inline-const-variables-in-headers` check

2023-02-18 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron marked 2 inline comments as done.
Izaron added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-inline-const-variables-in-headers.hpp:1
+// RUN: %check_clang_tidy %s -std=c++17 
modernize-use-inline-const-variables-in-headers %t
+

carlosgalvezp wrote:
> Should tests be added for the `CheckNonInline` and `CheckExtern` options?
I decided to split the test into two files as it is done for other checkers 
that have multiple options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118743

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


[PATCH] D144321: [PowerPC] Correctly use ELFv2 ABI on all OS's that use the ELFv2 ABI

2023-02-18 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 498642.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144321

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
  llvm/test/CodeGen/PowerPC/pr47373.ll


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-musl < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd12 < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-openbsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -237,7 +237,11 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-return PPCTargetMachine::PPC_ABI_ELFv1;
+if ((TT.isOSFreeBSD() && (TT.getOSVersion().empty() ||
+  TT.getOSMajorVersion() >= 13)) || TT.isOSOpenBSD() || TT.isMusl())
+  return PPCTargetMachine::PPC_ABI_ELFv2;
+else
+  return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
   }
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -427,7 +427,12 @@
   ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
-  ABI = "elfv1";
+  if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
+  Triple.getOSMajorVersion() >= 13)) || Triple.isOSOpenBSD() ||
+  Triple.isMusl())
+ABI = "elfv2";
+  else
+ABI = "elfv1";
 }
 
 if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) {


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-musl < %s | FileCheck %s -check-prefix=CHECK-ELFv2
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd12 < %s | FileC

[PATCH] D144232: [PowerPC] Correctly use ELFv2 ABI on FreeBSD/powerpc64

2023-02-18 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In D144232#4136787 , @brad wrote:

> I noticed this review. I have provided a more complete diff for review at 
> D144321 .

Yeah I think that is probably the better option, hope @pkubaj and @adalava 
agree with that?

As Brad's version covers both FreeBSD and OpenBSD, and also updates a bunch of 
unit tests, which this review appears to break (see the Unit Tests 
https://reviews.llvm.org/harbormaster/unit/214420/).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144232

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


[PATCH] D144321: [PowerPC] Correctly use ELFv2 ABI on all OS's that use the ELFv2 ABI

2023-02-18 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

LGTM, some minor clang-format nits, but these aren't critical (to me at least :)




Comment at: clang/lib/Basic/Targets/PPC.h:432
+  Triple.getOSMajorVersion() >= 13)) || Triple.isOSOpenBSD() ||
+  Triple.isMusl())
+ABI = "elfv2";

clang-format seems to want to format the `if` as:

```
  if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
Triple.getOSMajorVersion() >= 13)) ||
  Triple.isOSOpenBSD() || Triple.isMusl())
```

E,g. it groups the whole FreeBSD expression together. I didn't know it could do 
this, but it seems relatively clear.



Comment at: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp:242
+  TT.getOSMajorVersion() >= 13)) || TT.isOSOpenBSD() || TT.isMusl())
+  return PPCTargetMachine::PPC_ABI_ELFv2;
+else

similarly for this one, clang-format likes to format it as:
```
 if ((TT.isOSFreeBSD() &&
  (TT.getOSVersion().empty() || TT.getOSMajorVersion() >= 13)) ||
 TT.isOSOpenBSD() || TT.isMusl())
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144321

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


[PATCH] D144321: [PowerPC] Correctly use ELFv2 ABI on all OS's that use the ELFv2 ABI

2023-02-18 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 498648.
brad added a comment.

reformatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144321

Files:
  clang/lib/Basic/Targets/PPC.h
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
  llvm/test/CodeGen/PowerPC/pr47373.ll


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-musl < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd12 < %s | 
FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd 
-target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-openbsd < %s | 
FileCheck %s -check-prefix=CHECK-ELFv2
+
 ; CHECK-ELFv2: .abiversion 2
 ; CHECK-ELFv1-NOT: .abiversion 2
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -237,7 +237,12 @@
   case Triple::ppc64le:
 return PPCTargetMachine::PPC_ABI_ELFv2;
   case Triple::ppc64:
-return PPCTargetMachine::PPC_ABI_ELFv1;
+if ((TT.isOSFreeBSD() &&
+ (TT.getOSVersion().empty() || TT.getOSMajorVersion() >= 13)) ||
+TT.isOSOpenBSD() || TT.isMusl())
+  return PPCTargetMachine::PPC_ABI_ELFv2;
+else
+  return PPCTargetMachine::PPC_ABI_ELFv1;
   default:
 return PPCTargetMachine::PPC_ABI_UNKNOWN;
   }
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -427,7 +427,12 @@
   ABI = "elfv2";
 } else {
   DataLayout = "E-m:e-i64:64-n32:64";
-  ABI = "elfv1";
+  if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
+Triple.getOSMajorVersion() >= 13)) ||
+  Triple.isOSOpenBSD() || Triple.isMusl())
+ABI = "elfv2";
+  else
+ABI = "elfv1";
 }
 
 if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) {


Index: llvm/test/CodeGen/PowerPC/pr47373.ll
===
--- llvm/test/CodeGen/PowerPC/pr47373.ll
+++ llvm/test/CodeGen/PowerPC/pr47373.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=powerpc64-unknown-freebsd13.0 -verify-machineinstrs \
+; RUN: llc -mtriple=powerpc64-unknown-freebsd12.0 -verify-machineinstrs \
 ; RUN:   -mcpu=ppc64 -ppc-asm-full-reg-names < %s | FileCheck %s
 @a = local_unnamed_addr global ptr null, align 8
 
Index: llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
===
--- llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
+++ llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
@@ -5,9 +5,14 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
 
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-musl < %s | FileCheck %s -check-prefix=CHECK-ELFv2
+
+; RUN:

[PATCH] D144321: [PowerPC] Correctly use ELFv2 ABI on all OS's that use the ELFv2 ABI

2023-02-18 Thread Brad Smith via Phabricator via cfe-commits
brad marked 2 inline comments as done.
brad added inline comments.



Comment at: clang/lib/Basic/Targets/PPC.h:432
+  Triple.getOSMajorVersion() >= 13)) || Triple.isOSOpenBSD() ||
+  Triple.isMusl())
+ABI = "elfv2";

dim wrote:
> clang-format seems to want to format the `if` as:
> 
> ```
>   if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
> Triple.getOSMajorVersion() >= 13)) ||
>   Triple.isOSOpenBSD() || Triple.isMusl())
> ```
> 
> E,g. it groups the whole FreeBSD expression together. I didn't know it could 
> do this, but it seems relatively clear.
> clang-format seems to want to format the `if` as:
> 
> ```
>   if ((Triple.isOSFreeBSD() && (Triple.getOSVersion().empty() ||
> Triple.getOSMajorVersion() >= 13)) ||
>   Triple.isOSOpenBSD() || Triple.isMusl())
> ```
> 
> E,g. it groups the whole FreeBSD expression together. I didn't know it could 
> do this, but it seems relatively clear.

I can see both ways of doing things. I try to keep it as compact as possible. 
But I'll go with the suggested format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144321

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


[PATCH] D134831: [Clang][Sema] Add -Wcast-function-type-strict

2023-02-18 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

Is this intended to warn on code that casts a function taking a pointer to some 
non-void type to a function that takes a void*?

  void set(void (*g)(int*)) {
f = (void(*)(void*)) g;
  }

gives me

  warning: cast from 'void (*)(int *)' to 'void (*)(void *)' converts to 
incompatible function type [-Wcast-function-type-strict]

I didn't see this mentioned in the diff description, comments, or test. Is the 
behavior intentional? Are these types actually incompatible?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134831

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


[PATCH] D143803: [clang][alias|ifunc]: Add a diagnostic for mangled names

2023-02-18 Thread Dhruv Chawla via Phabricator via cfe-commits
0xdc03 added a comment.

nudge! at anyone who knows what to do here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143803

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


[PATCH] D141215: [clang-repl][WIP] Implement pretty printing

2023-02-18 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 498655.
junaire added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -18,6 +19,8 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h" // llvm_shutdown
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h" // llvm::Initialize*
@@ -66,6 +69,29 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterCreateValue(void*, void*, bool);",
+  "void __InterpreterCreateValue(void*, void*, char);",
+  "void __InterpreterCreateValue(void*, void*, signed char);",
+  "void __InterpreterCreateValue(void*, void*, short);",
+  "void __InterpreterCreateValue(void*, void*, int);",
+  "void __InterpreterCreateValue(void*, void*, long);",
+  "void __InterpreterCreateValue(void*, void*, long long);",
+  "void __InterpreterCreateValue(void*, void*, unsigned char);",
+  "void __InterpreterCreateValue(void*, void*, unsigned short);",
+  "void __InterpreterCreateValue(void*, void*, unsigned int);",
+  "void __InterpreterCreateValue(void*, void*, unsigned long);",
+  "void __InterpreterCreateValue(void*, void*, unsigned long long);",
+  "void __InterpreterCreateValue(void*, void*, float);",
+  "void __InterpreterCreateValue(void*, void*, double);",
+  "void __InterpreterCreateValue(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+int x = 42;
+x
+// CHECK: (int) 42
+x - 2
+// CHECK-NEXT: (int) 40
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -154,10 +154,20 @@
   return true;
 }
 
-bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed) {
+bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed,
+  bool IsTopExpr) {
   if (TryConsumeToken(tok::semi))
 return false;
 
+  // If this is in the incremental C++ mode, then it means we need to pretty
+  // print this expression. Thus, let's pretend we have this semi and continue
+  // parsing.
+  if (PP.isIncrementalProcessingEnabled() && IsTopExpr &&
+  DiagID == diag::err_expected_semi_after_expr) {
+setPrettyPrintMode();
+return false;
+  }
+
   if (Tok.is(tok::code_completion)) {
 handleUnexpectedCodeCompletionToken();
 return false;
Index: clang/lib/Parse/ParseStmt.cpp
==

[PATCH] D144341: [Driver][FreeBSD]

2023-02-18 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: dim.
brad added a project: clang.
Herald added subscribers: krytarowski, arichardson, emaste.
Herald added a project: All.
brad requested review of this revision.
Herald added a subscriber: MaskRay.

While looking at other usage of getOSMajorVersion() I noticed if a version 
number is not included in the FreeBSD triple it won't include the 
--hash-style=both linker option, but it's checking for 9.0 or newer. Without a 
version should be the latest.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144341

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/test/Driver/freebsd.c


Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -90,6 +90,9 @@
 // RUN: %clang --target=x86_64-pc-freebsd10.0 -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
+// RUN: %clang --target=x86_64-pc-freebsd -m32 %s \
+// RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
 // CHECK-LDFLAGS8-NOT: --hash-style=both
 // CHECK-LDFLAGS8: --enable-new-dtags
 // CHECK-LDFLAGS9: --hash-style=both
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -176,7 +176,7 @@
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
 const llvm::Triple &T = ToolChain.getTriple();
-if (T.getOSMajorVersion() >= 9) {
+if (T.getOSVersion().empty() || T.getOSMajorVersion() >= 9) {
   if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || 
T.isX86())
 CmdArgs.push_back("--hash-style=both");
 }


Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -90,6 +90,9 @@
 // RUN: %clang --target=x86_64-pc-freebsd10.0 -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
+// RUN: %clang --target=x86_64-pc-freebsd -m32 %s \
+// RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
 // CHECK-LDFLAGS8-NOT: --hash-style=both
 // CHECK-LDFLAGS8: --enable-new-dtags
 // CHECK-LDFLAGS9: --hash-style=both
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -176,7 +176,7 @@
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
 const llvm::Triple &T = ToolChain.getTriple();
-if (T.getOSMajorVersion() >= 9) {
+if (T.getOSVersion().empty() || T.getOSMajorVersion() >= 9) {
   if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || T.isX86())
 CmdArgs.push_back("--hash-style=both");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits