[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 421696.
junaire added a comment.

Update the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttr) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttr)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttr = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 421706.
vabridgers added a comment.

update per @steakhal's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -4,8 +4,21 @@
 //
 // RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
 // RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -DSUPPRESS_ADDRESS_SPACES\
 // RUN: -analyzer-output=text -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=AMDGCN-CHECK
 
+// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false -analyzer-output=text\
+// RUN: -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=AMDGCN-CHECK-WARNADDRSPACE
+
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown\
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false -analyzer-output=text\
+// RUN: -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=DEFAULT-CHECK
+
 #include "Inputs/llvm.h"
 
 // The amggcn triple case uses an intentionally different address space.
@@ -48,6 +61,7 @@
   (void)C;
 }
 #elif defined(AMDGCN_TRIPLE)
+#if defined(SUPPRESS_ADDRESS_SPACES)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
   clang_analyzer_printState();
@@ -56,6 +70,18 @@
   (void)C;
 }
 #else
+void evalReferences(const Shape &S) {
+  const auto &C = dyn_cast(S);
+  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-2 {{Dereference of null pointer}}
+  // expected-warning@-3 {{Dereference of null pointer}}
+  clang_analyzer_printState();
+  // AMDGCN-CHECK-WARNADDRSPACE: "dynamic_types": [
+  // AMDGCN-CHECK-WARNADDRSPACE-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  (void)C;
+}
+#endif
+#else
 #error Target must be specified, and must be pinned
 #endif
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -41,6 +41,7 @@
 // CHECK-NEXT: core.CallAndMessage:NilReceiver = true
 // CHECK-NEXT: core.CallAndMessage:ParameterCount = true
 // CHECK-NEXT: core.CallAndMessage:UndefReceiver = true
+// CHECK-NEXT: core.NullDereference:SuppressAddressSpaces = true
 // CHECK-NEXT: cplusplus.Move:WarnOn = KnownsAndLocals
 // CHECK-NEXT: cplusplus.SmartPtrModeling:ModelSmartPtrDereference = false
 // CHECK-NEXT: crosscheck-with-z3 = false
Index: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -11,9 +11,10 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -39,6 +40,8 @@
   void reportBug(DerefKind K, ProgramStateRef State, const Stmt *S,
  CheckerContext &C) const;
 
+  bool suppressReport(CheckerContext &C, const Expr *E) const;
+
 public:
   void checkLocation(SVal location, bool isLoad, const Stmt* S,
  CheckerContext &C) const;
@@ -49,6 +52,8 @@
  const Expr *Ex, const ProgramState *state,
  const LocationContext *LCtx,
  bool loadedFrom = false);
+
+  bool SuppressAddressSpaces = false;
 };
 } // end anonymous namespace
 
@@ -109,9 +114,35 @@
   return E;
 }
 
-static bool suppressReport(const Expr *E) {
-  // Do not report dereferences on memory in non-default address spaces.
-  return E->getType().hasAddressSpace();
+bool DereferenceChecker::suppressReport(CheckerContext &C,
+const Expr *E) const {
+  // Do 

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 3 inline comments as done.
vabridgers added a comment.

I believe all points have been addressed. Thanks for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-09 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:130
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), 
NumIdentifierLookups(),

You're not passing this as a const, so the calling function's Cursor will be 
updated - this doesn't sound generally safe to me - what about a move?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[clang] e4903d8 - [CUDA/HIP] Remove argument from module ctor/dtor signatures

2022-04-09 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-04-09T12:34:41+02:00
New Revision: e4903d8be399864cc978236fc4a28087f91c20fe

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

LOG: [CUDA/HIP] Remove argument from module ctor/dtor signatures

In theory, constructors can take arguments when called via .init_array
where at least glibc passes in (argc, argv, envp). This isn't used in
the generated code and if it was, the first argument should be an
integer, not a pointer. For destructors registered via atexit, the
function should never take an argument.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/test/CodeGenCUDA/device-stub.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 3ae152d743206..187817d0e5059 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -659,7 +659,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_ctor(void*) {
+/// void __cuda_module_ctor() {
 /// Handle = __cudaRegisterFatBinary(GpuBinaryBlob);
 /// __cuda_register_globals(Handle);
 /// }
@@ -667,7 +667,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_ctor(void*) {
+/// void __hip_module_ctor() {
 /// if (__hip_gpubin_handle == 0) {
 /// __hip_gpubin_handle  = __hipRegisterFatBinary(GpuBinaryBlob);
 /// __hip_register_globals(__hip_gpubin_handle);
@@ -717,7 +717,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   }
 
   llvm::Function *ModuleCtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_ctor"), &TheModule);
   llvm::BasicBlock *CtorEntryBB =
@@ -931,14 +931,14 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_dtor(void*) {
+/// void __cuda_module_dtor() {
 /// __cudaUnregisterFatBinary(Handle);
 /// }
 /// \endcode
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_dtor(void*) {
+/// void __hip_module_dtor() {
 /// if (__hip_gpubin_handle) {
 /// __hipUnregisterFatBinary(__hip_gpubin_handle);
 /// __hip_gpubin_handle = 0;
@@ -956,7 +956,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleDtorFunction() {
   addUnderscoredPrefixToName("UnregisterFatBinary"));
 
   llvm::Function *ModuleDtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_dtor"), &TheModule);
 

diff  --git a/clang/test/CodeGenCUDA/device-stub.cu 
b/clang/test/CodeGenCUDA/device-stub.cu
index aa7211aeaf8e7..0f925a29c215d 100644
--- a/clang/test/CodeGenCUDA/device-stub.cu
+++ b/clang/test/CodeGenCUDA/device-stub.cu
@@ -257,8 +257,8 @@ void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
 // CUDANORDC-NEXT: call void @__[[PREFIX]]_register_globals
 // HIP-NEXT: call void @__[[PREFIX]]_register_globals
 // * In separate mode we also register a destructor.
-// CUDANORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
-// HIP-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
+// CUDANORDC-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
+// HIP-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
 
 // With relocatable device code we call 
__[[PREFIX]]RegisterLinkedBinary%NVModuleID%
 // CUDARDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](



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


[PATCH] D123370: [CUDA/HIP] Remove argument from module ctor/dtor signatures

2022-04-09 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe4903d8be399: [CUDA/HIP] Remove argument from module 
ctor/dtor signatures (authored by Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123370

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/device-stub.cu


Index: clang/test/CodeGenCUDA/device-stub.cu
===
--- clang/test/CodeGenCUDA/device-stub.cu
+++ clang/test/CodeGenCUDA/device-stub.cu
@@ -257,8 +257,8 @@
 // CUDANORDC-NEXT: call void @__[[PREFIX]]_register_globals
 // HIP-NEXT: call void @__[[PREFIX]]_register_globals
 // * In separate mode we also register a destructor.
-// CUDANORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
-// HIP-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
+// CUDANORDC-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
+// HIP-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
 
 // With relocatable device code we call 
__[[PREFIX]]RegisterLinkedBinary%NVModuleID%
 // CUDARDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -659,7 +659,7 @@
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_ctor(void*) {
+/// void __cuda_module_ctor() {
 /// Handle = __cudaRegisterFatBinary(GpuBinaryBlob);
 /// __cuda_register_globals(Handle);
 /// }
@@ -667,7 +667,7 @@
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_ctor(void*) {
+/// void __hip_module_ctor() {
 /// if (__hip_gpubin_handle == 0) {
 /// __hip_gpubin_handle  = __hipRegisterFatBinary(GpuBinaryBlob);
 /// __hip_register_globals(__hip_gpubin_handle);
@@ -717,7 +717,7 @@
   }
 
   llvm::Function *ModuleCtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_ctor"), &TheModule);
   llvm::BasicBlock *CtorEntryBB =
@@ -931,14 +931,14 @@
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_dtor(void*) {
+/// void __cuda_module_dtor() {
 /// __cudaUnregisterFatBinary(Handle);
 /// }
 /// \endcode
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_dtor(void*) {
+/// void __hip_module_dtor() {
 /// if (__hip_gpubin_handle) {
 /// __hipUnregisterFatBinary(__hip_gpubin_handle);
 /// __hip_gpubin_handle = 0;
@@ -956,7 +956,7 @@
   addUnderscoredPrefixToName("UnregisterFatBinary"));
 
   llvm::Function *ModuleDtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_dtor"), &TheModule);
 


Index: clang/test/CodeGenCUDA/device-stub.cu
===
--- clang/test/CodeGenCUDA/device-stub.cu
+++ clang/test/CodeGenCUDA/device-stub.cu
@@ -257,8 +257,8 @@
 // CUDANORDC-NEXT: call void @__[[PREFIX]]_register_globals
 // HIP-NEXT: call void @__[[PREFIX]]_register_globals
 // * In separate mode we also register a destructor.
-// CUDANORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
-// HIP-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
+// CUDANORDC-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
+// HIP-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
 
 // With relocatable device code we call __[[PREFIX]]RegisterLinkedBinary%NVModuleID%
 // CUDARDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -659,7 +659,7 @@
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_ctor(void*) {
+/// void __cuda_module_ctor() {
 /// Handle = __cudaRegisterFatBinary(GpuBinaryBlob);
 /// __cuda_register_globals(Handle);
 /// }
@@ -667,7 +667,7 @@
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_ctor(void*) {
+/// void __hip_module_ctor() {
 /// if (__hip_gpubin_handle == 0) {
 /// __hip_gpubin_handle  = __hipRegisterFatBinary(GpuBinaryBlob);
 /// __hip_register_globals(__hip_gpubin_handle);
@@ -717,7 +717,7 @@
   }
 
   llvm::Function *ModuleCtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_ctor"), &TheModule);
   llvm::BasicBlock *CtorEntryBB =
@@ -931,14 +931,14 @@
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_d

[PATCH] D123450: [clang-format] Parse Verilog if statements

2022-04-09 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius, owenpan.
Herald added a subscriber: mgorny.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch mainly handles treating `begin` as block openers.

While and for statements will be handled in another patch.

We added an alias option in FormatToken to treat a token as another
token.  This way when some language uses an alternative symbol like
backtick for hash we can continue using tok::hash in the code.  For
keywords like `begin`, left braces aren't block openers in if
expressions while they are in structs and enums.  That means we can't
simply treat `begin` and the left brace the same way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123450

Files:
  clang/docs/ClangFormat.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTestUtils.h
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- /dev/null
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -0,0 +1,118 @@
+//===- unittest/Format/FormatTestVerilog.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestVerilog : public ::testing::Test {
+protected:
+  static std::string format(llvm::StringRef Code, unsigned Offset,
+unsigned Length, const FormatStyle &Style) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(Offset, Length));
+tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
+return format(Code, 0, Code.size(), Style);
+  }
+
+  static void verifyFormat(
+  llvm::StringRef Code,
+  const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Verilog)) {
+EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
+EXPECT_EQ(Code.str(),
+  format(test::messUp(Code, /*HandleHash=*/false), Style));
+  }
+};
+
+TEST_F(FormatTestVerilog, If) {
+  verifyFormat("if (x)\n"
+   "  x = x;");
+  verifyFormat("if (x)\n"
+   "  x = x;\n"
+   "x = x;");
+
+  // Test else
+  verifyFormat("if (x)\n"
+   "  x = x;\n"
+   "else if (x)\n"
+   "  x = x;\n"
+   "else\n"
+   "  x = x;");
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "end else if (x) begin\n"
+   "  x = x;\n"
+   "end else begin\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x else if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x else begin : x\n"
+   "  x = x;\n"
+   "end : x");
+
+  // Test block keywords.
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("if (x) begin : x\n"
+   "  x = x;\n"
+   "end : x");
+  verifyFormat("if (x) begin\n"
+   "  x = x;\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("disable fork;\n"
+   "x = x;");
+  verifyFormat("rand join x x;\n"
+   "x = x;");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join_any");
+  verifyFormat("if (x) fork\n"
+   "  x = x;\n"
+   "join_none");
+  verifyFormat("if (x) generate\n"
+   "  x = x;\n"
+   "endgenerate");
+  verifyFormat("if (x) generate : x\n"
+   "  x = x;\n"
+   "endgenerate : x");
+
+  // Te

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

No major issues left.




Comment at: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:331
+  auto *Chk = mgr.registerChecker();
+  // auto *Chk = mgr.getChecker();
+  Chk->DetectAllNullDereferences =

steakhal wrote:
> dead-code?
This still looks dead.



Comment at: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:56
+
+  bool SuppressAddressSpaces = false;
 };

If I'm correct, we tend to use the 'DefaultBool' instead of plain old bools for 
checker options. Could you please check if this is the case and consolidate 
this?



Comment at: clang/test/Analysis/cast-value-notes.cpp:20
+// RUN: -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=DEFAULT-CHECK
+

Nit: the default triple is the host/native triple, but you did actually pin it 
to x86. Hence it might not be the default on other platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D121916: [clang-format] [doc] Add script to automatically update help output in ClangFormat.rst.

2022-04-09 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

It looks like you forgot to chmod +x.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121916

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


[PATCH] D123450: [clang-format] Parse Verilog if statements

2022-04-09 Thread sstwcw via Phabricator via cfe-commits
sstwcw added inline comments.



Comment at: clang/lib/Format/FormatToken.h:1157
+VerilogExtraKeywords = std::unordered_set(
+{kw_always,   kw_always_comb,  kw_always_ff,kw_always_latch,
+ kw_assert,   kw_assign,   kw_assume,   kw_automatic,

Does anyone know why this part gets aligned unlike the two lists above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123450

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


[PATCH] D123452: [Clang] Override method ModuleImportRead in MultiplexASTDeserializationListener

2022-04-09 Thread Guoxiong Li via Phabricator via cfe-commits
lgxbslgx created this revision.
Herald added a project: All.
lgxbslgx requested review of this revision.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123452

Files:
  clang/include/clang/Frontend/MultiplexConsumer.h
  clang/lib/Frontend/MultiplexConsumer.cpp


Index: clang/lib/Frontend/MultiplexConsumer.cpp
===
--- clang/lib/Frontend/MultiplexConsumer.cpp
+++ clang/lib/Frontend/MultiplexConsumer.cpp
@@ -73,6 +73,12 @@
 Listener->ModuleRead(ID, Mod);
 }
 
+void MultiplexASTDeserializationListener::ModuleImportRead(
+serialization::SubmoduleID ID, SourceLocation ImportLoc) {
+  for (auto &Listener : Listeners)
+Listener->ModuleImportRead(ID, ImportLoc);
+}
+
 // This ASTMutationListener forwards its notifications to a set of
 // child listeners.
 class MultiplexASTMutationListener : public ASTMutationListener {
Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -40,6 +40,8 @@
   void MacroDefinitionRead(serialization::PreprocessedEntityID,
MacroDefinitionRecord *MD) override;
   void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
+  void ModuleImportRead(serialization::SubmoduleID ID,
+SourceLocation ImportLoc) override;
 
 private:
   std::vector Listeners;


Index: clang/lib/Frontend/MultiplexConsumer.cpp
===
--- clang/lib/Frontend/MultiplexConsumer.cpp
+++ clang/lib/Frontend/MultiplexConsumer.cpp
@@ -73,6 +73,12 @@
 Listener->ModuleRead(ID, Mod);
 }
 
+void MultiplexASTDeserializationListener::ModuleImportRead(
+serialization::SubmoduleID ID, SourceLocation ImportLoc) {
+  for (auto &Listener : Listeners)
+Listener->ModuleImportRead(ID, ImportLoc);
+}
+
 // This ASTMutationListener forwards its notifications to a set of
 // child listeners.
 class MultiplexASTMutationListener : public ASTMutationListener {
Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -40,6 +40,8 @@
   void MacroDefinitionRead(serialization::PreprocessedEntityID,
MacroDefinitionRecord *MD) override;
   void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
+  void ModuleImportRead(serialization::SubmoduleID ID,
+SourceLocation ImportLoc) override;
 
 private:
   std::vector Listeners;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:130
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), 
NumIdentifierLookups(),

RKSimon wrote:
> You're not passing this as a const, so the calling function's Cursor will be 
> updated - this doesn't sound generally safe to me - what about a move?
> You're not passing this as a const, so the calling function's Cursor will be 
> updated - this doesn't sound generally safe to me - what about a move?

IIUC, `GlobalModuleIndex::GlobalModuleIndex` is a private function that has 
only been called by `GlobalModuleIndex::readIndex`, and the `Cursor` object has 
only one consumer (`GlobalModuleIndex::readIndex`), so I guess there should not 
be any unsafe concern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 421719.
junaire added a comment.

Rename an argument for consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttrs) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttrs)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index

[PATCH] D123064: [Clang][C++23][WIP] P2071 Named universal character escapes

2022-04-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 421721.
cor3ntin added a comment.

- Add tests
- Cleanups
- Optimization of nearestMatchesForCodepointName to only allocate

when necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ScopedPrinter.cpp
  llvm/lib/Support/StringExtras.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D121556: [randstruct] Add randomize structure layout support

2022-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4244
 
+  if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_file_EQ)) {
+std::ifstream SeedFile(A->getValue(0));

MaskRay wrote:
> void wrote:
> > MaskRay wrote:
> > > Why is -frandomize-layout-seed-file= needed? Can't the user use something 
> > > like -frandomize-layout-seed=$( > > compatibility?
> > > 
> > > The impl uses the very uncommon header .
> > That seems a bit clunky to me. If you don't like it, I can just remove the 
> > option entirely. Wish you would have mentioned these concerns 
> > earlier...like in the several weeks this has been in review.
> > 
> > The `fstream` header is used in other places. If there's a better 
> > alternative, please suggest one.
> > 
> I was a subscriber only vaguely aware of this patch and mostly absent in the 
> past 2 weeks on trips (which meant I spent really little time on reading 
> patches) :)
> 
> I just hope that every option added is useful. A thing that is not so 
> necessarily can be delayed until it is actually needed.
> 
> Just noticed that there is test coverage gap that the cc1 options are 
> completely untested. There are unit tests, but no lit test.
> I just hope that every option added is useful. A thing that is not so 
> necessarily can be delayed until it is actually needed.

I think this option is useful. Windows' cmd.exe doesn't make it particularly 
trivial to pipe contents to an argument in a command line, but also, IDEs don't 
always make it obvious how you would pipe the seed content into a file either. 
I don't see an issue with using `fstream` either; we use it when necessary.



Comment at: clang/unittests/AST/RandstructTest.cpp:41
+
+std::unique_ptr makeAST(const std::string &SourceCode,
+ bool ExpectErr = false) {

void wrote:
> MaskRay wrote:
> > Use static. See 
> > https://llvm.org/docs/CodingStandards.html#anonymous-namespaces
> Nah.
FWIW, I agree with this feedback -- please follow the coding standards unless 
there's strong incentive not to (which I don't think there is here). Sorry for 
not catching this before during review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121556

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


[PATCH] D123064: [Clang][C++23][WIP] P2071 Named universal character escapes

2022-04-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 421723.
cor3ntin added a comment.

Fix in nameToCodepointLoose


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ScopedPrinter.cpp
  llvm/lib/Support/StringExtras.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this, it's a great improvement! I think it's generally correct, 
but I did have some minor questions.

> Most of these improvements are very small, but I measured a 3% decrease in 
> -O0 object file size for a simple C++ source file using the standard library 
> after this change.

Any chance you'd be interested in submitting this patch to 
http://llvm-compile-time-tracker.com/ (instructions at 
http://llvm-compile-time-tracker.com/about.php) so we can have an idea of how 
compile times are impacted? (It's not critical, but having some more compile 
time performance measurements would be helpful to validate that this actually 
saves compile time as expected.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6577-6578
+// FIXME: This should also be in -Wc++23-compat once we have it.
+def warn_use_of_unaddressable_function : Warning<
+  "taking address of non-addressable standard library function">,
+  InGroup;

Thank you for making this one on by default :-)



Comment at: clang/lib/Sema/SemaExpr.cpp:20282
+  if (Context.BuiltinInfo.isInStdNamespace(BuiltinID)) {
+// Any use of these other than a direct call is ill-formed as of C++20,
+// because they are not addressable functions. In earlier language

I wonder how often these get passed around as function objects... e.g.,
```
template 
void func(Fn &&Call);

int main() {
  func(std::move);
}
```
(I don't see evidence that this is a common code pattern, but C++ surprises me 
often enough that I wonder if this will cause issues.)



Comment at: clang/lib/Sema/SemaInit.cpp:8192-8195
+  // We might get back another placeholder expression if we resolved to a
+  // builtin.
+  if (!CurInit.isInvalid())
+CurInit = S.CheckPlaceholderExpr(CurInit.get());

Do we need to make this call every time we've called 
`FixOverloadedFunctionReference()`? I guess I'm not seeing the changes that 
necessitated this call (or the one below).



Comment at: clang/test/SemaCXX/builtin-std-move.cpp:12
+
+  template CONSTEXPR T &&move(T &x) {
+static_assert(T::moveable, "instantiated move"); // expected-error {{no 
member named 'moveable' in 'B'}}

Formatting looks like it's gone wonky in this file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

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


[PATCH] D123353: [CUDA][HIP] Externalize kernels in anonymous name space

2022-04-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/test/CodeGenCUDA/kernel-in-anon-ns.cu:13
+
+// CHECK: define weak_odr {{.*}}void 
@[[KERN:_ZN12_GLOBAL__N_16kernelEv\.anon\..*]](
+// CHECK: @[[STR:.*]] = {{.*}} c"[[KERN]]\00"

tra wrote:
> yaxunl wrote:
> > tra wrote:
> > > Will the externalized names be uniquified as well?
> > > 
> > > E.g. if we compile with -fgpu-rdc, we do want the kernels to be 
> > > externally visible, but we also don't want the names to clash if we have 
> > > two TUs having the same external name for them.
> > Yes, the kernel name is uniquified with a hash of the source path and 
> > compile options.
> Then we should probably include the unique suffix in the CHECK line. The RUN 
> lines already provide specific cuid, so the fuffix will always be the same.
will do when committing


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

https://reviews.llvm.org/D123353

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


[clang] f67e3f6 - [clang-format] Add execute permission to dump_format_help.py

2022-04-09 Thread via cfe-commits

Author: owenca
Date: 2022-04-09T07:58:33-07:00
New Revision: f67e3f6e8c566928c88262df5664ac6e679753d2

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

LOG: [clang-format] Add execute permission to dump_format_help.py

Added: 


Modified: 
clang/docs/tools/dump_format_help.py

Removed: 




diff  --git a/clang/docs/tools/dump_format_help.py 
b/clang/docs/tools/dump_format_help.py
old mode 100644
new mode 100755



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


[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: jyknight, hubert.reinterpretcast, delcypher, 
erichkeane, clang-language-wg.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

This catches places where a function without a prototype is accidentally used, 
potentially passing an incorrect number of arguments, and is a follow-up to the 
work done in https://reviews.llvm.org/D122895 and described in the RFC 
(https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c). 
The diagnostic is grouped under the new `-Wdeprecated-non-prototypes` warning 
group and is enabled by default.

The diagnostic is disabled if the function being called was implicitly declared 
(the user already gets an on-by-default warning about the creation of the 
implicit function declaration, so no need to warn them twice on the same line). 
Additionally, the diagnostic is disabled if the declaration of the function 
without a prototype was in a location where the user explicitly disabled 
deprecation warnings for functions without prototypes (this allows the provider 
of the API a way to disable the diagnostic at call sites because the lack of 
prototype is intentional).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123456

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/nullability.c
  clang/test/Analysis/svalbuilder-float-cast.c
  clang/test/Sema/warn-deprecated-non-prototype.c

Index: clang/test/Sema/warn-deprecated-non-prototype.c
===
--- clang/test/Sema/warn-deprecated-non-prototype.c
+++ clang/test/Sema/warn-deprecated-non-prototype.c
@@ -36,7 +36,7 @@
 void another(); // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
 
 int main(void) {
-  another(1, 2); // OK for now
+  another(1, 2);  // both-warning {{calling 'another' with arguments when the function has no prototype}}
 }
 
 void order1();// expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
@@ -71,3 +71,47 @@
 void blapp(int);
 void blapp() { } // both-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
  // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+
+// Disable -Wdeprecated-non-prototype
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-non-prototype"
+void depr_non_prot(); // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+#pragma GCC diagnostic pop
+// Reenable it.
+
+// Disable -Wstrict-prototypes
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+void strict_prot(); // OK
+#pragma GCC diagnostic pop
+// Reenable it.
+
+void calls(void) {
+  // Ensure that we diagnose calls to functions without a prototype, but only
+  // if they pass arguments.
+  never_defined(); // OK
+  never_defined(1); // both-warning {{calling 'never_defined' with arguments when the function has no prototype}}
+
+  // Ensure that calls to builtins without a traditional prototype are not
+  // diagnosed.
+  (void)__builtin_isless(1.0, 1.0); // OK
+
+  // Calling a function whose prototype was provided by a function with an
+  // identifier list is still fine.
+  func(1, 2); // OK
+
+  // Ensure that a call through a function pointer is still diagnosed properly.
+  fp f;
+  f(); // OK
+  f(1, 2); // both-warning {{calling a function with arguments when the function has no prototype}}
+
+  // Ensure that we don't diagnose when the diagnostic group is disabled.
+  depr_non_prot(1); // OK
+  strict_prot(1); // OK
+
+  // Ensure we don't issue diagnostics if the function without a prototype was
+  // later given a prototype by a definintion. Also ensure we don't duplicate
+  // diagnostics if such a call is incorrect.
+  func(1, 2); // OK
+  func(1, 2, 3); // both-warning {{too many arguments in call to 'func'}}
+}
Index: clang/test/Analysis/svalbuilder-float-cast.c
===
--- clang/test/Analysis/svalbuilder-float-cast.c
+++ clang/test/Analysis/svalbuilder-float-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -Wno-deprecated-non-prototype -verify %s
 void clang_analyzer_denote(int, const char *);
 void clang_analyzer_express(int);
 
Index: clang/test/Analysis/nullability.c
===
--- clang/test/Analysis/nullability.c
+++ clang/test/Analysis/nullability.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-chec

[PATCH] D121916: [clang-format] [doc] Add script to automatically update help output in ClangFormat.rst.

2022-04-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D121916#3440831 , @sstwcw wrote:

> It looks like you forgot to chmod +x.

Added in f67e3f6 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121916

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


[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision as: cor3ntin.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM except a couple of nitpicks




Comment at: clang/lib/Sema/SemaExpr.cpp:7052
+// the call, diagnose this as calling a function without a prototype.
+// However, if we found a function declaration, check to see if the strict
+// uses without a prototype warning was disabled where the function was

I have a hard time parsing this sentence. I suspect words or punctuation are 
missing 



Comment at: clang/lib/Sema/SemaExpr.cpp:7065
+  Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
+  << (bool)FDecl << FDecl;
+

`!= nullptr` may be cleaner 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123456

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


[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 421738.
aaron.ballman marked 2 inline comments as done.
aaron.ballman added a comment.

Updated based on review comments.


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

https://reviews.llvm.org/D123456

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/nullability.c
  clang/test/Analysis/svalbuilder-float-cast.c
  clang/test/Sema/warn-deprecated-non-prototype.c

Index: clang/test/Sema/warn-deprecated-non-prototype.c
===
--- clang/test/Sema/warn-deprecated-non-prototype.c
+++ clang/test/Sema/warn-deprecated-non-prototype.c
@@ -36,7 +36,7 @@
 void another(); // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
 
 int main(void) {
-  another(1, 2); // OK for now
+  another(1, 2);  // both-warning {{calling 'another' with arguments when the function has no prototype}}
 }
 
 void order1();// expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
@@ -71,3 +71,47 @@
 void blapp(int);
 void blapp() { } // both-warning {{a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x}} \
  // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+
+// Disable -Wdeprecated-non-prototype
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-non-prototype"
+void depr_non_prot(); // strict-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+#pragma GCC diagnostic pop
+// Reenable it.
+
+// Disable -Wstrict-prototypes
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+void strict_prot(); // OK
+#pragma GCC diagnostic pop
+// Reenable it.
+
+void calls(void) {
+  // Ensure that we diagnose calls to functions without a prototype, but only
+  // if they pass arguments.
+  never_defined(); // OK
+  never_defined(1); // both-warning {{calling 'never_defined' with arguments when the function has no prototype}}
+
+  // Ensure that calls to builtins without a traditional prototype are not
+  // diagnosed.
+  (void)__builtin_isless(1.0, 1.0); // OK
+
+  // Calling a function whose prototype was provided by a function with an
+  // identifier list is still fine.
+  func(1, 2); // OK
+
+  // Ensure that a call through a function pointer is still diagnosed properly.
+  fp f;
+  f(); // OK
+  f(1, 2); // both-warning {{calling a function with arguments when the function has no prototype}}
+
+  // Ensure that we don't diagnose when the diagnostic group is disabled.
+  depr_non_prot(1); // OK
+  strict_prot(1); // OK
+
+  // Ensure we don't issue diagnostics if the function without a prototype was
+  // later given a prototype by a definintion. Also ensure we don't duplicate
+  // diagnostics if such a call is incorrect.
+  func(1, 2); // OK
+  func(1, 2, 3); // both-warning {{too many arguments in call to 'func'}}
+}
Index: clang/test/Analysis/svalbuilder-float-cast.c
===
--- clang/test/Analysis/svalbuilder-float-cast.c
+++ clang/test/Analysis/svalbuilder-float-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -Wno-deprecated-non-prototype -verify %s
 void clang_analyzer_denote(int, const char *);
 void clang_analyzer_express(int);
 
Index: clang/test/Analysis/nullability.c
===
--- clang/test/Analysis/nullability.c
+++ clang/test/Analysis/nullability.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,nullability -verify %s
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,nullability -Wno-deprecated-non-prototype -verify %s
 
 void it_takes_two(int a, int b);
 void function_pointer_arity_mismatch() {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7047,6 +7047,23 @@
 Proto = FDecl->getType()->getAs();
 }
 
+// If we still haven't found a prototype to use but there are arguments to
+// the call, diagnose this as calling a function without a prototype.
+// However, if we found a function declaration, check to see if
+// -Wdeprecated-non-prototype was disabled where the function was declared.
+// If so, we will silence the diagnostic here on the assumption that this
+// interface is intentional and the user knows what they're doing. We will
+// also silence the diagnostic if there is a function declaration but it
+// was implicitly defined (the user already gets 

[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7052
+// the call, diagnose this as calling a function without a prototype.
+// However, if we found a function declaration, check to see if the strict
+// uses without a prototype warning was disabled where the function was

cor3ntin wrote:
> I have a hard time parsing this sentence. I suspect words or punctuation are 
> missing 
I reworded to mention the warning group specifically; that hopefully clears up 
the confusion.



Comment at: clang/lib/Sema/SemaExpr.cpp:7065
+  Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
+  << (bool)FDecl << FDecl;
+

cor3ntin wrote:
> `!= nullptr` may be cleaner 
Sure!


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

https://reviews.llvm.org/D123456

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


[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7052
+// the call, diagnose this as calling a function without a prototype.
+// However, if we found a function declaration, check to see if the strict
+// uses without a prototype warning was disabled where the function was

aaron.ballman wrote:
> cor3ntin wrote:
> > I have a hard time parsing this sentence. I suspect words or punctuation 
> > are missing 
> I reworded to mention the warning group specifically; that hopefully clears 
> up the confusion.
Excellent !


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

https://reviews.llvm.org/D123456

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


[libunwind] 958251e - Add some prototypes to fix -Wstrict-prototypes. NFC

2022-04-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-04-09T09:46:39-07:00
New Revision: 958251ef76db60dba6f0bb48c50a7cc9b9e9c4f1

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

LOG: Add some prototypes to fix -Wstrict-prototypes. NFC

Added: 


Modified: 
libunwind/src/cet_unwind.h
libunwind/src/config.h

Removed: 




diff  --git a/libunwind/src/cet_unwind.h b/libunwind/src/cet_unwind.h
index e371be20c4520..c364ed3e12feb 100644
--- a/libunwind/src/cet_unwind.h
+++ b/libunwind/src/cet_unwind.h
@@ -36,6 +36,6 @@
 #endif
 
 extern void *__libunwind_cet_get_registers(unw_cursor_t *);
-extern void *__libunwind_cet_get_jump_target();
+extern void *__libunwind_cet_get_jump_target(void);
 
 #endif

diff  --git a/libunwind/src/config.h b/libunwind/src/config.h
index 5ae1604f657dd..d2309186df57a 100644
--- a/libunwind/src/config.h
+++ b/libunwind/src/config.h
@@ -188,9 +188,9 @@
   #ifdef __cplusplus
 extern "C" {
   #endif
-extern  bool logAPIs();
-extern  bool logUnwinding();
-extern  bool logDWARF();
+extern  bool logAPIs(void);
+extern  bool logUnwinding(void);
+extern  bool logDWARF(void);
   #ifdef __cplusplus
 }
   #endif



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


[PATCH] D121556: [randstruct] Add randomize structure layout support

2022-04-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4244
 
+  if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_file_EQ)) {
+std::ifstream SeedFile(A->getValue(0));

aaron.ballman wrote:
> MaskRay wrote:
> > void wrote:
> > > MaskRay wrote:
> > > > Why is -frandomize-layout-seed-file= needed? Can't the user use 
> > > > something like -frandomize-layout-seed=$( > > > POSIX sh compatibility?
> > > > 
> > > > The impl uses the very uncommon header .
> > > That seems a bit clunky to me. If you don't like it, I can just remove 
> > > the option entirely. Wish you would have mentioned these concerns 
> > > earlier...like in the several weeks this has been in review.
> > > 
> > > The `fstream` header is used in other places. If there's a better 
> > > alternative, please suggest one.
> > > 
> > I was a subscriber only vaguely aware of this patch and mostly absent in 
> > the past 2 weeks on trips (which meant I spent really little time on 
> > reading patches) :)
> > 
> > I just hope that every option added is useful. A thing that is not so 
> > necessarily can be delayed until it is actually needed.
> > 
> > Just noticed that there is test coverage gap that the cc1 options are 
> > completely untested. There are unit tests, but no lit test.
> > I just hope that every option added is useful. A thing that is not so 
> > necessarily can be delayed until it is actually needed.
> 
> I think this option is useful. Windows' cmd.exe doesn't make it particularly 
> trivial to pipe contents to an argument in a command line, but also, IDEs 
> don't always make it obvious how you would pipe the seed content into a file 
> either. I don't see an issue with using `fstream` either; we use it when 
> necessary.
Ah, LG! 

Just need some tests for the two -f -cc1 options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121556

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2022-04-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'm totally fine with a specifier that removes all qualifiers; I just think we 
can't use it for `std::remove_cv`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

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


[clang] 7aa8c38 - [randstruct] Add randomize structure layout support

2022-04-09 Thread Bill Wendling via cfe-commits

Author: Connor Kuehl
Date: 2022-04-09T13:15:36-07:00
New Revision: 7aa8c38a9e190aea14116028c38b1d9f54cbb0b3

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

LOG: [randstruct] Add randomize structure layout support

The Randstruct feature is a compile-time hardening technique that
randomizes the field layout for designated structures of a code base.
Admittedly, this is mostly useful for closed-source releases of code,
since the randomization seed would need to be available for public and
open source applications.

Why implement it? This patch set enhances Clang’s feature parity with
that of GCC which already has the Randstruct feature. It's used by the
Linux kernel in certain structures to help thwart attacks that depend on
structure layouts in memory.

This patch set is a from-scratch reimplementation of the Randstruct
feature that was originally ported to GCC. The patches for the GCC
implementation can be found here:

  https://www.openwall.com/lists/kernel-hardening/2017/04/06/14

Link: https://lists.llvm.org/pipermail/cfe-dev/2019-March/061607.html
Co-authored-by: Cole Nixon 
Co-authored-by: Connor Kuehl 
Co-authored-by: James Foster 
Co-authored-by: Jeff Takahashi 
Co-authored-by: Jordan Cantrell 
Co-authored-by: Nikk Forbus 
Co-authored-by: Tim Pugh 
Co-authored-by: Bill Wendling 
Signed-off-by: Bill Wendling 

Reviewed By: aaron.ballman

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

Added: 
clang/include/clang/AST/Randstruct.h
clang/lib/AST/Randstruct.cpp
clang/unittests/AST/RandstructTest.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Decl.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 079258c743704..c53fa0ad7fe01 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -54,6 +54,20 @@ Major New Features
   There is an analogous ``zero_call_used_regs`` attribute to allow for finer
   control of this feature.
 
+- Clang now supports randomizing structure layout in C. This feature is a
+  compile-time hardening technique, making it more 
diff icult for an attacker to
+  retrieve data from structures. Specify randomization with the
+  ``randomize_layout`` attribute. The corresponding ``no_randomize_layout``
+  attribute can be used to turn the feature off.
+
+  A seed value is required to enable randomization, and is deterministic based
+  on a seed value. Use the ``-frandomize-layout-seed=`` or
+  ``-frandomize-layout-seed-file=`` flags.
+
+  .. note::
+
+  Randomizing structure layout is a C-only feature.
+
 Bug Fixes
 --
 - ``CXXNewExpr::getArraySize()`` previously returned a ``llvm::Optional``

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 1246287ee2e62..21a8545920387 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4051,6 +4051,12 @@ class RecordDecl : public TagDecl {
 RecordDeclBits.ParamDestroyedInCallee = V;
   }
 
+  bool isRandomized() const { return RecordDeclBits.IsRandomized; }
+
+  void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
+
+  void reorderFields(const SmallVectorImpl &Fields);
+
   /// Determines whether this declaration represents the
   /// injected class name.
   ///

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index a89f776248c1f..a4a44e0b30e64 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -313,6 +313,7 @@ class alignas(8) Decl {
   friend class ASTReader;
   friend class CXXClassMemberWrapper;
   friend class LinkageComputer;
+  friend class RecordDecl;
   template friend class Redeclarable;
 
   /// Access - Used by C++ decls for the access specifier.
@@ -1540,10 +1541,13 @@ class DeclContext {
 
 /// Represents the way this type is passed to a function.
 uint64_t ArgPassingRestrictions : 2;
+
+/// Indicates whether this struct has had its field layout randomized.
+uint64_t IsRandomized : 1;
   };
 
   /// Number of non-inherited bits in RecordDeclBitfields.
-  e

[PATCH] D121556: [randstruct] Add randomize structure layout support

2022-04-09 Thread Bill Wendling via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7aa8c38a9e19: [randstruct] Add randomize structure layout 
support (authored by connorkuehl, committed by void).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121556

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Randstruct.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Randstruct.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/RandstructTest.cpp

Index: clang/unittests/AST/RandstructTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/RandstructTest.cpp
@@ -0,0 +1,424 @@
+//===- unittest/AST/RandstructTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file contains tests for Clang's structure field layout randomization.
+//
+//===--===//
+
+/*
+ * Build this test suite by running `make ASTTests` in the build folder.
+ *
+ * Run this test suite by running the following in the build folder:
+ * ` ./tools/clang/unittests/AST/ASTTests
+ * --gtest_filter=StructureLayoutRandomization*`
+ */
+
+#include "clang/AST/Randstruct.h"
+#include "gtest/gtest.h"
+
+#include "DeclMatcher.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
+#include "clang/Tooling/Tooling.h"
+
+#include 
+
+using namespace clang;
+using namespace clang::ast_matchers;
+using namespace clang::randstruct;
+
+using field_names = std::vector;
+
+namespace {
+
+std::unique_ptr makeAST(const std::string &SourceCode) {
+  std::vector Args = getCommandLineArgsForTesting(Lang_C99);
+  Args.push_back("-frandomize-layout-seed=1234567890abcdef");
+
+  IgnoringDiagConsumer IgnoringConsumer = IgnoringDiagConsumer();
+
+  return tooling::buildASTFromCodeWithArgs(
+  SourceCode, Args, "input.c", "clang-tool",
+  std::make_shared(),
+  tooling::getClangStripDependencyFileAdjuster(),
+  tooling::FileContentMappings(), &IgnoringConsumer);
+}
+
+RecordDecl *getRecordDeclFromAST(const ASTContext &C, const std::string &Name) {
+  RecordDecl *RD = FirstDeclMatcher().match(
+  C.getTranslationUnitDecl(), recordDecl(hasName(Name)));
+  return RD;
+}
+
+std::vector getFieldNamesFromRecord(const RecordDecl *RD) {
+  std::vector Fields;
+
+  Fields.reserve(8);
+  for (auto *Field : RD->fields())
+Fields.push_back(Field->getNameAsString());
+
+  return Fields;
+}
+
+bool isSubsequence(const field_names &Seq, const field_names &Subseq) {
+  unsigned SeqLen = Seq.size();
+  unsigned SubLen = Subseq.size();
+
+  bool IsSubseq = false;
+  for (unsigned I = 0; I < SeqLen; ++I)
+if (Seq[I] == Subseq[0]) {
+  IsSubseq = true;
+  for (unsigned J = 0; J + I < SeqLen && J < SubLen; ++J) {
+if (Seq[J + I] != Subseq[J]) {
+  IsSubseq = false;
+  break;
+}
+  }
+}
+
+  return IsSubseq;
+}
+
+} // end anonymous namespace
+
+namespace clang {
+namespace ast_matchers {
+
+#define RANDSTRUCT_TEST_SUITE_TEST StructureLayoutRandomizationTestSuiteTest
+
+TEST(RANDSTRUCT_TEST_SUITE_TEST, CanDetermineIfSubsequenceExists) {
+  const field_names Seq = {"a", "b", "c", "d"};
+
+  EXPECT_TRUE(isSubsequence(Seq, {"b", "c"}));
+  EXPECT_TRUE(isSubsequence(Seq, {"a", "b", "c", "d"}));
+  EXPECT_TRUE(isSubsequence(Seq, {"b", "c", "d"}));
+  EXPECT_TRUE(isSubsequence(Seq, {"a"}));
+  EXPECT_FALSE(isSubsequence(Seq, {"a", "d"}));
+}
+
+#define RANDSTRUCT_TEST StructureLayoutRandomization
+
+TEST(RANDSTRUCT_TEST, UnmarkedStruct) {
+  const std::unique_ptr AST = makeAST(R"c(
+struct test {
+int bacon;
+long lettuce;
+long long tomato;
+float mayonnaise;
+};
+  )c");
+
+  EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  const RecordDecl *RD = getRecordDeclFro

[clang] 77e71bc - [randstruct] NFC change to use static

2022-04-09 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-04-09T13:25:25-07:00
New Revision: 77e71bcfde7264466849babaa0e9ccbec51a8a08

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

LOG: [randstruct] NFC change to use static

Added: 


Modified: 
clang/unittests/AST/RandstructTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/RandstructTest.cpp 
b/clang/unittests/AST/RandstructTest.cpp
index b64d9fdfb2ad4..9e03beaa9caf8 100644
--- a/clang/unittests/AST/RandstructTest.cpp
+++ b/clang/unittests/AST/RandstructTest.cpp
@@ -36,9 +36,7 @@ using namespace clang::randstruct;
 
 using field_names = std::vector;
 
-namespace {
-
-std::unique_ptr makeAST(const std::string &SourceCode) {
+static std::unique_ptr makeAST(const std::string &SourceCode) {
   std::vector Args = getCommandLineArgsForTesting(Lang_C99);
   Args.push_back("-frandomize-layout-seed=1234567890abcdef");
 
@@ -51,13 +49,14 @@ std::unique_ptr makeAST(const std::string 
&SourceCode) {
   tooling::FileContentMappings(), &IgnoringConsumer);
 }
 
-RecordDecl *getRecordDeclFromAST(const ASTContext &C, const std::string &Name) 
{
+static RecordDecl *getRecordDeclFromAST(const ASTContext &C,
+const std::string &Name) {
   RecordDecl *RD = FirstDeclMatcher().match(
   C.getTranslationUnitDecl(), recordDecl(hasName(Name)));
   return RD;
 }
 
-std::vector getFieldNamesFromRecord(const RecordDecl *RD) {
+static std::vector getFieldNamesFromRecord(const RecordDecl *RD) {
   std::vector Fields;
 
   Fields.reserve(8);
@@ -67,7 +66,7 @@ std::vector getFieldNamesFromRecord(const 
RecordDecl *RD) {
   return Fields;
 }
 
-bool isSubsequence(const field_names &Seq, const field_names &Subseq) {
+static bool isSubsequence(const field_names &Seq, const field_names &Subseq) {
   unsigned SeqLen = Seq.size();
   unsigned SubLen = Subseq.size();
 
@@ -86,8 +85,6 @@ bool isSubsequence(const field_names &Seq, const field_names 
&Subseq) {
   return IsSubseq;
 }
 
-} // end anonymous namespace
-
 namespace clang {
 namespace ast_matchers {
 



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


[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers planned changes to this revision.
vabridgers added a comment.

Thanks for the the comments. I'll make the changes and resubmit. Please let me 
know your preferences for the test case (default vs pinned x86 or same).

Best!




Comment at: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:331
+  auto *Chk = mgr.registerChecker();
+  // auto *Chk = mgr.getChecker();
+  Chk->DetectAllNullDereferences =

steakhal wrote:
> steakhal wrote:
> > dead-code?
> This still looks dead.
arg, missed that. I'll clean this up.



Comment at: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:56
+
+  bool SuppressAddressSpaces = false;
 };

steakhal wrote:
> If I'm correct, we tend to use the 'DefaultBool' instead of plain old bools 
> for checker options. Could you please check if this is the case and 
> consolidate this?
I'll address. FYI, looks like I chose the red pill when I found an example to 
go by :/  Looks like there's opportunity for some cleanup NFC type of patches. 
I'll pick these up in a separate patch. 


```
120 namespace {
121 class DeadStoresChecker : public Checker {
122 public:
123   bool ShowFixIts = false;
124   bool WarnForDeadNestedAssignments = true;
125 
126   void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
127 BugReporter &BR) const;
128 };

```



Comment at: clang/test/Analysis/cast-value-notes.cpp:20
+// RUN: -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=DEFAULT-CHECK
+

steakhal wrote:
> Nit: the default triple is the host/native triple, but you did actually pin 
> it to x86. Hence it might not be the default on other platforms.
Yeah, the result is the same (as far as what the test code would look like). 
Not sure what your preferences are here. 

Would you prefer to see separate cases (default and pinned x86), or perhaps the 
macro names renamed to something that means both (instead of implying default)? 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

___
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

2022-04-09 Thread Clemens Wasser via Phabricator via cfe-commits
clemenswasser updated this revision to Diff 421758.
clemenswasser added a comment.

Hi,
today I found some more time to play/progress with this patch. I'm generally 
optimistic that most of the basic lsan stuff should already be working on 
Windows.
However without some help of you, I'm unable to get the tests to properly work. 
The main Problem I looked into today is that `llvm-lit.py` seems to be somehow 
unable to capture the stdout/err of the tests. More precisely my Debugging 
showed that when I insert a `print(procs[-1].stdout.read())` at 
TestRunner.py:790 I get the correctly captured stdout of a test e.g.:

  =
  ==25028==ERROR: LeakSanitizer: detected memory leaks
  
  Direct leak of 1337 byte(s) in 1 object(s) allocated from:
  #0 0x7ff77fc0488e in __asan_wrap_malloc 
C:\Users\cleme\dev\cpp\llvm-project\compiler-rt\lib\lsan\lsan_interceptors.cpp:75
  #1 0x7ff77fbbaafe in main 
C:\Users\cleme\dev\cpp\llvm-project\compiler-rt\test\lsan\TestCases\leak_check_at_exit.cpp:13:40
  #2 0x7ff77fc09e2b in invoke_main 
d:\a01\_work\43\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  #3 0x7ff77fc09e2b in __scrt_common_main_seh 
d:\a01\_work\43\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  #4 0x7ff8cb5654df  (C:\Windows\System32\KERNEL32.DLL+0x1800154df)
  #5 0x7ff8cc9e485a  (C:\Windows\SYSTEM32\ntdll.dll+0x18000485a)
  
  SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s).

However further below at lines 816-829 this output is lost 
(`proc.stdout.read()` returns a empty string, which obviously causes any 
FileCheck afterwards to fail)... and I can't figure out why. The only possible 
explaination I can think of is that the captured stdout is lost during the next 
loopiteration over `cmd.commands`


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

https://reviews.llvm.org/D115103

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/lsan/CMakeLists.txt
  compiler-rt/lib/lsan/lsan.h
  compiler-rt/lib/lsan/lsan_allocator.h
  compiler-rt/lib/lsan/lsan_common.cpp
  compiler-rt/lib/lsan/lsan_common.h
  compiler-rt/lib/lsan/lsan_common_win.cpp
  compiler-rt/lib/lsan/lsan_interceptors.cpp
  compiler-rt/lib/lsan/lsan_win.cpp
  compiler-rt/lib/lsan/lsan_win.h
  compiler-rt/test/lsan/TestCases/Darwin/dispatch.mm
  compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c
  compiler-rt/test/lsan/TestCases/Linux/disabler_in_tsd_destructor.c
  compiler-rt/test/lsan/TestCases/Linux/use_tls_dynamic.cpp
  compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_dynamic.cpp
  compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_static.cpp
  compiler-rt/test/lsan/TestCases/Linux/use_tls_static.cpp
  compiler-rt/test/lsan/TestCases/disabler.c
  compiler-rt/test/lsan/TestCases/disabler.cpp
  compiler-rt/test/lsan/TestCases/do_leak_check_override.cpp
  compiler-rt/test/lsan/TestCases/high_allocator_contention.cpp
  compiler-rt/test/lsan/TestCases/ignore_object.c
  compiler-rt/test/lsan/TestCases/large_allocation_leak.cpp
  compiler-rt/test/lsan/TestCases/leak_check_at_exit.cpp
  compiler-rt/test/lsan/TestCases/link_turned_off.cpp
  compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp
  compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp
  compiler-rt/test/lsan/TestCases/pointer_to_self.cpp
  compiler-rt/test/lsan/TestCases/print_suppressions.cpp
  compiler-rt/test/lsan/TestCases/recoverable_leak_check.cpp
  compiler-rt/test/lsan/TestCases/register_root_region.cpp
  compiler-rt/test/lsan/TestCases/stale_stack_leak.cpp
  compiler-rt/test/lsan/TestCases/suppressions_default.cpp
  compiler-rt/test/lsan/TestCases/suppressions_file.cpp
  compiler-rt/test/lsan/TestCases/use_after_return.cpp
  compiler-rt/test/lsan/TestCases/use_globals_initialized.cpp
  compiler-rt/test/lsan/TestCases/use_globals_uninitialized.cpp
  compiler-rt/test/lsan/TestCases/use_globals_unused.cpp
  compiler-rt/test/lsan/TestCases/use_poisoned_asan.cpp
  compiler-rt/test/lsan/TestCases/use_registers.cpp
  compiler-rt/test/lsan/TestCases/use_registers_extra.cpp
  compiler-rt/test/lsan/TestCases/use_stacks.cpp
  compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp
  compiler-rt/test/lsan/TestCases/use_unaligned.cpp
  compiler-rt/test/lsan/lit.common.cfg.py

Index: compiler-rt/test/lsan/lit.common.cfg.py
===
--- compiler-rt/test/lsan/lit.common.cfg.py
+++ compiler-rt/test/lsan/lit.common.cfg.py
@@ -22,7 +22,8 @@
 # Choose between standalone and LSan+ASan modes.
 lsan_lit_test_mode = get_required_attr(config, 'lsan_lit_test_mode')
 
-if lsan_lit_test_mode == "Standalone":
+# FIXME: All tests are Standalone on Windows for now. Since all win32 function calls in lsan get intercepted by asan :(
+if lsan_lit_test_mode == "Standalone" or config.host_os == 'Windows':
   config.name = "Leak

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 421759.
vabridgers added a comment.
This revision is now accepted and ready to land.

update per @steakhal's latest comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -4,8 +4,21 @@
 //
 // RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
 // RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -DSUPPRESS_ADDRESS_SPACES\
 // RUN: -analyzer-output=text -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=AMDGCN-CHECK
 
+// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false -analyzer-output=text\
+// RUN: -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=AMDGCN-CHECK-WARNADDRSPACE
+
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown\
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false -analyzer-output=text\
+// RUN: -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s\
+// RUN: -check-prefix=DEFAULT-CHECK
+
 #include "Inputs/llvm.h"
 
 // The amggcn triple case uses an intentionally different address space.
@@ -48,6 +61,7 @@
   (void)C;
 }
 #elif defined(AMDGCN_TRIPLE)
+#if defined(SUPPRESS_ADDRESS_SPACES)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
   clang_analyzer_printState();
@@ -56,6 +70,18 @@
   (void)C;
 }
 #else
+void evalReferences(const Shape &S) {
+  const auto &C = dyn_cast(S);
+  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-2 {{Dereference of null pointer}}
+  // expected-warning@-3 {{Dereference of null pointer}}
+  clang_analyzer_printState();
+  // AMDGCN-CHECK-WARNADDRSPACE: "dynamic_types": [
+  // AMDGCN-CHECK-WARNADDRSPACE-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  (void)C;
+}
+#endif
+#else
 #error Target must be specified, and must be pinned
 #endif
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -41,6 +41,7 @@
 // CHECK-NEXT: core.CallAndMessage:NilReceiver = true
 // CHECK-NEXT: core.CallAndMessage:ParameterCount = true
 // CHECK-NEXT: core.CallAndMessage:UndefReceiver = true
+// CHECK-NEXT: core.NullDereference:SuppressAddressSpaces = true
 // CHECK-NEXT: cplusplus.Move:WarnOn = KnownsAndLocals
 // CHECK-NEXT: cplusplus.SmartPtrModeling:ModelSmartPtrDereference = false
 // CHECK-NEXT: crosscheck-with-z3 = false
Index: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -11,9 +11,10 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -39,6 +40,8 @@
   void reportBug(DerefKind K, ProgramStateRef State, const Stmt *S,
  CheckerContext &C) const;
 
+  bool suppressReport(CheckerContext &C, const Expr *E) const;
+
 public:
   void checkLocation(SVal location, bool isLoad, const Stmt* S,
  CheckerContext &C) const;
@@ -49,6 +52,8 @@
  const Expr *Ex, const ProgramState *state,
  const LocationContext *LCtx,
  bool loadedFrom = false);
+
+  DefaultBool SuppressAddressSpaces;
 };
 } // end anonymous namespace
 
@@ -109,9 +114,35 @@
   return E;
 }
 
-static bool suppressReport(const Expr *E) {
-  // Do not report dereferences on memory in non-default address spaces.
-  return E->getType().hasAddressSpace();
+bool DereferenceChecker::suppressReport(CheckerContext &C,
+ 

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked 3 inline comments as done.
vabridgers added a comment.

The two small issues are addressed, I think the only outstanding issue is the 
question about the test case. Please let me know a preference and I'll 
implement accordingly. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-09 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

As is, I think this conflicts with `-ffreestanding` assumptions or at the very 
least the spirit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

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


[PATCH] D123460: [OpenMP] Make generating offloading entries more generic

2022-04-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ABataev.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch moves the logic for generating the offloading entries to the
OpenMPIRBuilder. This makes it easier to re-use in other places, such as
for OpenMP support in Flang or using the same method for generating
offloading entires for other languages like Cuda.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123460

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -598,6 +598,45 @@
   return Builder.saveIP();
 }
 
+void OpenMPIRBuilder::emitOffloadingEntry(Constant *ID, Constant *Addr,
+  uint64_t Size, int32_t Flags,
+  StringRef SectionName) {
+  Type *Int8PtrTy = Type::getInt8PtrTy(M.getContext());
+  Type *Int32Ty = Type::getInt32Ty(M.getContext());
+  Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
+
+  Constant *AddrName =
+  ConstantDataArray::getString(M.getContext(), Addr->getName());
+
+  // Create the constant string used to look up the symbol in the device.
+  auto *Str = new llvm::GlobalVariable(
+  M, AddrName->getType(), /*isConstant=*/true,
+  llvm::GlobalValue::InternalLinkage, AddrName, ".omp_offloading.entry_name");
+  Str->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
+  // Construct the offloading entry.
+  Constant *EntryData[] = {
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(ID, Int8PtrTy),
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(Str, Int8PtrTy),
+  ConstantInt::get(SizeTy, Size),
+  ConstantInt::get(Int32Ty, Flags),
+  ConstantInt::get(Int32Ty, 0),
+  };
+  Constant *EntryInitializer =
+  ConstantStruct::get(OpenMPIRBuilder::OffloadEntry, EntryData);
+
+  auto *Entry = new GlobalVariable(
+  M, OpenMPIRBuilder::OffloadEntry,
+  /* isConstant = */ true, GlobalValue::WeakAnyLinkage, EntryInitializer,
+  ".omp_offloading.entry." + Addr->getName(), nullptr,
+  GlobalValue::NotThreadLocal,
+  M.getDataLayout().getDefaultGlobalsAddressSpace());
+
+  // The entry has to be created in the section the linker expects it to be.
+  Entry->setSection(SectionName);
+  Entry->setAlignment(Align(1));
+}
+
 void OpenMPIRBuilder::emitCancelationCheckImpl(Value *CancelFlag,
omp::Directive CanceledDirective,
FinalizeCallbackTy ExitCB) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -86,6 +86,8 @@
   OMP_STRUCT_TYPE(VarName, "struct." #Name, __VA_ARGS__)
 
 __OMP_STRUCT_TYPE(Ident, ident_t, Int32, Int32, Int32, Int32, Int8Ptr)
+__OMP_STRUCT_TYPE(OffloadEntry, __tgt_offload_entry, Int8Ptr, Int8Ptr, SizeTy,
+  Int32, Int32)
 __OMP_STRUCT_TYPE(AsyncInfo, __tgt_async_info, Int8Ptr)
 
 #undef __OMP_STRUCT_TYPE
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -715,6 +715,27 @@
   /// Value.
   GlobalValue *createGlobalFlag(unsigned Value, StringRef Name);
 
+  /// Create an offloading section struct used to register this global at
+  /// runtime.
+  ///
+  /// Type struct __tgt_offload_entry{
+  ///   void*addr;  // Pointer to the offload entry info.
+  ///   // (function or global)
+  ///   char*name;  // Name of the function or global.
+  ///   size_t  size;   // Size of the entry info (0 if it a function).
+  ///   int32_t flags;
+  ///   int32_t reserved;
+  /// };
+  ///
+  /// \param ID The pointer to the global being registered.
+  /// \param Addr The named address associated with the global.
+  /// \param Size The size in bytes of the global (0 for functions).
+  /// \param Flags Flags associated with the entry.
+  /// \param SectionName The section this entry will be placed at.
+  void emitOffloadingEntry(Constant *ID, Constant *Addr, uint64_t Size,
+   int32_t Flags,
+   StringRef SectionName = "omp_offloading_entries");
+
   /// Gener

[PATCH] D123460: [OpenMP] Make generating offloading entries more generic

2022-04-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 421764.
jhuber6 added a comment.

clang format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123460

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -598,6 +598,46 @@
   return Builder.saveIP();
 }
 
+void OpenMPIRBuilder::emitOffloadingEntry(Constant *ID, Constant *Addr,
+  uint64_t Size, int32_t Flags,
+  StringRef SectionName) {
+  Type *Int8PtrTy = Type::getInt8PtrTy(M.getContext());
+  Type *Int32Ty = Type::getInt32Ty(M.getContext());
+  Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
+
+  Constant *AddrName =
+  ConstantDataArray::getString(M.getContext(), Addr->getName());
+
+  // Create the constant string used to look up the symbol in the device.
+  auto *Str =
+  new llvm::GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
+   llvm::GlobalValue::InternalLinkage, AddrName,
+   ".omp_offloading.entry_name");
+  Str->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
+  // Construct the offloading entry.
+  Constant *EntryData[] = {
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(ID, Int8PtrTy),
+  ConstantExpr::getPointerBitCastOrAddrSpaceCast(Str, Int8PtrTy),
+  ConstantInt::get(SizeTy, Size),
+  ConstantInt::get(Int32Ty, Flags),
+  ConstantInt::get(Int32Ty, 0),
+  };
+  Constant *EntryInitializer =
+  ConstantStruct::get(OpenMPIRBuilder::OffloadEntry, EntryData);
+
+  auto *Entry = new GlobalVariable(
+  M, OpenMPIRBuilder::OffloadEntry,
+  /* isConstant = */ true, GlobalValue::WeakAnyLinkage, EntryInitializer,
+  ".omp_offloading.entry." + Addr->getName(), nullptr,
+  GlobalValue::NotThreadLocal,
+  M.getDataLayout().getDefaultGlobalsAddressSpace());
+
+  // The entry has to be created in the section the linker expects it to be.
+  Entry->setSection(SectionName);
+  Entry->setAlignment(Align(1));
+}
+
 void OpenMPIRBuilder::emitCancelationCheckImpl(Value *CancelFlag,
omp::Directive CanceledDirective,
FinalizeCallbackTy ExitCB) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -86,6 +86,8 @@
   OMP_STRUCT_TYPE(VarName, "struct." #Name, __VA_ARGS__)
 
 __OMP_STRUCT_TYPE(Ident, ident_t, Int32, Int32, Int32, Int32, Int8Ptr)
+__OMP_STRUCT_TYPE(OffloadEntry, __tgt_offload_entry, Int8Ptr, Int8Ptr, SizeTy,
+  Int32, Int32)
 __OMP_STRUCT_TYPE(AsyncInfo, __tgt_async_info, Int8Ptr)
 
 #undef __OMP_STRUCT_TYPE
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -715,6 +715,27 @@
   /// Value.
   GlobalValue *createGlobalFlag(unsigned Value, StringRef Name);
 
+  /// Create an offloading section struct used to register this global at
+  /// runtime.
+  ///
+  /// Type struct __tgt_offload_entry{
+  ///   void*addr;  // Pointer to the offload entry info.
+  ///   // (function or global)
+  ///   char*name;  // Name of the function or global.
+  ///   size_t  size;   // Size of the entry info (0 if it a function).
+  ///   int32_t flags;
+  ///   int32_t reserved;
+  /// };
+  ///
+  /// \param ID The pointer to the global being registered.
+  /// \param Addr The named address associated with the global.
+  /// \param Size The size in bytes of the global (0 for functions).
+  /// \param Flags Flags associated with the entry.
+  /// \param SectionName The section this entry will be placed at.
+  void emitOffloadingEntry(Constant *ID, Constant *Addr, uint64_t Size,
+   int32_t Flags,
+   StringRef SectionName = "omp_offloading_entries");
+
   /// Generate control flow and cleanup for cancellation.
   ///
   /// \param CancelFlag Flag indicating if the cancellation is performed.
Index: clang/lib/CodeGen/CGOpenMPRuntime.h
===
--- clang/lib/CodeGen/CGOpenMPRuntime.h
+++ clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -518,15 +518,6 @@
   ///  kmp_int64 st; // stride
   /// };
   Qual

[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-04-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 421768.
cor3ntin added a comment.

Add missing header in generated code to fix windows CI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ScopedPrinter.cpp
  llvm/lib/Support/StringExtras.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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