[clang] b92d6dd - [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files

2024-03-16 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-03-16T22:24:11-07:00
New Revision: b92d6dd704d789240685a336ad8b25a9f381b4cc

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

LOG: [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files

Added: 


Modified: 
clang/lib/Format/AffectedRangeManager.cpp
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/MacroCallReconstructor.cpp
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/NamespaceEndCommentsFixer.cpp
clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UsingDeclarationsSorter.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/lib/Format/AffectedRangeManager.cpp 
b/clang/lib/Format/AffectedRangeManager.cpp
index bf124d73e89e71..ae08965714b1b7 100644
--- a/clang/lib/Format/AffectedRangeManager.cpp
+++ b/clang/lib/Format/AffectedRangeManager.cpp
@@ -13,7 +13,6 @@
 
 #include "AffectedRangeManager.h"
 
-#include "FormatToken.h"
 #include "TokenAnnotator.h"
 
 namespace clang {

diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 75304908dc6506..c33b74eeb80b4a 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -15,10 +15,6 @@
 #include "BreakableToken.h"
 #include "ContinuationIndenter.h"
 #include "clang/Basic/CharInfo.h"
-#include "clang/Format/Format.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Debug.h"
-#include 
 
 #define DEBUG_TYPE "format-token-breaker"
 

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 964f1ead806bfb..3987f2185450ec 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -14,15 +14,6 @@
 #include "ContinuationIndenter.h"
 #include "BreakableToken.h"
 #include "FormatInternal.h"
-#include "FormatToken.h"
-#include "WhitespaceManager.h"
-#include "clang/Basic/OperatorPrecedence.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TokenKinds.h"
-#include "clang/Format/Format.h"
-#include "llvm/ADT/StringSet.h"
-#include "llvm/Support/Debug.h"
-#include 
 
 #define DEBUG_TYPE "format-indenter"
 

diff  --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..32fc77de4407cc 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -14,7 +14,6 @@
 
//===--===//
 
 #include "DefinitionBlockSeparator.h"
-#include "llvm/Support/Debug.h"
 #define DEBUG_TYPE "definition-block-separator"
 
 namespace clang {

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 665b2e43259b21..a63db8cc795277 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -14,9 +14,6 @@
 
 #include "FormatToken.h"
 #include "ContinuationIndenter.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Debug.h"
-#include 
 
 namespace clang {
 namespace format {

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 717eb6bb49b1f4..a1c8df80e6a9f5 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -13,11 +13,7 @@
 
//===--===//
 
 #include "FormatTokenLexer.h"
-#include "FormatToken.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Format/Format.h"
-#include "llvm/Support/Regex.h"
 
 namespace clang {
 namespace format {

diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
index 101acefdfe7a31..5ba4f2c99a6afa 100644
--- a/clang/lib/Format/MacroCallReconstructor.cpp
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -16,10 +16,7 @@
 #include "Macros.h"
 
 #include "UnwrappedLineParser.h"
-#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/Support/Debug.h"
-#include 
 
 #define DEBUG_TYPE "format-reconstruct"
 

diff  --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index 5a1cdd884c5e69..7668765

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-16 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeList

[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/85174

>From 7e1cf74f4fc9271e88b62462ea9a38826fd3ee38 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)strict-align for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mstrict-align is used for
pre-R6, lwl/lwr won't be disabled.

If -mstrict-align is used for r6 and the access is not well
aligned, some lb/lh instructions will be used to replace lw.
This is useful for OS kernels.

To be back-compatible with GCC, -m(no-)unaligned-access are also
added as Neg-Alias of -m(no-)strict-align.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  9 +++
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  2 +-
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 145 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acb7592e98100a..6567e7a7a9a745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4704,9 +4704,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned (AArch32 only)">;
+  HelpText<"Allow memory accesses to be unaligned (AArch32/MIPSr6 only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned (AArch32 only)">;
+  HelpText<"Force all memory accesses to be aligned (AArch32/MIPSr6 only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..74a8874a3ea2b7 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,15 @@ void mips::getMIPSTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))
+  Features.push_back(Args.MakeArgString("+strict-align"));
+else
+  Features.push_back(Args.MakeArgString("-strict-align"));
+  }
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..5e92dccaa02abb 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STRICT-ALIGN %s
+// CHECK-STRICT-ALIGN: "-target-feature" "+strict-align"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-STRICT-ALIGN %s
+// CHECK-NO-STRICT-ALIGN: "-target-feature" "-strict-align"
+//
+// -mstrict-align
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mstrict-align 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-S

[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-16 Thread via cfe-commits

Sirraide wrote:

> This is not really an NFC change so you should have waited for an approval.

Yeah, that’s something I wasn’t sure about in this particular case: The code 
that was causing the problem was added and merged in by me earlier this week, 
so I figured it was fine (and this seemed like an ‘obvious’ fix seeing as this 
is what we’re also checking for in codegen), but I can wait for approval next 
time if a situation like this comes up again.

https://github.com/llvm/llvm-project/pull/85534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/85174
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/85174

>From e75523f5ab1bb58a495afdd30203a0c7c93c7ec4 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)strict-align for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mstrict-align is used for
pre-R6, lwl/lwr won't be disabled.

If -mstrict-align is used for r6 and the access is not well
aligned, some lb/lh instructions will be used to replace lw.
This is useful for OS kernels.

To be back-compatible with GCC, -m(no-)unaligned-access are also
added as Neg-Alias of -m(no-)strict-align.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp | 13 
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  2 +-
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 149 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acb7592e98100a..6567e7a7a9a745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4704,9 +4704,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned (AArch32 only)">;
+  HelpText<"Allow memory accesses to be unaligned (AArch32/MIPSr6 only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned (AArch32 only)">;
+  HelpText<"Force all memory accesses to be aligned (AArch32/MIPSr6 only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..b6c8a897106f20 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,19 @@ void mips::getMIPSTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  AddTargetFeature(Args, Features, options::OPT_mstrict_align,
+   options::OPT_mno_strict_align, "strict-align");
+  AddTargetFeature(Args, Features, options::OPT_mno_unaligned_access,
+   options::OPT_munaligned_access, "strict-align");
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))
+  Features.push_back(Args.MakeArgString("+strict-align"));
+else
+  Features.push_back(Args.MakeArgString("-strict-align"));
+  }
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..5e92dccaa02abb 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STRICT-ALIGN %s
+// CHECK-STRICT-ALIGN: "-target-feature" "+strict-align"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-STRICT-ALIGN %s
+//

[clang] [ObjC] Add reserved field in 64-bit ABI mode (PR #85487)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85487

>From b881ab8ff6d89860c5f49dec3baa63ed639edef3 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 19:58:03 -0400
Subject: [PATCH] [ObjC] Add reserved field in 64-bit ABI mode

---
 clang/lib/CodeGen/CGObjCMac.cpp | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..9f59a3a371ac33 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6047,11 +6047,17 @@ 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
   //   const struct _prop_list_t * const properties;
   // }
 
-  // FIXME. Add 'reserved' field in 64bit abi mode!
-  ClassRonfABITy = llvm::StructType::create(
-  "struct._class_ro_t", IntTy, IntTy, IntTy, Int8PtrTy, Int8PtrTy,
-  MethodListnfABIPtrTy, ProtocolListnfABIPtrTy, IvarListnfABIPtrTy,
-  Int8PtrTy, PropertyListPtrTy);
+  if (CGM.getTarget().getTriple().isArch64Bit())
+ClassRonfABITy = llvm::StructType::create(
+// Extra reserved field in 64-bit ABI
+"struct._class_ro_t", IntTy, IntTy, IntTy, IntTy, Int8PtrTy, Int8PtrTy,
+MethodListnfABIPtrTy, ProtocolListnfABIPtrTy, IvarListnfABIPtrTy,
+Int8PtrTy, PropertyListPtrTy);
+  else
+ClassRonfABITy = llvm::StructType::create(
+"struct._class_ro_t", IntTy, IntTy, IntTy, Int8PtrTy, Int8PtrTy,
+MethodListnfABIPtrTy, ProtocolListnfABIPtrTy, IvarListnfABIPtrTy,
+Int8PtrTy, PropertyListPtrTy);
 
   // ImpnfABITy - LLVM for id (*)(id, SEL, ...)
   llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy };

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


[clang] [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (PR #85465)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85465

>From 3e11da62fc4e0df9b3b6dc3456c879ec69a12799 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 16:43:10 -0400
Subject: [PATCH] [ObjC] Expand isClassLayoutKnownStatically to base classes as
 long as the implementation of it is known

Only NSObject we can trust the layout of won't change even though we cannot 
directly see its @implementation.
---
 clang/lib/CodeGen/CGObjCMac.cpp   |  9 -
 clang/test/CodeGenObjC/arc-blocks.m   |  8 ++---
 clang/test/CodeGenObjC/arc-property.m | 22 +---
 clang/test/CodeGenObjC/arc-weak-property.m|  5 ++-
 clang/test/CodeGenObjC/arc.m  | 18 --
 clang/test/CodeGenObjC/arm64-int32-ivar.m |  5 ++-
 .../test/CodeGenObjC/bitfield-ivar-offsets.m  |  5 ++-
 .../constant-non-fragile-ivar-offset.m| 34 +--
 clang/test/CodeGenObjC/direct-method.m|  3 +-
 clang/test/CodeGenObjC/hidden-visibility.m|  2 +-
 clang/test/CodeGenObjC/interface-layout-64.m  | 16 +
 .../CodeGenObjC/ivar-base-as-invariant-load.m |  5 ++-
 clang/test/CodeGenObjC/metadata-symbols-64.m  |  4 +--
 .../nontrivial-c-struct-property.m|  4 ++-
 .../CodeGenObjC/objc-asm-attribute-test.m |  5 +--
 clang/test/CodeGenObjC/ubsan-bool.m   |  4 ++-
 16 files changed, 96 insertions(+), 53 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..da47ef786cf816 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1595,6 +1595,11 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
 // Test a class by checking its superclasses up to
 // its base class if it has one.
+
+// Cannot check a null class
+if (!ID)
+  return false;
+
 for (; ID; ID = ID->getSuperClass()) {
   // The layout of base class NSObject
   // is guaranteed to be statically known
@@ -1606,7 +1611,9 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   if (!ID->getImplementation())
 return false;
 }
-return false;
+
+// We know the layout of all the intermediate classes and superclasses.
+return true;
   }
 
 public:
diff --git a/clang/test/CodeGenObjC/arc-blocks.m 
b/clang/test/CodeGenObjC/arc-blocks.m
index 105a72b4af1e1f..d1d299bb22b1e5 100644
--- a/clang/test/CodeGenObjC/arc-blocks.m
+++ b/clang/test/CodeGenObjC/arc-blocks.m
@@ -422,16 +422,16 @@ @interface Test12
 @implementation Test12
 @synthesize ablock, nblock;
 // CHECK:define internal ptr @"\01-[Test12 ablock]"(
-// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, i1 noundef zeroext true)
+// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, i1 noundef zeroext true)
 
 // CHECK:define internal void @"\01-[Test12 setAblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
 
 // CHECK:define internal ptr @"\01-[Test12 nblock]"(
-// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 %ivar
+// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 8
 
 // CHECK:define internal void @"\01-[Test12 setNblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 8, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
 @end
 
 void test13(id x) {
diff --git a/clang/test/CodeGenObjC/arc-property.m 
b/clang/test/CodeGenObjC/arc-property.m
index f57be6b4f6be41..3209993cc6d32c 100644
--- a/clang/test/CodeGenObjC/arc-property.m
+++ b/clang/test/CodeGenObjC/arc-property.m
@@ -22,16 +22,14 @@ @implementation Test1
 @end
 //   The getter should be a simple load.
 // CHECK:define internal ptr @"\01-[Test1 pointer]"(
-// CHECK:  [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 
[[OFFSET]]
+// CHECK: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 0
 // CHECK-NEXT: [[T3:%.*]] = load ptr, ptr [[T1]], align 8
 // CHECK-NEXT: ret ptr [[T3]]
 
 //   The setter should be using objc_setProperty.
 // CHECK:define internal void @"\01-[Test1 setPointer:]"(
-// CHECK: [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK-NEXT: [[T1:%.*]] = load ptr, ptr {{%.*}}
-// CHECK-NEXT: call void

[clang] [clang-format] Fix a bug in SpaceInEmptyBlock option (PR #85508)

2024-03-16 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/85508
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d33d563 - [clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)

2024-03-16 Thread via cfe-commits

Author: Owen Pan
Date: 2024-03-16T14:48:51-07:00
New Revision: d33d5630b281debe6eabd67e323bcf767340fb6a

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

LOG: [clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)

Fixes #84695.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1342d37a147915..5a715ac8a5f23f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4271,6 +4271,10 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 return Left.is(tok::hash);
   if (Left.isOneOf(tok::hashhash, tok::hash))
 return Right.is(tok::hash);
+  if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
+  Right.MatchingParen == &Left && Line.Children.empty()) {
+return Style.SpaceInEmptyBlock;
+  }
   if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
   (Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index add92d3e111089..1f2e8ceb58ceff 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6959,6 +6959,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
"else if (b) { }\n"
"else { }",
Style);
+
+  Style = getLLVMStyle(FormatStyle::LK_CSharp);
+  Style.SpaceInEmptyBlock = true;
+  verifyFormat("Event += () => { };", Style);
 }
 
 TEST_F(FormatTest, FormatBeginBlockEndMacros) {



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


[clang] [Sema] Allow -Wno-main to suppress the arg wrong error (PR #85494)

2024-03-16 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/85494

>From 0fd3675447f41b033472f9269648e8e735bc543a Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Fri, 15 Mar 2024 20:26:52 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td  |  4 ++--
 clang/lib/Sema/SemaDecl.cpp   |  2 +-
 .../CXX/basic/basic.start/basic.start.main/p2.cpp | 11 +++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e97902564af08..6cf4e288af5f1f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -950,9 +950,9 @@ def err_main_surplus_args : Error<"too many parameters (%0) 
for 'main': "
 "must be 0, 2, or 3">;
 def warn_main_one_arg : Warning<"only one parameter on 'main' declaration">,
 InGroup;
-def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 "
+def warn_main_arg_wrong : Warning<"%select{first|second|third|fourth}0 "
 "parameter of 'main' (%select{argument count|argument array|environment|"
-"platform-specific data}0) must be of type %1">;
+"platform-specific data}0) must be of type %1">, DefaultError, 
InGroup;
 def warn_main_returns_bool_literal : Warning<"bool literal returned from "
 "'main'">, InGroup;
 def err_main_global_variable :
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9aa..2718934609842b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12488,7 +12488,7 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& 
DS) {
 }
 
 if (mismatch) {
-  Diag(FD->getLocation(), diag::err_main_arg_wrong) << i << Expected[i];
+  Diag(FD->getLocation(), diag::warn_main_arg_wrong) << i << Expected[i];
   // TODO: suggest replacing given type with expected type
   FD->setInvalidDecl(true);
 }
diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp 
b/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp
index 42e87e5431f2a5..135c828e7366a0 100644
--- a/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp
+++ b/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST4
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST5
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST6
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST6A -Wno-main
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST7
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST8
 
@@ -64,6 +65,16 @@ main( // expected-error {{first parameter of 'main' 
(argument count) must be of
 
 const int main(); // expected-error {{'main' must return 'int'}}
 
+#elif TEST6A
+
+void  // expected-error {{'main' must return 'int'}}
+main(
+ float a
+) {
+}
+
+const int main(); // expected-error {{'main' must return 'int'}}
+
 #elif TEST7
 
 // expected-no-diagnostics

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


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-16 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This is not really an NFC change so you should have waited for an approval. 
This LGTM

https://github.com/llvm/llvm-project/pull/85534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)

2024-03-16 Thread via cfe-commits

scythris wrote:

Thank you @HazardyKnusperkeks 

Would somebody else be able to merge? I don't have access.

https://github.com/llvm/llvm-project/pull/85470
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (PR #85465)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85465

>From d7784045d0b6a5cf9c9a55bac4604361ec7e5e7d Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 16:43:10 -0400
Subject: [PATCH] [ObjC] Expand isClassLayoutKnownStatically to base classes as
 long as the implementation of it is known

Only NSObject we can trust the layout of won't change even though we cannot 
directly see its @implementation
---
 clang/lib/CodeGen/CGObjCMac.cpp   |  9 +-
 .../constant-non-fragile-ivar-offset.m| 30 ++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..da47ef786cf816 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1595,6 +1595,11 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
 // Test a class by checking its superclasses up to
 // its base class if it has one.
+
+// Cannot check a null class
+if (!ID)
+  return false;
+
 for (; ID; ID = ID->getSuperClass()) {
   // The layout of base class NSObject
   // is guaranteed to be statically known
@@ -1606,7 +1611,9 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   if (!ID->getImplementation())
 return false;
 }
-return false;
+
+// We know the layout of all the intermediate classes and superclasses.
+return true;
   }
 
 public:
diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 8d55e6c7d23081..ee4034e4b7f205 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -8,6 +8,12 @@
 // CHECK: @"OBJC_IVAR_$_IntermediateClass._intermediateProperty" = hidden 
constant i64 48
 // CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = constant i64 56
 // CHECK: @"OBJC_IVAR_$_SubClass._subClassProperty" = hidden constant i64 64
+
+// CHECK: @"OBJC_IVAR_$_RootClass.these" = constant i64 0
+// CHECK: @"OBJC_IVAR_$_RootClass.dont" = constant i64 4
+// CHECK: @"OBJC_IVAR_$_RootClass.change" = constant i64 4
+// CHECK: @"OBJC_IVAR_$_StillStaticLayout.static_layout_ivar" = hidden global 
i32 12
+
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -120,7 +126,29 @@ -(void)intermediateSubclassVar {
 // CHECK: getelementptr inbounds i8, ptr %1, i64 64
 @end
 
-@interface NotNSObject {
+ __attribute((objc_root_class))  @interface RootClass {
+  int these, dont, change;
+}
+@end
+
+@implementation RootClass 
+@end
+
+@interface StillStaticLayout : RootClass
+@end
+
+@implementation StillStaticLayout {
+  int static_layout_ivar;
+}
+
+// CHECK-LABEL: define internal void @"\01-[StillStaticLayout meth]"
+-(void)meth {
+  static_layout_ivar = 0;
+  // CHECK-NOT: load i64, ptr @"OBJC_IVAR_$StillStaticLayout.static_layout_ivar
+}
+@end
+
+__attribute((objc_root_class))  @interface NotNSObject {
   int these, might, change;
 }
 @end

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


[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)

2024-03-16 Thread Ameer J via cfe-commits

https://github.com/ameerj updated 
https://github.com/llvm/llvm-project/pull/84988

>From 0d0868ddffe1b0668a57c10cc89614ab7c840634 Mon Sep 17 00:00:00 2001
From: ameerj 
Date: Sat, 16 Mar 2024 17:03:47 -0400
Subject: [PATCH] [clang-format] Add BreakFunctionDefinitionParameters option

---
 clang/docs/ClangFormatStyleOptions.rst |  6 ++
 clang/include/clang/Format/Format.h|  7 +++
 clang/lib/Format/Format.cpp|  3 +++
 clang/lib/Format/FormatToken.h |  3 +++
 clang/lib/Format/TokenAnnotator.cpp|  7 +++
 clang/unittests/Format/FormatTest.cpp  | 18 ++
 6 files changed, 44 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 5b00a8f4c00fb8..a5e710e21c8338 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3150,6 +3150,12 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakFunctionDefinitionParameters:
+
+**BreakFunctionDefinitionParameters** (``Boolean``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  If ``true``, clang-format will always break before function definition
+  parameters
+
 .. _BreakInheritanceList:
 
 **BreakInheritanceList** (``BreakInheritanceListStyle``) 
:versionbadge:`clang-format 7` :ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index a72c1b171c3e18..8bf3fac6176205 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2218,6 +2218,11 @@ struct FormatStyle {
   /// \version 3.8
   bool BreakAfterJavaFieldAnnotations;
 
+  /// If ``true``, clang-format will always break before function definition
+  /// parameters
+  /// \version 19
+  bool BreakFunctionDefinitionParameters;
+
   /// Allow breaking string literals when formatting.
   ///
   /// In C, C++, and Objective-C:
@@ -4867,6 +4872,8 @@ struct FormatStyle {
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
+   BreakFunctionDefinitionParameters ==
+   R.BreakFunctionDefinitionParameters &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d5d115a3c8db85..635f8123c402c7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -933,6 +933,8 @@ template <> struct MappingTraits {
 IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
 IO.mapOptional("BreakAfterReturnType", Style.BreakAfterReturnType);
+IO.mapOptional("BreakFunctionDefinitionParameters",
+   Style.BreakFunctionDefinitionParameters);
 IO.mapOptional("BreakArrays", Style.BreakArrays);
 IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
@@ -1443,6 +1445,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
+  LLVMStyle.BreakFunctionDefinitionParameters = false;
   LLVMStyle.BreakArrays = true;
   LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index c9022aba287187..d7cad8cec38948 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -569,6 +569,9 @@ struct FormatToken {
   /// Is optional and can be removed.
   bool Optional = false;
 
+  /// Might be function declaration open/closing paren.
+  bool MightBeFunctionDeclParen = false;
+
   /// Number of optional braces to be inserted after this token:
   ///   -1: a single left brace
   ///0: no braces
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1342d37a147915..352b2fac149b29 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1502,6 +1502,7 @@ class AnnotatingParser {
 (!Previous->isAttribute() &&
  !Previous->isOneOf(TT_RequiresClause, TT_LeadingJavaAnnotation))) 
{
   Line.MightBeFunctionDecl = true;
+  Tok->MightBeFunctionDeclParen = true;
 }
   }
   break;
@@ -5317,6 +5318,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
+  if (Style.BreakFunctionDefinitionParameters && Line.MightBeFunctionDecl &&
+  Line.mightBeFunctionDefinition() && Left.is(tok::l_paren) &&
+  Lef

[clang] [clang-format] Correctly parse C++11 attributes in enum specifiers (PR #85498)

2024-03-16 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/85498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 84b5178 - [clang-format] Correctly parse C++11 attributes in enum specifiers (#85498)

2024-03-16 Thread via cfe-commits

Author: Owen Pan
Date: 2024-03-16T13:51:36-07:00
New Revision: 84b5178124e47f6019b56c04abcfb978a94b1c3c

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

LOG: [clang-format] Correctly parse C++11 attributes in enum specifiers (#85498)

Fixes #85476.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index a1f6ce05e45ebc..2b893f7abe4023 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1224,7 +1224,6 @@ void UnwrappedLineParser::parsePPUnknown() {
 static bool tokenCanStartNewLine(const FormatToken &Tok) {
   // Semicolon can be a null-statement, l_square can be a start of a macro or
   // a C++11 attribute, but this doesn't seem to be common.
-  assert(Tok.isNot(TT_AttributeSquare));
   return !Tok.isOneOf(tok::semi, tok::l_brace,
   // Tokens that can only be used as binary operators and a
   // part of overloaded operator names.
@@ -3712,14 +3711,19 @@ bool UnwrappedLineParser::parseEnum() {
   if (Style.Language == FormatStyle::LK_Proto && FormatTok->is(tok::equal))
 return false;
 
-  // Eat up enum class ...
-  if (FormatTok->isOneOf(tok::kw_class, tok::kw_struct))
-nextToken();
+  if (IsCpp) {
+// Eat up enum class ...
+if (FormatTok->isOneOf(tok::kw_class, tok::kw_struct))
+  nextToken();
+while (FormatTok->is(tok::l_square))
+  if (!handleCppAttributes())
+return false;
+  }
 
   while (FormatTok->Tok.getIdentifierInfo() ||
  FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
 tok::greater, tok::comma, tok::question,
-tok::l_square, tok::r_square)) {
+tok::l_square)) {
 if (Style.isVerilog()) {
   FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
   nextToken();
@@ -3732,7 +3736,6 @@ bool UnwrappedLineParser::parseEnum() {
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();
-assert(FormatTok->isNot(TT_AttributeSquare));
 if (FormatTok->is(tok::identifier)) {
   nextToken();
   // If there are two identifiers in a row, this is likely an elaborate

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index fc367a7a5a8981..add92d3e111089 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3802,6 +3802,27 @@ TEST_F(FormatTest, FormatsEnum) {
"  // Comment 2\n"
"  TWO,\n"
"};");
+  verifyFormat("enum [[clang::enum_extensibility(open)]] E {\n"
+   "  // Comment 1\n"
+   "  ONE,\n"
+   "  // Comment 2\n"
+   "  TWO\n"
+   "};");
+  verifyFormat("enum [[nodiscard]] [[clang::enum_extensibility(open)]] E {\n"
+   "  // Comment 1\n"
+   "  ONE,\n"
+   "  // Comment 2\n"
+   "  TWO\n"
+   "};");
+  verifyFormat("enum [[clang::enum_extensibility(open)]] E { // foo\n"
+   "  A,\n"
+   "  // bar\n"
+   "  B\n"
+   "};",
+   "enum [[clang::enum_extensibility(open)]] E{// foo\n"
+   "   A,\n"
+   "   // bar\n"
+   "   B};");
 
   // Not enums.
   verifyFormat("enum X f() {\n"



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


[clang] [Sema] Allow -Wno-main to suppress the arg wrong error (PR #85494)

2024-03-16 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I believe this should have a release note.

https://github.com/llvm/llvm-project/pull/85494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in SpaceInEmptyBlock option (PR #85508)

2024-03-16 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/85508
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Correctly parse C++11 attributes in enum specifiers (PR #85498)

2024-03-16 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/85498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nolock/noalloc attributes (PR #84983)

2024-03-16 Thread via cfe-commits


@@ -3922,6 +3922,42 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
 return true;
   }
 
+  const auto OldFX = Old->getFunctionEffects();
+  const auto NewFX = New->getFunctionEffects();
+  if (OldFX != NewFX) {
+const auto Diffs = FunctionEffectSet::differences(OldFX, NewFX);
+for (const auto &Item : Diffs) {
+  const FunctionEffect *Effect = Item.first;
+  const bool Adding = Item.second;
+  if (Effect->diagnoseRedeclaration(Adding, *Old, OldFX, *New, NewFX)) {
+Diag(New->getLocation(),
+ diag::warn_mismatched_func_effect_redeclaration)
+<< Effect->name();
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }
+}
+
+const auto MergedFX = OldFX | NewFX;
+
+// Having diagnosed any problems, prevent further errors by applying the
+// merged set of effects to both declarations.
+auto applyMergedFX = [&](FunctionDecl *FD) {
+  const auto *FPT = FD->getType()->getAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.FunctionEffects = MergedFX;
+  QualType ModQT = Context.getFunctionType(FD->getReturnType(),
+   FPT->getParamTypes(), EPI);
+
+  FD->setType(ModQT);
+};
+
+applyMergedFX(Old);
+applyMergedFX(New);
+
+OldQType = Old->getType();

Sirraide wrote:

I personally feel like the macro solution is ‘good enough’, if you will; I 
don’t think `CheckEquivalentExceptionSpec` modifies `Old`, so I’m not sure why 
that comment says is does—maybe it did at the time (the comment is from 2016, 
and, funnily enough, was also added in the same commit that introduced that 
call to `isFunctionConversion()` where the arguments seem transposed).

There is one place where we call `setDeletedAsWritten(false)` on the old decl 
in a caller of `MergeFunctionDecl()`, but that one has a FIXME next to it, so...

I’ll ask if anyone’s aware of any specific reasons why or ways in which we 
should avoid modifying `Old` here, and if not, then I’ll see if I can make the 
pointer `const`, because that would communicate the intent more clearly that 
it’s really not supposed to be modified.

https://github.com/llvm/llvm-project/pull/84983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)

2024-03-16 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/85470
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-16 Thread via cfe-commits

github-actions[bot] wrote:



@alirezamoshtaghi Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/83369
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-16 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 closed 
https://github.com/llvm/llvm-project/pull/83369
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 2867095 - [clang] Skip implicit designators in DesignatedInitExpr::getBeginLoc (#83369)

2024-03-16 Thread via cfe-commits

Author: alirezamoshtaghi
Date: 2024-03-16T16:29:20-04:00
New Revision: 2867095917cef0d01a68b112bcb01e2f85de4308

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

LOG: [clang] Skip implicit designators in DesignatedInitExpr::getBeginLoc 
(#83369)

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
clang/lib/AST/Expr.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 42dd612c46..656b62c9a1f4e1 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -72,6 +72,22 @@ TEST_F(ExtractVariableTest, Test) {
 )cpp";
   EXPECT_UNAVAILABLE(NoCrashCasesC);
 
+  ExtraArgs = {"-xc"};
+  const char *NoCrashDesignator = R"cpp(
+struct A {
+  struct {
+int x;
+  };
+};
+struct B {
+  int y;
+};
+void foo(struct B *b) {
+  struct A a = {.x=b[[->]]y};
+}
+  )cpp";
+  EXPECT_AVAILABLE(NoCrashDesignator);
+
   ExtraArgs = {"-xobjective-c"};
   const char *AvailableObjC = R"cpp(
 __attribute__((objc_root_class))

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index f5ad402e3bd73e..131dace77f9c25 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4604,8 +4604,17 @@ SourceRange 
DesignatedInitExpr::getDesignatorsSourceRange() const {
 SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator &First = *DIE->getDesignator(0);
-  if (First.isFieldDesignator())
-return GNUSyntax ? First.getFieldLoc() : First.getDotLoc();
+  if (First.isFieldDesignator()) {
+// Skip past implicit designators for anonymous structs/unions, since
+// these do not have valid source locations.
+for (unsigned int i = 0; i < DIE->size(); i++) {
+  Designator &Des = *DIE->getDesignator(i);
+  SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
+  if (!retval.isValid())
+continue;
+  return retval;
+}
+  }
   return First.getLBracketLoc();
 }
 



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


[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/2] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85541

>From 214a2528f8f1383c997fc7906912bcb2993cf9d6 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 16 Mar 2024 12:07:21 -0400
Subject: [PATCH] Resolve FIXME: Look at E, not M.

---
 clang/lib/CodeGen/CGExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..0d17aa5863315f 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -316,13 +316,12 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   Destroy = &CodeGenFunction::destroyARCWeak;
 }
 if (Duration == SD_FullExpression)
-  CGF.pushDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(), *Destroy,
-  CleanupKind & EHCleanup);
+  CGF.pushDestroy(CleanupKind, ReferenceTemporary, E->getType(),
+  *Destroy, CleanupKind & EHCleanup);
 else
   CGF.pushLifetimeExtendedDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(),
-  *Destroy, CleanupKind & EHCleanup);
+  E->getType(), *Destroy,
+  CleanupKind & EHCleanup);
 return;
 
   case SD_Dynamic:

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


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/81976

>From 07c73f087a430f5115ecdfec23730c5afcab37f3 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 16 Feb 2024 14:26:36 +0530
Subject: [PATCH 1/3] fix unnecessary warning when using bitand with boolean

Signed-off-by: 11happy 
---
 clang/lib/Sema/SemaChecking.cpp | 24 ++--
 clang/test/Sema/warn-bitwise-and-bool.c |  4 ++--
 clang/test/Sema/warn-bitwise-or-bool.c  |  4 ++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..e43892cbf35890 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);
+
+  if (SR.str() == "&" || SR.str() == "|") {
+
+S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+<< (BO->getOpcode() == BO_And ? "&" : "|")
+<< OrigE->getSourceRange()
+<< FixItHint::CreateReplacement(
+   BO->getOperatorLoc(),
+   (BO->getOpcode() == BO_And ? "&&" : "||"));
+S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  }
 }
 
   // For conditional operators, we analyze the arguments as if they
diff --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
index 6bec1be1abdef6..23e7afcc59f8aa 100644
--- a/clang/test/Sema/warn-bitwise-and-bool.c
+++ b/clang/test/Sema/warn-bitwise-and-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() & (i > 4);
   b = (i == 7) & foo();
 #ifdef __cplusplus
-  b = foo() bitand bar(); // expected-warning {{use of bitwise '&' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitand bar(); // Ok, no warning expected
+  
 #endif
 
   if (foo() & bar())  // expected-warning {{use of bitwise '&' with 
boolean operands}}
diff --git a/clang/test/Sema/warn-bitwise-or-bool.c 
b/clang/test/Sema/warn-bitwise-or-bool.c
index ae86790901aac5..e84f59cf8f766a 100644
--- a/clang/test/Sema/warn-bitwise-or-bool.c
+++ b/clang/test/Sema/warn-bitwise-or-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() | (i > 4);
   b = (i == 7) | foo();
 #ifdef __cplusplus
-  b = foo() bitor bar();  // expected-warning {{use of bitwise '|' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitor bar();  //Ok, no warning expected
+  
 #endif
 
   if (foo() | bar())  // expected-warning {{use of bitwise '|' with 
boolean operands}}

>From a0ba9e05bb9d0443f386fd57eef3b4e6e2bd1217 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Sat, 16 Mar 2024 16:11:00 +0530
Subject: [PATCH 2/3] add release notes and add tests

Signed-off-by: 11happy 
---
 clang/docs/ReleaseNotes.rst |  5 +
 clang/lib/Sema/SemaChecking.cpp | 16 +---
 clang/test/Sema/warn-bitwise-and-bool.c |  6 ++
 clang/test/Sema/warn-bitwise-or-bool.c  |  4 
 4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 254e0a9cb72979..177f424abaa73c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@ Improvements to Clang's diagnostics
 - Clang now applies syntax highlighting to the code snippets it
   prints.
 
+- Clang now does not warn in cases where bitand operator is 
+  intentionally used with boolean operands, distinguishing it
+  from potential typographical errors or unintended bitwise operations.
+  Fixes (`#77601 `)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/Sema

[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85541

>From 369cd6fcebc22f926f7b002f64a44f866283a0c1 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 16 Mar 2024 12:07:21 -0400
Subject: [PATCH] Resolve FIXME: Look at E, not M.

---
 clang/lib/CodeGen/CGExpr.cpp | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..2f664ad3024eb3 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -316,13 +316,12 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   Destroy = &CodeGenFunction::destroyARCWeak;
 }
 if (Duration == SD_FullExpression)
-  CGF.pushDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(), *Destroy,
-  CleanupKind & EHCleanup);
+  CGF.pushDestroy(CleanupKind, ReferenceTemporary, E->getType(),
+  *Destroy, CleanupKind & EHCleanup);
 else
   CGF.pushLifetimeExtendedDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(),
-  *Destroy, CleanupKind & EHCleanup);
+  E->getType(), *Destroy,
+  CleanupKind & EHCleanup);
 return;
 
   case SD_Dynamic:
@@ -445,7 +444,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr 
*M) {
 
   // FIXME: ideally this would use EmitAnyExprToMem, however, we cannot do so
   // as that will cause the lifetime adjustment to be lost for ARC
-  auto ownership = M->getType().getObjCLifetime();
+  auto ownership = E->getType().getObjCLifetime();
   if (ownership != Qualifiers::OCL_None &&
   ownership != Qualifiers::OCL_ExplicitNone) {
 Address Object = createReferenceTemporary(*this, M, E);

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


[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff c51095f51b770f0663b65dd8a651601fca15701e 
e4af1febaa05e2749947b7cd406d65df5a1a7539 -- clang/lib/CodeGen/CGExpr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 0b8f43dab8..2f664ad302 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -316,13 +316,12 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   Destroy = &CodeGenFunction::destroyARCWeak;
 }
 if (Duration == SD_FullExpression)
-  CGF.pushDestroy(CleanupKind, ReferenceTemporary,
-  E->getType(), *Destroy,
-  CleanupKind & EHCleanup);
+  CGF.pushDestroy(CleanupKind, ReferenceTemporary, E->getType(),
+  *Destroy, CleanupKind & EHCleanup);
 else
   CGF.pushLifetimeExtendedDestroy(CleanupKind, ReferenceTemporary,
-  E->getType(),
-  *Destroy, CleanupKind & EHCleanup);
+  E->getType(), *Destroy,
+  CleanupKind & EHCleanup);
 return;
 
   case SD_Dynamic:

``




https://github.com/llvm/llvm-project/pull/85541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85541

>From e4af1febaa05e2749947b7cd406d65df5a1a7539 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 16 Mar 2024 12:07:21 -0400
Subject: [PATCH] Resolve FIXME: Look at E, not M.

---
 clang/lib/CodeGen/CGExpr.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..0b8f43dab8a8f0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -317,11 +317,11 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
 }
 if (Duration == SD_FullExpression)
   CGF.pushDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(), *Destroy,
+  E->getType(), *Destroy,
   CleanupKind & EHCleanup);
 else
   CGF.pushLifetimeExtendedDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(),
+  E->getType(),
   *Destroy, CleanupKind & EHCleanup);
 return;
 
@@ -445,7 +445,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr 
*M) {
 
   // FIXME: ideally this would use EmitAnyExprToMem, however, we cannot do so
   // as that will cause the lifetime adjustment to be lost for ARC
-  auto ownership = M->getType().getObjCLifetime();
+  auto ownership = E->getType().getObjCLifetime();
   if (ownership != Qualifiers::OCL_None &&
   ownership != Qualifiers::OCL_ExplicitNone) {
 Address Object = createReferenceTemporary(*this, M, E);

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


[clang] nolock/noalloc attributes (PR #84983)

2024-03-16 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos edited 
https://github.com/llvm/llvm-project/pull/84983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nolock/noalloc attributes (PR #84983)

2024-03-16 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos edited 
https://github.com/llvm/llvm-project/pull/84983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nolock/noalloc attributes (PR #84983)

2024-03-16 Thread Doug Wyatt via cfe-commits


@@ -3922,6 +3922,42 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
 return true;
   }
 
+  const auto OldFX = Old->getFunctionEffects();
+  const auto NewFX = New->getFunctionEffects();
+  if (OldFX != NewFX) {
+const auto Diffs = FunctionEffectSet::differences(OldFX, NewFX);
+for (const auto &Item : Diffs) {
+  const FunctionEffect *Effect = Item.first;
+  const bool Adding = Item.second;
+  if (Effect->diagnoseRedeclaration(Adding, *Old, OldFX, *New, NewFX)) {
+Diag(New->getLocation(),
+ diag::warn_mismatched_func_effect_redeclaration)
+<< Effect->name();
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }
+}
+
+const auto MergedFX = OldFX | NewFX;
+
+// Having diagnosed any problems, prevent further errors by applying the
+// merged set of effects to both declarations.
+auto applyMergedFX = [&](FunctionDecl *FD) {
+  const auto *FPT = FD->getType()->getAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.FunctionEffects = MergedFX;
+  QualType ModQT = Context.getFunctionType(FD->getReturnType(),
+   FPT->getParamTypes(), EPI);
+
+  FD->setType(ModQT);
+};
+
+applyMergedFX(Old);
+applyMergedFX(New);
+
+OldQType = Old->getType();

dougsonos wrote:

> > A workaround would be to create wrapper functions that are declared safe 
> > but call the unsafe function with diagnostics disabled.
> 
> I could see there being situations where you might want to be able to do 
> something like that (i.e. declare a function as safe even if the compiler 
> might think it’s unsafe because it calls unsafe functions), but I wonder if 
> you couldn’t just disable the diagnostics locally in that function (or even 
> just parts thereof) only using a `#pragma`.

Yes, though that could make it difficult to distinguish between
- calls that are truly unsafe but where disabling warnings is needed in the 
short term
- calls that are truly safe but where annotation hasn't yet caught up (e.g. 
https://developer.apple.com/documentation/kernel/1532191-vdsp_vadd )

On the other hand, it is practical to disable diagnostics through a macro 
including pragmas. The user could employ two different macros to disable 
diagnostics, and the macro names would express the difference between the two 
situations.

https://github.com/llvm/llvm-project/pull/84983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd212..2ccc607d4b63dcd 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1ce..5ed2e23425dc5fe 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85106
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f2794cc - [InstallAPI] Introduce Basic Verifier (#85106)

2024-03-16 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-16T10:37:52-07:00
New Revision: f2794ccede6d32a6b5ef7a376ced420331e2be27

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

LOG: [InstallAPI] Introduce Basic Verifier (#85106)

This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will check against the dylib's symbol table.

Added: 
clang/lib/InstallAPI/DylibVerifier.cpp
clang/test/InstallAPI/asm.test

Modified: 
clang/include/clang/AST/Availability.h
clang/include/clang/InstallAPI/Context.h
clang/include/clang/InstallAPI/DylibVerifier.h
clang/include/clang/InstallAPI/Frontend.h
clang/include/clang/InstallAPI/FrontendRecords.h
clang/include/clang/InstallAPI/MachO.h
clang/lib/InstallAPI/CMakeLists.txt
clang/lib/InstallAPI/Frontend.cpp
clang/lib/InstallAPI/Visitor.cpp
clang/tools/clang-installapi/ClangInstallAPI.cpp
clang/tools/clang-installapi/Options.cpp
llvm/include/llvm/TextAPI/Record.h

Removed: 




diff  --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index ae3acbeffe7f18..5cfbaf0cdfbd21 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -75,6 +75,9 @@ struct AvailabilityInfo {
   /// Determine if this AvailabilityInfo represents the default availability.
   bool isDefault() const { return *this == AvailabilityInfo(); }
 
+  /// Check if the symbol has been obsoleted.
+  bool isObsoleted() const { return !Obsoleted.empty(); }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode

diff  --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index bdb576d7d85fb6..54e517544b8edf 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -11,6 +11,7 @@
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/DylibVerifier.h"
 #include "clang/InstallAPI/HeaderFile.h"
 #include "clang/InstallAPI/MachO.h"
 #include "llvm/ADT/DenseMap.h"
@@ -45,6 +46,9 @@ struct InstallAPIContext {
   /// DiagnosticsEngine for all error reporting.
   DiagnosticsEngine *Diags = nullptr;
 
+  /// Verifier when binary dylib is passed as input.
+  std::unique_ptr Verifier = nullptr;
+
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
 

diff  --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 1a6121b3a258b5..72c4743fdf65e0 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -9,10 +9,12 @@
 #ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 #define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 
-#include "llvm/TextAPI/Target.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/InstallAPI/MachO.h"
 
 namespace clang {
 namespace installapi {
+struct FrontendAttrs;
 
 /// A list of InstallAPI verification modes.
 enum class VerificationMode {
@@ -22,6 +24,81 @@ enum class VerificationMode {
   Pedantic,
 };
 
+/// Service responsible to tracking state of verification across the
+/// lifetime of InstallAPI.
+/// As declarations are collected during AST traversal, they are
+/// compared as symbols against what is available in the binary dylib.
+class DylibVerifier {
+private:
+  struct SymbolContext;
+
+public:
+  enum class Result { NoVerify, Ignore, Valid, Invalid };
+  struct VerifierContext {
+// Current target being verified against the AST.
+llvm::MachO::Target Target;
+
+// Query state of verification after AST has been traversed.
+Result FrontendState;
+
+// First error for AST traversal, which is tied to the target triple.
+bool DiscoveredFirstError;
+  };
+
+  DylibVerifier() = default;
+
+  DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
+VerificationMode Mode, bool Demangle)
+  : Dylib(std::move(Dylib)), Diag(Diag), Mode(Mode), Demangle(Demangle),
+Exports(std::make_unique()) {}
+
+  Result verify(GlobalRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
+const StringRef SuperClass);
+
+  /// Initialize target for verification.
+  void setTarget(const Target &T);
+
+  /// Release ownership over exports.
+  std::unique_ptr getExports() { return std::move(Exports); }
+
+  /// Get result of verification.
+  Result getState() const { return Ctx.FrontendState; }
+
+private:
+  /// Determine whe

[clang] [llvm] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/85348
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85106

>From 3f0def7f7f56c80af04eecb7b6d11bf3757c8c82 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 12 Mar 2024 20:56:23 -0700
Subject: [PATCH 1/2] [InstallAPI] Introduce Basic Verifier

This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will actually check against the dylib's symbol table.
---
 clang/include/clang/AST/Availability.h|   3 +
 clang/include/clang/InstallAPI/Context.h  |   4 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  79 ++-
 clang/include/clang/InstallAPI/Frontend.h |   1 -
 .../clang/InstallAPI/FrontendRecords.h|  49 ++--
 clang/include/clang/InstallAPI/MachO.h|   3 +
 clang/lib/InstallAPI/CMakeLists.txt   |   2 +
 clang/lib/InstallAPI/DylibVerifier.cpp| 212 ++
 clang/lib/InstallAPI/Frontend.cpp |  49 ++--
 clang/lib/InstallAPI/Visitor.cpp  | 101 +
 clang/test/InstallAPI/asm.test|  90 
 .../clang-installapi/ClangInstallAPI.cpp  |  12 +-
 clang/tools/clang-installapi/Options.cpp  |   9 +-
 llvm/include/llvm/TextAPI/Record.h|   7 +-
 14 files changed, 524 insertions(+), 97 deletions(-)
 create mode 100644 clang/lib/InstallAPI/DylibVerifier.cpp
 create mode 100644 clang/test/InstallAPI/asm.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index ae3acbeffe7f18..5cfbaf0cdfbd21 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -75,6 +75,9 @@ struct AvailabilityInfo {
   /// Determine if this AvailabilityInfo represents the default availability.
   bool isDefault() const { return *this == AvailabilityInfo(); }
 
+  /// Check if the symbol has been obsoleted.
+  bool isObsoleted() const { return !Obsoleted.empty(); }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index bdb576d7d85fb6..074ff6f969773c 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -18,6 +18,7 @@
 namespace clang {
 namespace installapi {
 class FrontendRecordsSlice;
+class DylibVerifier;
 
 /// Struct used for generating validating InstallAPI.
 /// The attributes captured represent all necessary information
@@ -45,6 +46,9 @@ struct InstallAPIContext {
   /// DiagnosticsEngine for all error reporting.
   DiagnosticsEngine *Diags = nullptr;
 
+  /// Verifier when binary dylib is passed as input.
+  std::unique_ptr Verifier = nullptr;
+
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
 
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 1a6121b3a258b5..72c4743fdf65e0 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -9,10 +9,12 @@
 #ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 #define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 
-#include "llvm/TextAPI/Target.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/InstallAPI/MachO.h"
 
 namespace clang {
 namespace installapi {
+struct FrontendAttrs;
 
 /// A list of InstallAPI verification modes.
 enum class VerificationMode {
@@ -22,6 +24,81 @@ enum class VerificationMode {
   Pedantic,
 };
 
+/// Service responsible to tracking state of verification across the
+/// lifetime of InstallAPI.
+/// As declarations are collected during AST traversal, they are
+/// compared as symbols against what is available in the binary dylib.
+class DylibVerifier {
+private:
+  struct SymbolContext;
+
+public:
+  enum class Result { NoVerify, Ignore, Valid, Invalid };
+  struct VerifierContext {
+// Current target being verified against the AST.
+llvm::MachO::Target Target;
+
+// Query state of verification after AST has been traversed.
+Result FrontendState;
+
+// First error for AST traversal, which is tied to the target triple.
+bool DiscoveredFirstError;
+  };
+
+  DylibVerifier() = default;
+
+  DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
+VerificationMode Mode, bool Demangle)
+  : Dylib(std::move(Dylib)), Diag(Diag), Mode(Mode), Demangle(Demangle),
+Exports(std::make_unique()) {}
+
+  Result verify(GlobalRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
+const StringRef SuperClass);
+
+  /// Initialize target for verification.
+  void setTarget(const Target &T);
+
+  /// Release ownership over exports.
+  std::unique_ptr 

[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: AtariDreams (AtariDreams)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/85541.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+1-3) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..c826663955fecf 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -273,9 +273,7 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   // Objective-C++ ARC:
   //   If we are binding a reference to a temporary that has ownership, we
   //   need to perform retain/release operations on the temporary.
-  //
-  // FIXME: This should be looking at E, not M.
-  if (auto Lifetime = M->getType().getObjCLifetime()) {
+  if (auto Lifetime = E->getType().getObjCLifetime()) {
 switch (Lifetime) {
 case Qualifiers::OCL_None:
 case Qualifiers::OCL_ExplicitNone:

``




https://github.com/llvm/llvm-project/pull/85541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Resolve FIXME: Look at E, not M. (PR #85541)

2024-03-16 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/85541

None

>From cc61f38116b2b9143dbc96d45a35efc065d258f5 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 16 Mar 2024 12:07:21 -0400
Subject: [PATCH] Resolve FIXME: Look at E, not M.

---
 clang/lib/CodeGen/CGExpr.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..c826663955fecf 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -273,9 +273,7 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   // Objective-C++ ARC:
   //   If we are binding a reference to a temporary that has ownership, we
   //   need to perform retain/release operations on the temporary.
-  //
-  // FIXME: This should be looking at E, not M.
-  if (auto Lifetime = M->getType().getObjCLifetime()) {
+  if (auto Lifetime = E->getType().getObjCLifetime()) {
 switch (Lifetime) {
 case Qualifiers::OCL_None:
 case Qualifiers::OCL_ExplicitNone:

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


[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85106

>From 3f0def7f7f56c80af04eecb7b6d11bf3757c8c82 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 12 Mar 2024 20:56:23 -0700
Subject: [PATCH] [InstallAPI] Introduce Basic Verifier

This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will actually check against the dylib's symbol table.
---
 clang/include/clang/AST/Availability.h|   3 +
 clang/include/clang/InstallAPI/Context.h  |   4 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  79 ++-
 clang/include/clang/InstallAPI/Frontend.h |   1 -
 .../clang/InstallAPI/FrontendRecords.h|  49 ++--
 clang/include/clang/InstallAPI/MachO.h|   3 +
 clang/lib/InstallAPI/CMakeLists.txt   |   2 +
 clang/lib/InstallAPI/DylibVerifier.cpp| 212 ++
 clang/lib/InstallAPI/Frontend.cpp |  49 ++--
 clang/lib/InstallAPI/Visitor.cpp  | 101 +
 clang/test/InstallAPI/asm.test|  90 
 .../clang-installapi/ClangInstallAPI.cpp  |  12 +-
 clang/tools/clang-installapi/Options.cpp  |   9 +-
 llvm/include/llvm/TextAPI/Record.h|   7 +-
 14 files changed, 524 insertions(+), 97 deletions(-)
 create mode 100644 clang/lib/InstallAPI/DylibVerifier.cpp
 create mode 100644 clang/test/InstallAPI/asm.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index ae3acbeffe7f18..5cfbaf0cdfbd21 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -75,6 +75,9 @@ struct AvailabilityInfo {
   /// Determine if this AvailabilityInfo represents the default availability.
   bool isDefault() const { return *this == AvailabilityInfo(); }
 
+  /// Check if the symbol has been obsoleted.
+  bool isObsoleted() const { return !Obsoleted.empty(); }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index bdb576d7d85fb6..074ff6f969773c 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -18,6 +18,7 @@
 namespace clang {
 namespace installapi {
 class FrontendRecordsSlice;
+class DylibVerifier;
 
 /// Struct used for generating validating InstallAPI.
 /// The attributes captured represent all necessary information
@@ -45,6 +46,9 @@ struct InstallAPIContext {
   /// DiagnosticsEngine for all error reporting.
   DiagnosticsEngine *Diags = nullptr;
 
+  /// Verifier when binary dylib is passed as input.
+  std::unique_ptr Verifier = nullptr;
+
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
 
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 1a6121b3a258b5..72c4743fdf65e0 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -9,10 +9,12 @@
 #ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 #define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 
-#include "llvm/TextAPI/Target.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/InstallAPI/MachO.h"
 
 namespace clang {
 namespace installapi {
+struct FrontendAttrs;
 
 /// A list of InstallAPI verification modes.
 enum class VerificationMode {
@@ -22,6 +24,81 @@ enum class VerificationMode {
   Pedantic,
 };
 
+/// Service responsible to tracking state of verification across the
+/// lifetime of InstallAPI.
+/// As declarations are collected during AST traversal, they are
+/// compared as symbols against what is available in the binary dylib.
+class DylibVerifier {
+private:
+  struct SymbolContext;
+
+public:
+  enum class Result { NoVerify, Ignore, Valid, Invalid };
+  struct VerifierContext {
+// Current target being verified against the AST.
+llvm::MachO::Target Target;
+
+// Query state of verification after AST has been traversed.
+Result FrontendState;
+
+// First error for AST traversal, which is tied to the target triple.
+bool DiscoveredFirstError;
+  };
+
+  DylibVerifier() = default;
+
+  DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
+VerificationMode Mode, bool Demangle)
+  : Dylib(std::move(Dylib)), Diag(Diag), Mode(Mode), Demangle(Demangle),
+Exports(std::make_unique()) {}
+
+  Result verify(GlobalRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
+const StringRef SuperClass);
+
+  /// Initialize target for verification.
+  void setTarget(const Target &T);
+
+  /// Release ownership over exports.
+  std::unique_ptr getE

[clang] [llvm] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85100
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c51095f - [InstallAPI] Add installapi specific options & diagnostics (#85100)

2024-03-16 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-16T09:08:17-07:00
New Revision: c51095f51b770f0663b65dd8a651601fca15701e

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

LOG: [InstallAPI] Add installapi specific options & diagnostics (#85100)

* A lot of `tapi installapi` options are already shared with clang, but
not all. This patch handles installapi-specific options by filtering for
them in the initial argv input, then passing the rest to the clang
driver.
* Installapi not only generates a text file but also reports to library
developers when there are inconsistencies between an interface and its
implementation. To allow this, add support for reporting installapi
diagnostics. This will be leveraged in the verifier service.

Added: 
clang/include/clang/Basic/DiagnosticInstallAPI.h
clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
clang/include/clang/InstallAPI/DylibVerifier.h
clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
clang/tools/clang-installapi/InstallAPIOpts.td

Modified: 
clang/include/clang/Basic/AllDiagnostics.h
clang/include/clang/Basic/CMakeLists.txt
clang/include/clang/Basic/Diagnostic.td
clang/include/clang/Basic/DiagnosticIDs.h
clang/lib/Basic/DiagnosticIDs.cpp
clang/test/InstallAPI/driver-invalid-options.test
clang/test/InstallAPI/functions.test
clang/tools/clang-installapi/CMakeLists.txt
clang/tools/clang-installapi/ClangInstallAPI.cpp
clang/tools/clang-installapi/Options.cpp
clang/tools/clang-installapi/Options.h
llvm/lib/TextAPI/TextStub.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"

diff  --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)

diff  --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"

diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;

diff  --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /dev/null
+++ b/clang/include/clang/Basic/DiagnosticInstallAPI.h
@@ -0,0 +1,26 @@
+//===--- DiagnosticInstallAPI.h - Diagnostics for InstallAPI-*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// S

[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/85106
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support go-to-definition on type hints. The protocol part (PR #85497)

2024-03-16 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/85497

>From 6d61aa1e43bb522412904bdd77c7f1cfc4b42889 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 16 Mar 2024 12:33:58 +0800
Subject: [PATCH 1/4] [clangd] Support go-to-definition on type hints. The
 protocol part

This is in preparation for implementing go-to-definition support
on type inlay hints, switching the label field within the InlayHint
protocol to an array of InlayHintLabelPart.
---
 clang-tools-extra/clangd/ClangdLSPServer.cpp  |  2 +-
 clang-tools-extra/clangd/InlayHints.cpp   |  8 +++-
 clang-tools-extra/clangd/Protocol.cpp | 40 +-
 clang-tools-extra/clangd/Protocol.h   | 41 ++-
 clang-tools-extra/clangd/test/inlayHints.test |  6 ++-
 clang-tools-extra/clangd/tool/Check.cpp   |  8 +++-
 .../clangd/unittests/InlayHintTests.cpp   |  9 ++--
 7 files changed, 103 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..7fd599d4e1a0b0 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1390,7 +1390,7 @@ void ClangdLSPServer::onClangdInlayHints(const 
InlayHintsParams &Params,
   // Extension doesn't have paddingLeft/Right so adjust the label
   // accordingly.
   {"label",
-   ((Hint.paddingLeft ? " " : "") + llvm::StringRef(Hint.label) +
+   ((Hint.paddingLeft ? " " : "") + llvm::StringRef(Hint.joinLabels()) 
+
 (Hint.paddingRight ? " " : ""))
.str()},
   });
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index a0ebc631ef8285..5a9ec9ab6762fa 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -977,8 +977,12 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   return;
 bool PadLeft = Prefix.consume_front(" ");
 bool PadRight = Suffix.consume_back(" ");
-Results.push_back(InlayHint{LSPPos, (Prefix + Label + Suffix).str(), Kind,
-PadLeft, PadRight, LSPRange});
+Results.push_back(InlayHint{LSPPos,
+/*label=*/{(Prefix + Label + Suffix).str()},
+Kind,
+PadLeft,
+PadRight,
+LSPRange});
   }
 
   // Get the range of the main file that *exactly* corresponds to R.
diff --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index 8aa18bb0058abe..b1e29953337256 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -1483,9 +1483,18 @@ llvm::json::Value toJSON(const InlayHintKind &Kind) {
   llvm_unreachable("Unknown clang.clangd.InlayHintKind");
 }
 
+namespace {
+
+llvm::json::Array toJSON(const std::vector &Labels) {
+  return llvm::json::Array{
+  llvm::map_range(Labels, [](auto &Label) { return toJSON(Label); })};
+}
+
+} // namespace
+
 llvm::json::Value toJSON(const InlayHint &H) {
   llvm::json::Object Result{{"position", H.position},
-{"label", H.label},
+{"label", toJSON(H.label)},
 {"paddingLeft", H.paddingLeft},
 {"paddingRight", H.paddingRight}};
   auto K = toJSON(H.kind);
@@ -1501,6 +1510,10 @@ bool operator<(const InlayHint &A, const InlayHint &B) {
   return std::tie(A.position, A.range, A.kind, A.label) <
  std::tie(B.position, B.range, B.kind, B.label);
 }
+std::string InlayHint::joinLabels() const {
+  return llvm::join(llvm::map_range(label, [](auto &L) { return L.value; }),
+"");
+}
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, InlayHintKind Kind) {
   auto ToString = [](InlayHintKind K) {
@@ -1519,6 +1532,31 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 
InlayHintKind Kind) {
   return OS << ToString(Kind);
 }
 
+llvm::json::Value toJSON(const InlayHintLabelPart &L) {
+  llvm::json::Object Result{{"value", L.value}};
+  if (L.tooltip)
+Result["tooltip"] = *L.tooltip;
+  if (L.location)
+Result["location"] = *L.location;
+  return Result;
+}
+
+bool operator==(const InlayHintLabelPart &LHS, const InlayHintLabelPart &RHS) {
+  return std::tie(LHS.value, LHS.location) == std::tie(RHS.value, 
RHS.location);
+}
+
+bool operator<(const InlayHintLabelPart &LHS, const InlayHintLabelPart &RHS) {
+  return std::tie(LHS.value, LHS.location) < std::tie(RHS.value, RHS.location);
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const InlayHintLabelPart &L) {
+  OS << L.value;
+  if (L.location)
+OS << " (" << L.location << ")";
+  return OS;
+}
+
 static const char *toString(OffsetEncoding OE) {
   switch (OE) {
   case Of

[clang-tools-extra] [clangd] Support go-to-definition on type hints. The protocol part (PR #85497)

2024-03-16 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/85497

>From 6d61aa1e43bb522412904bdd77c7f1cfc4b42889 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 16 Mar 2024 12:33:58 +0800
Subject: [PATCH 1/3] [clangd] Support go-to-definition on type hints. The
 protocol part

This is in preparation for implementing go-to-definition support
on type inlay hints, switching the label field within the InlayHint
protocol to an array of InlayHintLabelPart.
---
 clang-tools-extra/clangd/ClangdLSPServer.cpp  |  2 +-
 clang-tools-extra/clangd/InlayHints.cpp   |  8 +++-
 clang-tools-extra/clangd/Protocol.cpp | 40 +-
 clang-tools-extra/clangd/Protocol.h   | 41 ++-
 clang-tools-extra/clangd/test/inlayHints.test |  6 ++-
 clang-tools-extra/clangd/tool/Check.cpp   |  8 +++-
 .../clangd/unittests/InlayHintTests.cpp   |  9 ++--
 7 files changed, 103 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..7fd599d4e1a0b0 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1390,7 +1390,7 @@ void ClangdLSPServer::onClangdInlayHints(const 
InlayHintsParams &Params,
   // Extension doesn't have paddingLeft/Right so adjust the label
   // accordingly.
   {"label",
-   ((Hint.paddingLeft ? " " : "") + llvm::StringRef(Hint.label) +
+   ((Hint.paddingLeft ? " " : "") + llvm::StringRef(Hint.joinLabels()) 
+
 (Hint.paddingRight ? " " : ""))
.str()},
   });
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index a0ebc631ef8285..5a9ec9ab6762fa 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -977,8 +977,12 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   return;
 bool PadLeft = Prefix.consume_front(" ");
 bool PadRight = Suffix.consume_back(" ");
-Results.push_back(InlayHint{LSPPos, (Prefix + Label + Suffix).str(), Kind,
-PadLeft, PadRight, LSPRange});
+Results.push_back(InlayHint{LSPPos,
+/*label=*/{(Prefix + Label + Suffix).str()},
+Kind,
+PadLeft,
+PadRight,
+LSPRange});
   }
 
   // Get the range of the main file that *exactly* corresponds to R.
diff --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index 8aa18bb0058abe..b1e29953337256 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -1483,9 +1483,18 @@ llvm::json::Value toJSON(const InlayHintKind &Kind) {
   llvm_unreachable("Unknown clang.clangd.InlayHintKind");
 }
 
+namespace {
+
+llvm::json::Array toJSON(const std::vector &Labels) {
+  return llvm::json::Array{
+  llvm::map_range(Labels, [](auto &Label) { return toJSON(Label); })};
+}
+
+} // namespace
+
 llvm::json::Value toJSON(const InlayHint &H) {
   llvm::json::Object Result{{"position", H.position},
-{"label", H.label},
+{"label", toJSON(H.label)},
 {"paddingLeft", H.paddingLeft},
 {"paddingRight", H.paddingRight}};
   auto K = toJSON(H.kind);
@@ -1501,6 +1510,10 @@ bool operator<(const InlayHint &A, const InlayHint &B) {
   return std::tie(A.position, A.range, A.kind, A.label) <
  std::tie(B.position, B.range, B.kind, B.label);
 }
+std::string InlayHint::joinLabels() const {
+  return llvm::join(llvm::map_range(label, [](auto &L) { return L.value; }),
+"");
+}
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, InlayHintKind Kind) {
   auto ToString = [](InlayHintKind K) {
@@ -1519,6 +1532,31 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 
InlayHintKind Kind) {
   return OS << ToString(Kind);
 }
 
+llvm::json::Value toJSON(const InlayHintLabelPart &L) {
+  llvm::json::Object Result{{"value", L.value}};
+  if (L.tooltip)
+Result["tooltip"] = *L.tooltip;
+  if (L.location)
+Result["location"] = *L.location;
+  return Result;
+}
+
+bool operator==(const InlayHintLabelPart &LHS, const InlayHintLabelPart &RHS) {
+  return std::tie(LHS.value, LHS.location) == std::tie(RHS.value, 
RHS.location);
+}
+
+bool operator<(const InlayHintLabelPart &LHS, const InlayHintLabelPart &RHS) {
+  return std::tie(LHS.value, LHS.location) < std::tie(RHS.value, RHS.location);
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const InlayHintLabelPart &L) {
+  OS << L.value;
+  if (L.location)
+OS << " (" << L.location << ")";
+  return OS;
+}
+
 static const char *toString(OffsetEncoding OE) {
   switch (OE) {
   case Of

[clang] [clang] Correct Microsoft mangling of lifetime extended temporary objects. (PR #85529)

2024-03-16 Thread Tom Honermann via cfe-commits


@@ -54,6 +54,12 @@ ABI Changes in This Version
   inline member function that contains a static local variable with a dynamic
   initializer is declared with ``__declspec(dllimport)``. (#GH83616).
 
+- Fixed Microsoft name mangling of lifetime extended temporary objects. This
+  change corrects missing back reference registrations that could result in
+  incorrect back reference indexes and suprising demangled name results. Since
+  MSVC uses a different mangling for these objects, compatibility is not 
affected.
+  (#GH85423).

tahonermann wrote:

Commit 
https://github.com/llvm/llvm-project/commit/e77de75d7e009daaadb03e9b1091c3a9a9c9d311
 claims that Microsoft doesn't have a mangling for these objects and that the 
`$RT` mangling is a Clang invention. The claim that MSVC doesn't implement a 
mangling for these doesn't seem right though. Consider 
https://godbolt.org/z/n715zPbc6. It appears that MSVC (back to at least v19.14) 
uses a `$S` mangling for these; like that used for other unnamed 
objects like for structured bindings, anonymous unions, and (non-thread-safe) 
guards for static local variables. Further, I think 
https://godbolt.org/z/x1Kh57818 demonstrates a Clang/MSVC compatibility issue. 
The code Clang emits for `h()` for the inlining of `g()` attempts to import 
`__imp_?$RT1@singleton@?1??g@@YAHXZ@4ABUS@@B` while MSVC's code attempts to 
import `__imp_?$S1@?1??g@@YAHXZ@4US@@B`.

Assuming agreement with the analysis above, I'll file a new issue for the 
divergent mangling.

https://github.com/llvm/llvm-project/pull/85529
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Fixes #85519.

---
Full diff: https://github.com/llvm/llvm-project/pull/85534.diff


2 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+3) 
- (modified) clang/test/SemaCXX/cxx23-assume.cpp (+10) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7137efb7876de2..fa9e8ecf654378 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5594,6 +5594,9 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
 if (Assumption->isValueDependent())
   return ESR_Failed;
 
+if (Assumption->HasSideEffects(Info.getCtx()))
+  continue;
+
 bool Value;
 if (!EvaluateAsBooleanCondition(Assumption, Value, Info))
   return ESR_Failed;
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2d7c9b174d9019..478da092471aff 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -126,3 +126,13 @@ static_assert(f5() == 1); // expected-note 3 {{while 
checking constraint sati
 static_assert(f5() == 2);
 static_assert(f5() == 1); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
 static_assert(f5() == 2); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
+
+// Do not validate assumptions whose evaluation would have side-effects.
+constexpr int foo() {
+  int a = 0;
+  [[assume(a++)]] [[assume(++a)]]; // expected-warning 2 {{has side effects 
that will be discarded}} ext-warning 2 {{C++23 extension}}
+  [[assume((a+=1))]]; // expected-warning {{has side effects that will be 
discarded}} ext-warning {{C++23 extension}}
+  return a;
+}
+
+static_assert(foo() == 0);

``




https://github.com/llvm/llvm-project/pull/85534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-16 Thread via cfe-commits

https://github.com/Sirraide closed 
https://github.com/llvm/llvm-project/pull/85534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 74d1a40 - [Clang] Ignore assumptions with side effects at compile time (#85534)

2024-03-16 Thread via cfe-commits

Author: Sirraide
Date: 2024-03-16T16:05:50+01:00
New Revision: 74d1a40915834cbf0629f8d34a7265734d4d9073

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

LOG: [Clang] Ignore assumptions with side effects at compile time (#85534)

Fixes #85519.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/cxx23-assume.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7137efb7876de2..fa9e8ecf654378 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5594,6 +5594,9 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
 if (Assumption->isValueDependent())
   return ESR_Failed;
 
+if (Assumption->HasSideEffects(Info.getCtx()))
+  continue;
+
 bool Value;
 if (!EvaluateAsBooleanCondition(Assumption, Value, Info))
   return ESR_Failed;

diff  --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2d7c9b174d9019..478da092471aff 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -126,3 +126,13 @@ static_assert(f5() == 1); // expected-note 3 {{while 
checking constraint sati
 static_assert(f5() == 2);
 static_assert(f5() == 1); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
 static_assert(f5() == 2); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
+
+// Do not validate assumptions whose evaluation would have side-effects.
+constexpr int foo() {
+  int a = 0;
+  [[assume(a++)]] [[assume(++a)]]; // expected-warning 2 {{has side effects 
that will be discarded}} ext-warning 2 {{C++23 extension}}
+  [[assume((a+=1))]]; // expected-warning {{has side effects that will be 
discarded}} ext-warning {{C++23 extension}}
+  return a;
+}
+
+static_assert(foo() == 0);



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


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-16 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/85534

Fixes #85519.

>From 37b7999752cb6bbcf0911b9d6b87f04395a82dcc Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 16 Mar 2024 16:01:43 +0100
Subject: [PATCH] [Clang] Do not check assumptions with side effects at compile
 time

---
 clang/lib/AST/ExprConstant.cpp  |  3 +++
 clang/test/SemaCXX/cxx23-assume.cpp | 10 ++
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7137efb7876de2..fa9e8ecf654378 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5594,6 +5594,9 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
 if (Assumption->isValueDependent())
   return ESR_Failed;
 
+if (Assumption->HasSideEffects(Info.getCtx()))
+  continue;
+
 bool Value;
 if (!EvaluateAsBooleanCondition(Assumption, Value, Info))
   return ESR_Failed;
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 2d7c9b174d9019..478da092471aff 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -126,3 +126,13 @@ static_assert(f5() == 1); // expected-note 3 {{while 
checking constraint sati
 static_assert(f5() == 2);
 static_assert(f5() == 1); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
 static_assert(f5() == 2); // expected-note {{while checking constraint 
satisfaction}} expected-note {{in instantiation of}}
+
+// Do not validate assumptions whose evaluation would have side-effects.
+constexpr int foo() {
+  int a = 0;
+  [[assume(a++)]] [[assume(++a)]]; // expected-warning 2 {{has side effects 
that will be discarded}} ext-warning 2 {{C++23 extension}}
+  [[assume((a+=1))]]; // expected-warning {{has side effects that will be 
discarded}} ext-warning {{C++23 extension}}
+  return a;
+}
+
+static_assert(foo() == 0);

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


[clang] [clang] Correct Microsoft mangling of lifetime extended temporary objects. (PR #85529)

2024-03-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tom Honermann (tahonermann)


Changes

Lifetime extended temporary objects that are bound to references with static 
storage duration may have external linkage and therefore require mangled symbol 
names.  Clang uses an extension of the Microsoft ABI to give these symbols an 
implicit name of '$RT' followed by a discriminator and then mangles them 
similarly to the variable they are bound to.  Clang's mangling scheme differs 
from the one used by MSVC.

Previously, the `$RT` portion of the name was not 
registered as a back reference candidate and this resulted in incorrect back 
references for enclosing class and/or namespace scopes that might be referenced 
in the type of the object.

This is an ABI change and has the potential to cause backward compatibility 
issues with previous Clang releases.  Since MSVC uses a different mangling 
scheme, this change does not affect compatibility with MSVC.

This fixes one of the name mangling concerns reported in #85423.

---
Full diff: https://github.com/llvm/llvm-project/pull/85529.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+2-1) 
- (modified) clang/test/CodeGenCXX/mangle-ms-back-references.cpp (+13) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1ae35e6881d2f8..f0da6ca497b575 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -54,6 +54,12 @@ ABI Changes in This Version
   inline member function that contains a static local variable with a dynamic
   initializer is declared with ``__declspec(dllimport)``. (#GH83616).
 
+- Fixed Microsoft name mangling of lifetime extended temporary objects. This
+  change corrects missing back reference registrations that could result in
+  incorrect back reference indexes and suprising demangled name results. Since
+  MSVC uses a different mangling for these objects, compatibility is not 
affected.
+  (#GH85423).
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index aa26bb7ed46f48..cf9c2093a8f6a1 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3911,7 +3911,8 @@ void MicrosoftMangleContextImpl::mangleReferenceTemporary(
   msvc_hashing_ostream MHO(Out);
   MicrosoftCXXNameMangler Mangler(*this, MHO);
 
-  Mangler.getStream() << "?$RT" << ManglingNumber << '@';
+  Mangler.getStream() << "?";
+  Mangler.mangleSourceName("$RT" + llvm::utostr(ManglingNumber));
   Mangler.mangle(VD, "");
 }
 
diff --git a/clang/test/CodeGenCXX/mangle-ms-back-references.cpp 
b/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
index b27a9c5acacb77..8707bff9534070 100644
--- a/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
@@ -1,5 +1,18 @@
 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - 
-triple=i386-pc-win32 | FileCheck %s
 
+namespace NS {
+// The name "RT1" for the name of the class below has been specifically
+// chosen to ensure that back reference lookup does not match against the
+// implicitly generated "$RT1" name of the reference temporary symbol.
+struct RT1 {
+  static const RT1& singleton;
+  int i;
+};
+const RT1& RT1::singleton = RT1{1};
+}
+// CHECK: "?$RT1@singleton@RT1@NS@@2ABU23@B"
+// CHECK: "?singleton@RT1@NS@@2ABU12@B"
+
 void f1(const char* a, const char* b) {}
 // CHECK: "?f1@@YAXPBD0@Z"
 

``




https://github.com/llvm/llvm-project/pull/85529
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Correct Microsoft mangling of lifetime extended temporary objects. (PR #85529)

2024-03-16 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann created 
https://github.com/llvm/llvm-project/pull/85529

Lifetime extended temporary objects that are bound to references with static 
storage duration may have external linkage and therefore require mangled symbol 
names.  Clang uses an extension of the Microsoft ABI to give these symbols an 
implicit name of '$RT' followed by a discriminator and then mangles them 
similarly to the variable they are bound to.  Clang's mangling scheme differs 
from the one used by MSVC.

Previously, the `$RT` portion of the name was not registered as 
a back reference candidate and this resulted in incorrect back references for 
enclosing class and/or namespace scopes that might be referenced in the type of 
the object.

This is an ABI change and has the potential to cause backward compatibility 
issues with previous Clang releases.  Since MSVC uses a different mangling 
scheme, this change does not affect compatibility with MSVC.

This fixes one of the name mangling concerns reported in #85423.

>From 4c0149e934aae9d061e22400eb3eace47e4906be Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Sat, 16 Mar 2024 07:09:58 -0700
Subject: [PATCH] [clang] Correct Microsoft mangling of lifetime extended
 temporary objects.

Lifetime extended temporary objects that are bound to references with static
storage duration may have external linkage and therefore require mangled symbol
names.  Clang uses an extension of the Microsoft ABI to give these symbols an
implicit name of '$RT' followed by a discriminator and then mangles them
similarly to the variable they are bound to.  Clang's mangling scheme differs
from the one used by MSVC.

Previously, the '$RT' portion of the name was not registered as
a back reference candidate and this resulted in incorrect back references for
enclosing class and/or namespace scopes that might be referenced in the
type of the object.

This is an ABI change and has the potential to cause backward compatibility
issues with previous Clang releases.  Since MSVC uses a different mangling
scheme, this change does not affect compatibility with MSVC.
---
 clang/docs/ReleaseNotes.rst |  6 ++
 clang/lib/AST/MicrosoftMangle.cpp   |  3 ++-
 clang/test/CodeGenCXX/mangle-ms-back-references.cpp | 13 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1ae35e6881d2f8..f0da6ca497b575 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -54,6 +54,12 @@ ABI Changes in This Version
   inline member function that contains a static local variable with a dynamic
   initializer is declared with ``__declspec(dllimport)``. (#GH83616).
 
+- Fixed Microsoft name mangling of lifetime extended temporary objects. This
+  change corrects missing back reference registrations that could result in
+  incorrect back reference indexes and suprising demangled name results. Since
+  MSVC uses a different mangling for these objects, compatibility is not 
affected.
+  (#GH85423).
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index aa26bb7ed46f48..cf9c2093a8f6a1 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3911,7 +3911,8 @@ void MicrosoftMangleContextImpl::mangleReferenceTemporary(
   msvc_hashing_ostream MHO(Out);
   MicrosoftCXXNameMangler Mangler(*this, MHO);
 
-  Mangler.getStream() << "?$RT" << ManglingNumber << '@';
+  Mangler.getStream() << "?";
+  Mangler.mangleSourceName("$RT" + llvm::utostr(ManglingNumber));
   Mangler.mangle(VD, "");
 }
 
diff --git a/clang/test/CodeGenCXX/mangle-ms-back-references.cpp 
b/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
index b27a9c5acacb77..8707bff9534070 100644
--- a/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-back-references.cpp
@@ -1,5 +1,18 @@
 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - 
-triple=i386-pc-win32 | FileCheck %s
 
+namespace NS {
+// The name "RT1" for the name of the class below has been specifically
+// chosen to ensure that back reference lookup does not match against the
+// implicitly generated "$RT1" name of the reference temporary symbol.
+struct RT1 {
+  static const RT1& singleton;
+  int i;
+};
+const RT1& RT1::singleton = RT1{1};
+}
+// CHECK: "?$RT1@singleton@RT1@NS@@2ABU23@B"
+// CHECK: "?singleton@RT1@NS@@2ABU12@B"
+
 void f1(const char* a, const char* b) {}
 // CHECK: "?f1@@YAXPBD0@Z"
 

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


[clang] Reland Print library module manifest path again (PR #84881)

2024-03-16 Thread Mark de Wever via cfe-commits

https://github.com/mordante approved this pull request.

Thanks for picking it up @ChuanqiXu9 and thanks for testing @kaz7.

https://github.com/llvm/llvm-project/pull/84881
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8e69052 - [clang][Interp] Handle ArrayTypeTraitExprs

2024-03-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-16T12:46:28+01:00
New Revision: 8e69052b0e2f3b1bc7dbcf56a0c771e30d2edbf7

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

LOG: [clang][Interp] Handle ArrayTypeTraitExprs

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f07e430e279d22..2e48ec2c508775 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1755,6 +1755,14 @@ bool ByteCodeExprGen::VisitTypeTraitExpr(const 
TypeTraitExpr *E) {
   return this->emitConst(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitArrayTypeTraitExpr(
+const ArrayTypeTraitExpr *E) {
+  if (DiscardResult)
+return true;
+  return this->emitConst(E->getValue(), E);
+}
+
 template 
 bool ByteCodeExprGen::VisitLambdaExpr(const LambdaExpr *E) {
   if (DiscardResult)

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 969598c9780513..db0d73ce23f7c4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
+  bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 0a9580b6f664b0..277438d2e63114 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -910,6 +910,18 @@ namespace TypeTraits {
   struct U {};
   static_assert(S3{}.foo(), "");
   static_assert(!S3{}.foo(), "");
+
+  typedef int Int;
+  typedef Int IntAr[10];
+  typedef const IntAr ConstIntAr;
+  typedef ConstIntAr ConstIntArAr[4];
+
+  static_assert(__array_rank(IntAr) == 1, "");
+  static_assert(__array_rank(ConstIntArAr) == 2, "");
+
+  static_assert(__array_extent(IntAr, 0) == 10, "");
+  static_assert(__array_extent(ConstIntArAr, 0) == 4, "");
+  static_assert(__array_extent(ConstIntArAr, 1) == 10, "");
 }
 
 #if __cplusplus >= 201402L



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


[clang] 367f355 - Reapply "[clang] Fix crash when declaring invalid lambda member" (#85427)

2024-03-16 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2024-03-16T12:36:33+01:00
New Revision: 367f355fbfe30b1769368c93f30e04b2ecba613e

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

LOG: Reapply "[clang] Fix crash when declaring invalid lambda member" (#85427)

This re-applies #74110 with the crashing code disabled in C++11. I'll
try to fix the new crash in it's own patch.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclCXX.cpp
clang/test/SemaCXX/lambda-expressions.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 93cc5291e2391f..ba9de1ac98de08 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,9 @@ Bug Fixes in This Version
   by the C standard. This significantly improves codegen of `*` and `/` 
especially.
   Fixes (`#31205 `_).
 
+- Fixes an assertion failure on invalid code when trying to define member
+  functions in lambdas.
+
 Bug Fixes to Compiler Builtins
 ^^
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..645ec2f7563bca 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,10 +1567,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });
 }
 #endif
 

diff  --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 0516a5da31ae9a..389002ab0e349b 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -558,8 +559,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; };
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
+  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
 };
 
 B b;
@@ -589,6 +590,7 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
+  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto &v) -> void { v.n = 0; };
+  auto y = [](auto &v) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -624,22 +626,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const;
+friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const;
+  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const;
+  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK: lambda's call operator is a friend.
-  void use(X &x) { y(x); }
+  // Should be OK in C++14 and later: lambda's call operator is a friend.
+  void use(X &x) { y(x); } // cxx11-error {{no matching function for call to 
object}}
 
   // This used to crash in return type deduction for the conversion opreator.
 

[clang] Reapply "[clang] Fix crash when declaring invalid lambda member" (PR #85427)

2024-03-16 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 closed 
https://github.com/llvm/llvm-project/pull/85427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-16 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 updated 
https://github.com/llvm/llvm-project/pull/85515

>From 1d37cd1a7dac2ddb05fdcf125483991b3ac645d8 Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Sat, 16 Mar 2024 18:25:12 +0800
Subject: [PATCH 1/2] allow egraph rewriter not to open html directly

---
 .../utils/analyzer/exploded-graph-rewriter.py | 20 ---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
+dump_html_only):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
 self._topo_mode = topo_mode
 self._dump_dot_only = dump_dot_only
+self._dump_html_only = dump_html_only
 self._output = []
 
 def _dump_raw(self, s):
@@ -998,6 +1000,8 @@ def write_temp_file(suffix, prefix, data):
 '%s'
 % ("#1a1a1a" if self._dark_mode else "white", svg),
 )
+if self._dump_html_only:
+return
 if sys.platform == "win32":
 os.startfile(filename)
 elif sys.platform == "darwin":
@@ -1176,7 +1180,8 @@ def main():
 default=False,
 help="black-and-white mode",
 )
-parser.add_argument(
+dump_conflict = parser.add_mutually_exclusive_group()
+dump_conflict.add_argument(
 "--dump-dot-only",
 action="store_const",
 dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
 "displaying it, dump the rewritten dot file "
 "to stdout",
 )
+dump_conflict.add_argument(
+"--dump-html-only",
+action="store_const",
+dest="dump_html_only",
+const=True,
+default=False,
+help="do not open the generated HTML immediately",
+)
 args = parser.parse_args()
 logging.basicConfig(level=args.loglevel)
 
@@ -1206,7 +1219,8 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
+args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
+args.dump_html_only
 )
 
 for trimmer in trimmers:

>From 3e44fb5936e37f234d601e4070c9da445a2e53ba Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Sat, 16 Mar 2024 19:15:11 +0800
Subject: [PATCH 2/2] fix format issues

---
 clang/utils/analyzer/exploded-graph-rewriter.py | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index ffec964d8ef09a..1dc8a5337da598 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,8 +479,9 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
-dump_html_only):
+def __init__(
+self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, 
dump_html_only
+):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
@@ -1219,8 +1220,12 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
-args.dump_html_only
+args.diff,
+args.dark,
+args.gray,
+args.topology,
+args.dump_dot_only,
+args.dump_html_only,
 )
 
 for trimmer in trimmers:

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


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
8f68022f8e6e54d1aeae4ed301f5a015963089b7...1d37cd1a7dac2ddb05fdcf125483991b3ac645d8
 clang/utils/analyzer/exploded-graph-rewriter.py
``





View the diff from darker here.


``diff
--- exploded-graph-rewriter.py  2024-03-16 10:25:12.00 +
+++ exploded-graph-rewriter.py  2024-03-16 11:10:55.694720 +
@@ -477,12 +477,13 @@
 
 
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
-dump_html_only):
+def __init__(
+self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, 
dump_html_only
+):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
 self._topo_mode = topo_mode
 self._dump_dot_only = dump_dot_only
@@ -1217,12 +1218,16 @@
 trimmers.append(SinglePathTrimmer())
 
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
-args.dump_html_only
+args.diff,
+args.dark,
+args.gray,
+args.topology,
+args.dump_dot_only,
+args.dump_html_only,
 )
 
 for trimmer in trimmers:
 trimmer.trim(graph)
 

``




https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ella Ma (Snape3058)


Changes

When developing on a headless device through SSH, we do not have a browser or 
even an X environment. Hence, it would be more convenient if the rewriter could 
stop before attempting to open the generated HTML file. Then, it can be opened 
remotely through an HTML server.

This patch adds a new option `--dump-html-only` with a shortcut `-x` to make 
the rewriter stop before opening the generated HTML in a browser. The new 
option is marked in conflict with the existing `--dump-dot-only` option to 
prevent unexpected behaviors.

---
Full diff: https://github.com/llvm/llvm-project/pull/85515.diff


1 Files Affected:

- (modified) clang/utils/analyzer/exploded-graph-rewriter.py (+17-3) 


``diff
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
+dump_html_only):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
 self._topo_mode = topo_mode
 self._dump_dot_only = dump_dot_only
+self._dump_html_only = dump_html_only
 self._output = []
 
 def _dump_raw(self, s):
@@ -998,6 +1000,8 @@ def write_temp_file(suffix, prefix, data):
 '%s'
 % ("#1a1a1a" if self._dark_mode else "white", svg),
 )
+if self._dump_html_only:
+return
 if sys.platform == "win32":
 os.startfile(filename)
 elif sys.platform == "darwin":
@@ -1176,7 +1180,8 @@ def main():
 default=False,
 help="black-and-white mode",
 )
-parser.add_argument(
+dump_conflict = parser.add_mutually_exclusive_group()
+dump_conflict.add_argument(
 "--dump-dot-only",
 action="store_const",
 dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
 "displaying it, dump the rewritten dot file "
 "to stdout",
 )
+dump_conflict.add_argument(
+"--dump-html-only",
+action="store_const",
+dest="dump_html_only",
+const=True,
+default=False,
+help="do not open the generated HTML immediately",
+)
 args = parser.parse_args()
 logging.basicConfig(level=args.loglevel)
 
@@ -1206,7 +1219,8 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
+args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
+args.dump_html_only
 )
 
 for trimmer in trimmers:

``




https://github.com/llvm/llvm-project/pull/85515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

2024-03-16 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 created 
https://github.com/llvm/llvm-project/pull/85515

When developing on a headless device through SSH, we do not have a browser or 
even an X environment. Hence, it would be more convenient if the rewriter could 
stop before attempting to open the generated HTML file. Then, it can be opened 
remotely through an HTML server.

This patch adds a new option `--dump-html-only` with a shortcut `-x` to make 
the rewriter stop before opening the generated HTML in a browser. The new 
option is marked in conflict with the existing `--dump-dot-only` option to 
prevent unexpected behaviors.

>From 1d37cd1a7dac2ddb05fdcf125483991b3ac645d8 Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Sat, 16 Mar 2024 18:25:12 +0800
Subject: [PATCH] allow egraph rewriter not to open html directly

---
 .../utils/analyzer/exploded-graph-rewriter.py | 20 ---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py 
b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only):
+def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, 
dump_dot_only,
+dump_html_only):
 self._do_diffs = do_diffs
 self._dark_mode = dark_mode
 self._gray_mode = gray_mode
 self._topo_mode = topo_mode
 self._dump_dot_only = dump_dot_only
+self._dump_html_only = dump_html_only
 self._output = []
 
 def _dump_raw(self, s):
@@ -998,6 +1000,8 @@ def write_temp_file(suffix, prefix, data):
 '%s'
 % ("#1a1a1a" if self._dark_mode else "white", svg),
 )
+if self._dump_html_only:
+return
 if sys.platform == "win32":
 os.startfile(filename)
 elif sys.platform == "darwin":
@@ -1176,7 +1180,8 @@ def main():
 default=False,
 help="black-and-white mode",
 )
-parser.add_argument(
+dump_conflict = parser.add_mutually_exclusive_group()
+dump_conflict.add_argument(
 "--dump-dot-only",
 action="store_const",
 dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
 "displaying it, dump the rewritten dot file "
 "to stdout",
 )
+dump_conflict.add_argument(
+"--dump-html-only",
+action="store_const",
+dest="dump_html_only",
+const=True,
+default=False,
+help="do not open the generated HTML immediately",
+)
 args = parser.parse_args()
 logging.basicConfig(level=args.loglevel)
 
@@ -1206,7 +1219,8 @@ def main():
 explorer = BasicExplorer()
 
 visitor = DotDumpVisitor(
-args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
+args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
+args.dump_html_only
 )
 
 for trimmer in trimmers:

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


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

currently the macro definition for both `&` and `bitand` is not giving any 
warning however should the `&` one warn? or current working is correct 
behaviour as expected?

https://github.com/llvm/llvm-project/pull/81976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-16 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Shouldn't we simply `return`?

As you say, the assert is disabled in Release mode. Even if it's enabled, the 
author if `getSubExpr` may one day decide to remove the assert without possibly 
knowing all the places that do rely on that assert, leaving the code 
unprotected. It seems like it's trivial solution to `return` and be on the safe 
side.

https://github.com/llvm/llvm-project/pull/85473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits


@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() & (i > 4);
   b = (i == 7) & foo();
 #ifdef __cplusplus
-  b = foo() bitand bar(); // expected-warning {{use of bitwise '&' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitand bar(); // Ok, no warning expected
+  

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/81976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits


@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);
+
+  if (SR.str() == "&" || SR.str() == "|") {
+
+S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/81976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits


@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/81976
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-03-16 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/81976

>From 07c73f087a430f5115ecdfec23730c5afcab37f3 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 16 Feb 2024 14:26:36 +0530
Subject: [PATCH 1/2] fix unnecessary warning when using bitand with boolean

Signed-off-by: 11happy 
---
 clang/lib/Sema/SemaChecking.cpp | 24 ++--
 clang/test/Sema/warn-bitwise-and-bool.c |  4 ++--
 clang/test/Sema/warn-bitwise-or-bool.c  |  4 ++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..e43892cbf35890 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);
+
+  if (SR.str() == "&" || SR.str() == "|") {
+
+S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+<< (BO->getOpcode() == BO_And ? "&" : "|")
+<< OrigE->getSourceRange()
+<< FixItHint::CreateReplacement(
+   BO->getOperatorLoc(),
+   (BO->getOpcode() == BO_And ? "&&" : "||"));
+S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  }
 }
 
   // For conditional operators, we analyze the arguments as if they
diff --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
index 6bec1be1abdef6..23e7afcc59f8aa 100644
--- a/clang/test/Sema/warn-bitwise-and-bool.c
+++ b/clang/test/Sema/warn-bitwise-and-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() & (i > 4);
   b = (i == 7) & foo();
 #ifdef __cplusplus
-  b = foo() bitand bar(); // expected-warning {{use of bitwise '&' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitand bar(); // Ok, no warning expected
+  
 #endif
 
   if (foo() & bar())  // expected-warning {{use of bitwise '&' with 
boolean operands}}
diff --git a/clang/test/Sema/warn-bitwise-or-bool.c 
b/clang/test/Sema/warn-bitwise-or-bool.c
index ae86790901aac5..e84f59cf8f766a 100644
--- a/clang/test/Sema/warn-bitwise-or-bool.c
+++ b/clang/test/Sema/warn-bitwise-or-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() | (i > 4);
   b = (i == 7) | foo();
 #ifdef __cplusplus
-  b = foo() bitor bar();  // expected-warning {{use of bitwise '|' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitor bar();  //Ok, no warning expected
+  
 #endif
 
   if (foo() | bar())  // expected-warning {{use of bitwise '|' with 
boolean operands}}

>From a0ba9e05bb9d0443f386fd57eef3b4e6e2bd1217 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Sat, 16 Mar 2024 16:11:00 +0530
Subject: [PATCH 2/2] add release notes and add tests

Signed-off-by: 11happy 
---
 clang/docs/ReleaseNotes.rst |  5 +
 clang/lib/Sema/SemaChecking.cpp | 16 +---
 clang/test/Sema/warn-bitwise-and-bool.c |  6 ++
 clang/test/Sema/warn-bitwise-or-bool.c  |  4 
 4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 254e0a9cb72979..177f424abaa73c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@ Improvements to Clang's diagnostics
 - Clang now applies syntax highlighting to the code snippets it
   prints.
 
+- Clang now does not warn in cases where bitand operator is 
+  intentionally used with boolean operands, distinguishing it
+  from potential typographical errors or unintended bitwise operations.
+  Fixes (`#77601 `)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/Sema

[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-16 Thread Giuseppe D'Angelo via cfe-commits


@@ -857,8 +881,13 @@ void CXXRecordDecl::addedMember(Decl *D) {
 data().HasDeclaredCopyAssignmentWithConstParam = true;
 }
 
-if (Method->isMoveAssignmentOperator())
+if (Method->isMoveAssignmentOperator()) {
   SMKind |= SMF_MoveAssignment;
+}
+
+if (Method->isUserProvided() &&
+(Method->isCopyAssignment() || Method->isMoveAssignment()))
+  data().IsNaturallyTriviallyRelocatable = false;

dangelog wrote:

I've also been asked to comment. My personal opinion is that relocability is 
strictly tied to the Rule Of Five. The moment a user decides to opt into the 
RO5 by e.g. writing a custom assignment operator, they should lose trivial 
relocability, unless they do something extra to gain it back (different 
proposals disagree on the syntax but ultimately they achieve the same). (We may 
then argue regarding all the subtleties about user-declared vs. user-defaulted 
vs. user-defined, but I don't really have a strong opinion about that.)

https://github.com/llvm/llvm-project/pull/84621
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

First this null-ptr check does nothing because in line 114 we still missing 
nullptr check.
Proper way would be to "return" when we find nullptr were it shoudnt.

Second thing, asserts mean nothing. In release mode they are disabled. This 
mean that if we get nullptr, then we going to crash.

Change is fine for me, but not because there is assert but because in line 114 
dereference will happened anyway.

https://github.com/llvm/llvm-project/pull/85473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5ac784d - Revert "[clang-format][NFC] Don't use clang-format style in config files"

2024-03-16 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-03-16T02:39:37-07:00
New Revision: 5ac784d1d00ce4733d07c3432ff946497a249e51

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

LOG: Revert "[clang-format][NFC] Don't use clang-format style in config files"

This reverts commit c69ec700adec315b3daa55742f2ef655242fa297, which has been
obsolete since commit dec63221d56e because the clang-format style was added
in version 18.

Added: 


Modified: 
clang/include/clang/Format/.clang-format
clang/lib/Format/.clang-format
clang/tools/clang-format/.clang-format
clang/unittests/Format/.clang-format

Removed: 




diff  --git a/clang/include/clang/Format/.clang-format 
b/clang/include/clang/Format/.clang-format
index f95602cab0f7fc..d7331b3c8cf02e 100644
--- a/clang/include/clang/Format/.clang-format
+++ b/clang/include/clang/Format/.clang-format
@@ -1,6 +1 @@
-BasedOnStyle: LLVM
-InsertBraces: true
-InsertNewlineAtEOF: true
-LineEnding: LF
-RemoveBracesLLVM: true
-RemoveParentheses: ReturnStatement
+BasedOnStyle: clang-format

diff  --git a/clang/lib/Format/.clang-format b/clang/lib/Format/.clang-format
index f95602cab0f7fc..d7331b3c8cf02e 100644
--- a/clang/lib/Format/.clang-format
+++ b/clang/lib/Format/.clang-format
@@ -1,6 +1 @@
-BasedOnStyle: LLVM
-InsertBraces: true
-InsertNewlineAtEOF: true
-LineEnding: LF
-RemoveBracesLLVM: true
-RemoveParentheses: ReturnStatement
+BasedOnStyle: clang-format

diff  --git a/clang/tools/clang-format/.clang-format 
b/clang/tools/clang-format/.clang-format
index f95602cab0f7fc..d7331b3c8cf02e 100644
--- a/clang/tools/clang-format/.clang-format
+++ b/clang/tools/clang-format/.clang-format
@@ -1,6 +1 @@
-BasedOnStyle: LLVM
-InsertBraces: true
-InsertNewlineAtEOF: true
-LineEnding: LF
-RemoveBracesLLVM: true
-RemoveParentheses: ReturnStatement
+BasedOnStyle: clang-format

diff  --git a/clang/unittests/Format/.clang-format 
b/clang/unittests/Format/.clang-format
index f95602cab0f7fc..d7331b3c8cf02e 100644
--- a/clang/unittests/Format/.clang-format
+++ b/clang/unittests/Format/.clang-format
@@ -1,6 +1 @@
-BasedOnStyle: LLVM
-InsertBraces: true
-InsertNewlineAtEOF: true
-LineEnding: LF
-RemoveBracesLLVM: true
-RemoveParentheses: ReturnStatement
+BasedOnStyle: clang-format



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


[clang] [clang-format] Fix a bug in SpaceInEmptyBlock option (PR #85508)

2024-03-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #84695.

---
Full diff: https://github.com/llvm/llvm-project/pull/85508.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+4) 
- (modified) clang/unittests/Format/FormatTest.cpp (+4) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1342d37a147915..5a715ac8a5f23f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4271,6 +4271,10 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 return Left.is(tok::hash);
   if (Left.isOneOf(tok::hashhash, tok::hash))
 return Right.is(tok::hash);
+  if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
+  Right.MatchingParen == &Left && Line.Children.empty()) {
+return Style.SpaceInEmptyBlock;
+  }
   if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
   (Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index fc367a7a5a8981..4a72c043862b90 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6938,6 +6938,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
"else if (b) { }\n"
"else { }",
Style);
+
+  Style = getLLVMStyle(FormatStyle::LK_CSharp);
+  Style.SpaceInEmptyBlock = true;
+  verifyFormat("Event += () => { };", Style);
 }
 
 TEST_F(FormatTest, FormatBeginBlockEndMacros) {

``




https://github.com/llvm/llvm-project/pull/85508
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in SpaceInEmptyBlock option (PR #85508)

2024-03-16 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/85508

Fixes #84695.

>From d15f3ddd2f9aef02f1706e7af64e76359a89 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 16 Mar 2024 02:18:33 -0700
Subject: [PATCH] [clang-format] Fix a bug in SpaceInEmptyBlock option

Fixes #84695.
---
 clang/lib/Format/TokenAnnotator.cpp   | 4 
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1342d37a147915..5a715ac8a5f23f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4271,6 +4271,10 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 return Left.is(tok::hash);
   if (Left.isOneOf(tok::hashhash, tok::hash))
 return Right.is(tok::hash);
+  if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
+  Right.MatchingParen == &Left && Line.Children.empty()) {
+return Style.SpaceInEmptyBlock;
+  }
   if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
   (Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index fc367a7a5a8981..4a72c043862b90 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6938,6 +6938,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
"else if (b) { }\n"
"else { }",
Style);
+
+  Style = getLLVMStyle(FormatStyle::LK_CSharp);
+  Style.SpaceInEmptyBlock = true;
+  verifyFormat("Event += () => { };", Style);
 }
 
 TEST_F(FormatTest, FormatBeginBlockEndMacros) {

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


[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-03-16 Thread Nikita Popov via cfe-commits

nikic wrote:

> > Shouldn't plain `-fsanitize=undefined` disable this sanitizer by default 
> > (requiring explicit opt-in)? In `-fwrapv` mode this is not undefined 
> > behavior, so `-fsanitize=undefined` should not complain about it.
> 
> I was on the fence whether `-fsanitize=undefined` should expand to 
> signed-integer-overflow: [#80089 
> (comment)](https://github.com/llvm/llvm-project/pull/80089#issuecomment-1945202620)
> 
> Perhaps you have run into some convenience issues? #85501 for the 
> signed-integer-overflow suppresion.

I don't use `-fwrapv` myself, so this is more a philosophical consideration. It 
seems wrong to me for `-fsanitize=undefined` to report something as undefined 
behavior which is not undefined behavior in the used language dialect. 
`-fsanitize=undefined` already has a lot of checks that are conditioned on the 
used language dialect, so excluding the signed overflow case in particular from 
that general approach it is a bit odd.

Thanks for putting up the patch!

https://github.com/llvm/llvm-project/pull/82432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Reland Print library module manifest path again (PR #84881)

2024-03-16 Thread Kazushi Marukawa via cfe-commits

https://github.com/kaz7 approved this pull request.

Thank you for updating test scripts.  It works fine in the situation I 
explained before.  It works fine under VE buildbot configuration too.

https://github.com/llvm/llvm-project/pull/84881
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits