[clang] 6f867f9 - [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-04 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-08-04T15:12:15+08:00
New Revision: 6f867f9102838ebe314c1f3661fdf95700386e5a

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

LOG: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect 
thunk

This is to address feature request from 
https://github.com/ClangBuiltLinux/linux/issues/1665

Reviewed By: nickdesaulniers, MaskRay

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

Added: 
clang/test/CodeGen/X86/indirect-branch-cs-prefix.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/x86_features.c
llvm/lib/Target/X86/X86MCInstLower.cpp
llvm/lib/Target/X86/X86ReturnThunks.cpp
llvm/test/CodeGen/X86/attr-function-return.ll
llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd0d802ff2c10..7d90b08814baa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -138,6 +138,8 @@ CUDA Support in Clang
 X86 Support in Clang
 
 
+- Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk.
+
 DWARF Support in Clang
 --
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index ef7957979dccd..1d322814f6ee3 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -108,6 +108,8 @@ CODEGENOPT(CFProtectionBranch , 1, 0) ///< if 
-fcf-protection is
   ///< set to full or branch.
 CODEGENOPT(IBTSeal, 1, 0) ///< set to optimize CFProtectionBranch.
 CODEGENOPT(FunctionReturnThunks, 1, 0) ///< 
-mfunction-return={keep|thunk-extern}
+CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix
+ ///< is set.
 
 CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
///< enabled.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 709dbfd12cdb9..be84975547def 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2025,6 +2025,10 @@ def mfunction_return_EQ : Joined<["-"], 
"mfunction-return=">,
   NormalizedValues<["Keep", "Extern"]>,
   NormalizedValuesScope<"llvm::FunctionReturnThunksKind">,
   MarshallingInfoEnum, "Keep">;
+def mindirect_branch_cs_prefix : Flag<["-"], "mindirect-branch-cs-prefix">,
+  Group, Flags<[CoreOption, CC1Option]>,
+  HelpText<"Add cs prefix to call and jmp to indirect thunk">,
+  MarshallingInfoFlag>;
 
 defm xray_instrument : BoolFOption<"xray-instrument",
   LangOpts<"XRayInstrument">, DefaultFalse,

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dc1122f3ab67f..537cb78611b4b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -775,6 +775,9 @@ void CodeGenModule::Release() {
   if (CodeGenOpts.FunctionReturnThunks)
 getModule().addModuleFlag(llvm::Module::Override, 
"function_return_thunk_extern", 1);
 
+  if (CodeGenOpts.IndirectBranchCSPrefix)
+getModule().addModuleFlag(llvm::Module::Override, 
"indirect_branch_cs_prefix", 1);
+
   // Add module metadata for return address signing (ignoring
   // non-leaf/all) and stack tagging. These are actually turned on by function
   // attributes, but we use module metadata to emit build attributes. This is

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 231eed2acd552..7e88a203e6e2b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6359,6 +6359,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-mfunction-return=") + A->getValue()));
 
+  Args.AddLastArg(CmdArgs, options::OPT_mindirect_branch_cs_prefix);
+
   // Forward -f options with positive and negative forms; we translate these by
   // hand.  Do not propagate PGO options to the GPU-side compilations as the
   // profile info is for the host-side compilation only.

diff  --git a/clang/test/CodeGen/X86/indirect-branch-cs-prefix.c 
b/clang/test/CodeGen/X86/indirect-branch-cs-prefix.c
new file mode 100644
index 0..369db26677b4d
--- /dev/null
+++ b/clang/test/CodeGen/X86/indirect-branch-cs-prefix.c
@@ -0,0 +1,4 @@
+// RUN: %clang -target i386-unknown-unknown -o - -emit-llvm -S 
-mindirect-branch-cs-prefix %s | 

[PATCH] D130754: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-04 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
pengfei marked an inline comment as done.
Closed by commit rG6f867f910283: [X86] Support ``-mindirect-branch-cs-prefix`` 
for call and jmp to indirect thunk (authored by pengfei).

Changed prior to commit:
  https://reviews.llvm.org/D130754?vs=449275&id=449890#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130754

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/X86/indirect-branch-cs-prefix.c
  clang/test/Driver/x86_features.c
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86ReturnThunks.cpp
  llvm/test/CodeGen/X86/attr-function-return.ll
  llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll

Index: llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
===
--- llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
+++ llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
@@ -22,18 +22,22 @@
 ; X64:   callq bar
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64:   movl %[[x]], %edi
 ; X64:   callq bar
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: icall_reg:
 ; X64FAST:   callq bar
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   callq bar
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 @global_fp = external dso_local global ptr
@@ -50,16 +54,20 @@
 ; X64-LABEL: icall_global_fp:
 ; X64-DAG:   movl %edi, %[[x:[^ ]*]]
 ; X64-DAG:   movq global_fp(%rip), %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64-DAG:   movl %[[x]], %edi
 ; X64-DAG:   movq global_fp(%rip), %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: icall_global_fp:
 ; X64FAST:   movq global_fp(%rip), %r11
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   movq global_fp(%rip), %r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 %struct.Foo = type { ptr }
@@ -79,14 +87,18 @@
 ; X64:   movq (%rdi), %[[vptr:[^ ]*]]
 ; X64:   movq 8(%[[vptr]]), %[[fp:[^ ]*]]
 ; X64:   movq %[[fp]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64-DAG:   movq %[[obj]], %rdi
 ; X64-DAG:   movq %[[fp]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 ; X64FAST-LABEL: vcall:
-; X64FAST:   callq __llvm_lvi_thunk_r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 declare dso_local void @direct_callee()
@@ -113,14 +125,18 @@
 ; X64-LABEL: nonlazybind_caller:
 ; X64:   movq nonlazybind_callee@GOTPCREL(%rip), %[[REG:.*]]
 ; X64:   movq %[[REG]], %r11
-; X64:   callq __llvm_lvi_thunk_r11
+; X64:   cs
+; X64-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64:   movq %[[REG]], %r11
-; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64:   cs
+; X64-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 ; X64FAST-LABEL: nonlazybind_caller:
 ; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
-; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   cs
+; X64FAST-NEXT:  callq __llvm_lvi_thunk_r11
 ; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
-; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST:   cs
+; X64FAST-NEXT:  jmp __llvm_lvi_thunk_r11 # TAILCALL
 
 
 ; Check that a switch gets lowered using a jump table
@@ -278,3 +294,7 @@
 ; X64-NEXT:  jmpq *%r11
 
 attributes #1 = { nonlazybind }
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 4, !"indirect_branch_cs_prefix", i32 1}
Index: llvm/test/CodeGen/X86/attr-function-return.ll
===
--- llvm/test/CodeGen/X86/attr-function-return.ll
+++ llvm/test/CodeGen/X86/attr-function-return.ll
@@ -6,6 +6,11 @@
 define void @x() fn_ret_thunk_extern {
 ; CHECK-LABEL: x:
 ; CHECK:   # %bb.0:
+; CHECK-NEXT:cs
 ; CHECK-NEXT: 

[PATCH] D130754: [X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk

2022-08-04 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks for review!




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6350
 
+  if (Args.hasArg(options::OPT_mindirect_branch_cs_prefix))
+CmdArgs.push_back("-mindirect-branch-cs-prefix");

MaskRay wrote:
> pengfei wrote:
> > MaskRay wrote:
> > > This is not needed with the TableGen CC1Option change.
> > Do you have an example how to change the CC1Option? Removing the code 
> > directly won't generate the expected module flag anymore.
> OK, sorry. A statement is needed: `Args.AddLastArg(CmdArgs, 
> options::OPT_mindirect_branch_cs_prefix); `
Good to know such usage. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130754

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


[PATCH] D130735: [Clang][LLD][cmake] Drop deprecated support for `llvm-config`-based build

2022-08-04 Thread Tom Stellard via Phabricator via cfe-commits
tstellar accepted this revision.
tstellar added a comment.

LGTM.  I just tested this patch in our build config and it works fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130735

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-08-04 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic updated this revision to Diff 449894.
jpenix-quic added a comment.

Hopefully fix Window's build errors by using the proper Windows-specific 
environment utilities (_putenv_s vs setenv).


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

https://reviews.llvm.org/D130513

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/examples/external-hello.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Lower/Bridge.h
  flang/include/flang/Lower/Runtime.h
  flang/include/flang/Optimizer/Builder/Runtime/EnvironmentDefaults.h
  flang/include/flang/Optimizer/Support/InternalNames.h
  flang/include/flang/Runtime/environment-defaults.h
  flang/include/flang/Runtime/main.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Lower/Bridge.cpp
  flang/lib/Optimizer/Builder/CMakeLists.txt
  flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp
  flang/lib/Optimizer/Support/InternalNames.cpp
  flang/runtime/FortranMain/Fortran_main.c
  flang/runtime/environment-default-list.h
  flang/runtime/environment.cpp
  flang/runtime/environment.h
  flang/runtime/main.cpp
  flang/test/Driver/convert.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-mlir.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Lower/convert.f90
  flang/test/Lower/environment-defaults.f90
  flang/test/Runtime/no-cpp-dep.c
  flang/tools/bbc/bbc.cpp
  flang/unittests/Runtime/CommandTest.cpp
  flang/unittests/Runtime/Stop.cpp

Index: flang/unittests/Runtime/Stop.cpp
===
--- flang/unittests/Runtime/Stop.cpp
+++ flang/unittests/Runtime/Stop.cpp
@@ -26,7 +26,8 @@
 
 TEST(TestProgramEnd, StopTestNoStopMessage) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   EXPECT_EXIT(
   RTNAME(StopStatement)(), testing::ExitedWithCode(EXIT_SUCCESS), "");
 }
@@ -52,7 +53,8 @@
 
 TEST(TestProgramEnd, NoStopMessageTest) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   static const char *message{"bye bye"};
   EXPECT_EXIT(RTNAME(StopStatementText)(message, std::strlen(message),
   /*isErrorStop=*/false, /*quiet=*/false),
Index: flang/unittests/Runtime/CommandTest.cpp
===
--- flang/unittests/Runtime/CommandTest.cpp
+++ flang/unittests/Runtime/CommandTest.cpp
@@ -49,7 +49,7 @@
 class CommandFixture : public ::testing::Test {
 protected:
   CommandFixture(int argc, const char *argv[]) {
-RTNAME(ProgramStart)(argc, argv, {});
+RTNAME(ProgramStart)(argc, argv, {}, {});
   }
 
   std::string GetPaddedStr(const char *text, std::size_t len) const {
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -220,7 +220,7 @@
   auto burnside = Fortran::lower::LoweringBridge::create(
   ctx, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(), "",
-  kindMap);
+  kindMap, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
   std::error_code ec;
Index: flang/test/Runtime/no-cpp-dep.c
===
--- flang/test/Runtime/no-cpp-dep.c
+++ flang/test/Runtime/no-cpp-dep.c
@@ -16,18 +16,20 @@
 we're testing. We can't include any headers directly since they likely contain
 C++ code that would explode here.
 */
+struct EnvironmentDefaultList;
 struct Descriptor;
 
 double RTNAME(CpuTime)();
 
-void RTNAME(ProgramStart)(int, const char *[], const char *[]);
+void RTNAME(ProgramStart)(
+int, const char *[], const char *[], const struct EnvironmentDefaultList *);
 int32_t RTNAME(ArgumentCount)();
 int32_t RTNAME(GetCommandArgument)(int32_t, const struct Descriptor *,
 const struct Descriptor *, const struct Descriptor *);
 
 int main() {
   double x = RTNAME(CpuTime)();
-  RTNAME(ProgramStart)(0, 0, 0);
+  RTNAME(ProgramStart)(0, 0, 0, 0);
   int32_t c = RTNAME(ArgumentCount)();
   int32_t v = RTNAME(GetCommandArgument)(0, 0, 0, 0);
   return x + c + v;
Index: flang/test/Lower/environment-defaults.f90
===
--- /dev/null
+++ flang/test/Lower/environment-defaults.f90
@@ -0,0 +1,12 @@
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+program test
+  continue
+end
+
+! Test that a null pointer is generated for environment defaults if nothing is specified
+
+! CHECK: fir.global @_Q

[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-08-04 Thread Asmaa via Phabricator via cfe-commits
asmok-g added a comment.

This is also causing a compilation error in some google third-party code. 
Compiling with older clang doesn't give that error. Error:

  error: no matching function for call to object of type 
'key_compare_adapter::IntervalLess>::checked_compare'
  comp(__trans_tmp_3, k);
  ^~~~
  /tmp/pre.ii:85:5: note: in instantiation of function template specialization 
'btree_node::IntervalLess>>::linear_search_impl::IntervalLess>::checked_compare>' 
requested here
  linear_search_impl(k, 0, 0, comp,
  ^
  /tmp/pre.ii:76:32: note: in instantiation of function template specialization 
'btree_node::IntervalLess>>::linear_search::IntervalLess>::checked_compare>' 
requested here
  use_linear_search::value ? linear_search(k, comp) : binary_search(k, 
comp);
 ^
  /tmp/pre.ii:123:15: note: in instantiation of function template 
specialization 
'btree_node::IntervalLess>>::lower_bound' 
requested here
iter.node_->lower_bound(key, key_comp());
^
  /tmp/pre.ii:111:51: note: in instantiation of function template 
specialization 
'btree::IntervalLess>>::internal_lower_bound'
 requested here
template  void lower_bound(K key) { internal_lower_bound(key); }
^
  /tmp/pre.ii:133:37: note: in instantiation of function template 
specialization 
'btree::IntervalLess>>::lower_bound' 
requested here
void lower_bound(int key) { tree_.lower_bound(key); }
  ^
  /tmp/pre.ii:164:14: note: in instantiation of member function 
'btree_container::IntervalLess>>>::lower_bound'
 requested here
intervals_.lower_bound(0);
   ^
  /tmp/pre.ii:158:16: note: in instantiation of member function 
'QuicIntervalSet::Add' requested here
void Add() { Add(value_type(Add_min, Add_max)); }
 ^
  /tmp/pre.ii:190:34: note: in instantiation of member function 
'QuicIntervalSet::Add' requested here
unacked_frame_headers_offsets_.Add();
   ^
  /tmp/pre.ii:44:10: note: candidate template ignored: substitution failure 
[with T = QuicInterval, U = int]
  void operator()(T lhs, U rhs) {

I attached the preprocessed file for the case F24012260: pre.ii 
.

The commande to reproduce is: `clang -msse4.2 -O1 -fsized-deallocation 
-std=gnu++17 -c pre.ii`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-08-04 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

I'm surprised that

  $ cat test.c
  struct S {
  int m1;
  int m2[1];
  };
  void f(struct S * s) {
  s->m2[1] = 0;
  }
  
  $ clang -fsyntax-only -fstrict-flex-arrays=1 test.c
  test.c:6:5: warning: array index 1 is past the end of the array (which 
contains 1 element) [-Warray-bounds]
  s->m2[1] = 0;
  ^ ~
  test.c:3:5: note: array 'm2' declared here
  int m2[1];
  ^
  1 warning generated.

causes a warning?  I would have expected it to be suppressed in this case, as 
with the lax `-fstrict-flex-arrays=0` default, and only to hit with the 
stricter `-fstrict-flex-arrays=2`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-08-04 Thread Bogdan Graur via Phabricator via cfe-commits
bgraur added a comment.

@SimplyDanny given the reports from @joanahalili and @asmok-g are you 
considering a revert for this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D131062: [docs] Add "C++20 Modules"

2022-08-04 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 449898.
ChuanqiXu marked 15 inline comments as done.
ChuanqiXu edited the summary of this revision.
ChuanqiXu added a comment.

- Address comments.
- Tested with `make docs-clang-html`.
- Add `Known Problems` section.


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

https://reviews.llvm.org/D131062

Files:
  clang/docs/CPlusPlus20Modules.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -40,6 +40,7 @@
SafeStack
ShadowCallStack
SourceBasedCodeCoverage
+   CPlusPlus20Modules
Modules
MSVCCompatibility
MisExpect
Index: clang/docs/CPlusPlus20Modules.rst
===
--- /dev/null
+++ clang/docs/CPlusPlus20Modules.rst
@@ -0,0 +1,651 @@
+=
+C++20 Modules
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+Modules have a lot of meanings. For the users of Clang compiler, modules may
+refer to ``Objective-C Modules``, ``Clang C++ Modules`` (or ``Clang Header Modules``,
+etc) and C++20 modules. The implementation of all kinds of the modules in Clang 
+share a big part of codes. But from the perspective of users, their semantics and
+command line interfaces are very different. So it should be helpful for the users
+to introduce how to use C++20 modules.
+
+There is already a detailed document about `Clang modules `_, it
+should be helpful to read `Clang modules `_ if you want to know
+more about the general idea of modules. Due to the C++20 modules having very
+different semantics, it might be more friendly for users who care about C++20
+modules only to create a new page.
+
+Although the term ``modules`` has a unique meaning in C++20 Language Specification,
+when people talk about C++20 modules, they may refer to another C++20 feature:
+header units. So this document would try to cover header units too.
+
+C++20 Modules
+=
+
+This document was intended to be pure manual. But it should be helpful to
+introduce some language background here for readers who are not familiar with
+the new language feature. This document is not intended to be a language
+tutorial. The document would only introduce concepts about the the
+structure and building of the project.
+
+Background and terminology
+--
+
+Modules
+~~~
+
+In this document, the term ``Modules``/``modules`` refers to C++20 modules
+feature if it is not decorated by ``Clang``.
+
+Clang Modules
+~
+
+In this document, the term ``Clang Modules``/``Clang modules`` refer to Clang
+c++ modules extension. It is also known as ``Clang header modules``,
+``Clang module map modules`` or ``Clang c++ modules``.
+
+Module and module unit
+~~
+
+A module consists of one or more module units. A module unit is a special
+translation unit. Every module unit should have a module declaration. The syntax
+of the module declaration is:
+
+.. code-block:: c++
+
+  [export] module module_name[:partition_name];
+
+Things in ``[]`` means optional. The syntax of ``module_name`` and ``partition_name``
+in regex form should be ``[a-zA-Z_][a-zA-Z_0-9.]*``. The dot ``.`` in the name has
+no special meaning.
+
+In this document, module units are classified into:
+
+* Primary module interface unit.
+
+* Module implementation unit.
+
+* Module partition interface unit.
+
+* Module partition implementation unit.
+
+A primary module interface unit is a module unit whose module declaration is
+``export module module_name;``. The ``module_name`` here denotes the name of the
+module. A module should have one and only primary module interface unit.
+
+A module implementation unit is a module unit whose module declaration is
+``module module_name;``. A module could have multiple module implementation
+units with the same declaration.
+
+A module partition interface unit is a module unit whose module declaration is
+``export module module_name:partition_name;``. The ``partition_name`` should be
+unique to the module.
+
+A module partition implementation unit is a module unit whose module declaration
+is ``module module_name:partition_name;``. The ``partition_name`` should be
+unique to the module.
+
+In this document, we call ``primary module interface unit`` and
+``module partition interface unit`` as ``module interface unit``. We call ``module
+interface unit`` and ``module partition implementation unit`` as
+``importable module unit``. We call ``module partition interface unit`` and
+``module partition implementation unit`` as ``module partition unit``.
+
+Module file
+~~~
+
+A module file stands for the precompiled result of an importable module unit.
+
+Global module fragment
+~~
+
+In a module unit, the section from ``module;`` to the module declaration is called the global module fragment.
+
+
+How to build

[PATCH] D131062: [docs] Add "C++20 Modules"

2022-08-04 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/docs/CPlusPlus20Modules.rst:18
+
+There is already a detailed document about clang modules Modules_, it
+should be helpful to read Modules_ if you want to know more about the general

Mordante wrote:
> Is `Modules_` intended to be a link?
Yes, it is linked to the clang modules page: 
https://clang.llvm.org/docs/Modules.html. This mimics the style of 
https://clang.llvm.org/docs/Modules.html#where-to-learn-more-about-modules



Comment at: clang/docs/CPlusPlus20Modules.rst:22
+might be more friendly for users who care about C++20 modules only to create a
+new page.
+

Mordante wrote:
> IMO we don't need to justify why we add a new page. WDYT?
I guess it is not bad to add it. Since it is really confusing about clang 
modules and C++20 Modules at first for people who are not so familiar to these 
topics. 



Comment at: clang/docs/CPlusPlus20Modules.rst:79
+A primary module interface unit is a module unit whose module declaration is
+`export module module_name;`. The `module_name` here denotes the name of the
+module. A module should have one and only primary module interface unit.

Mordante wrote:
> Did you render the document? I would have expected double backticks.
Yeah, I had rendered it in https://overbits.herokuapp.com/rsteditor/. But it is 
not good. I found http://rst.aaroniles.net which looks better.



Comment at: clang/docs/CPlusPlus20Modules.rst:133
+  module;
+  #include 
+  #include 

Mordante wrote:
> Does `import ;` work? If not is that a Clang or libc++ limitation?
Yes, `import ` works here. But I don't want to introduce too many 
information here. And I mentioned it indirectly later in `Include translation` 
section.



Comment at: clang/docs/CPlusPlus20Modules.rst:164
+  # Precompiling the module
+  clang++ -std=c++20 interface_part.cppm --precompile -o M-interface_part.pcm
+  clang++ -std=c++20 impl_part.cppm --precompile -fprebuilt-module-path=. -o 
M-impl_part.pcm

Mordante wrote:
> Maybe explain what all steps do.
I made a simple explanation in the `#` part and I intended to explain them in 
more detail in the following sections. I feel it may be confusing for readers 
who reads at the first time?



Comment at: clang/docs/CPlusPlus20Modules.rst:183
+
+Currently, C++20 Modules is enabled automatically if the language standard is 
`-std=c++20`.
+Sadly, we can't enable C++20 Modules now with lower language standard versions 
like coroutines by `-fcoroutines-ts` due to some implementation problems.

Mordante wrote:
> I assume `-std=c++2b` works too. Maybe rephrase the wording like this.
I sent a backport patch to 15.x: 
https://github.com/llvm/llvm-project/issues/56803. So it `-std=c++2b` should be 
fine in 15.x


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

https://reviews.llvm.org/D131062

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


[PATCH] D131062: [docs] Add "C++20 Modules"

2022-08-04 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/docs/CPlusPlus20Modules.rst:377-393
+  │ │  
  ││
+  ├─  frontend ─┼─  middle end 
──┼─── backend ┤
+  │ │  
  ││
+  └─── parsing  sema  codegen ──┴─── optimizations ─── IPO  ─── 
optimizations ─── codegen ───┴─── optimizations ─── codegen ──┘
+   
   
+  
┌───┐
+  │
   │

ChuanqiXu wrote:
> I'm not sure if this could be rendered properly, if there is any suggestion?
Now I've tested it with `make docs-clang-html`, and it looks not bad.


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

https://reviews.llvm.org/D131062

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


[clang] 127bf44 - [Clang][C++20] Support capturing structured bindings in lambdas

2022-08-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-04T10:12:53+02:00
New Revision: 127bf44385424891eb04cff8e52d3f157fc2cb7c

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

LOG: [Clang][C++20] Support capturing structured bindings in lambdas

This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate 
the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was 
already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this 
change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGenCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/decomposition-blocks.cpp
clang/test/SemaCXX/decomposition-openmp.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/LambdaCapture.h
clang/include/clang/AST/Stmt.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 5d4f3b8249249..fc3dfbdeac785 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -785,8 +785,8 @@ bool 
ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
const LambdaCapture *C,
Expr *Init) {
   if (C->capturesVariable()) {
-const VarDecl *VDecl = C->getCapturedVar();
-if (areSameVariable(IndexVar, cast(VDecl))) {
+const ValueDecl *VDecl = C->getCapturedVar();
+if (areSameVariable(IndexVar, VDecl)) {
   // FIXME: if the index is captured, it will count as an usage and the
   // alias (if any) won't work, because it is only used in case of having
   // exactly one usage.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d90b08814baa..878effe08294c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,6 +108,16 @@ C++ Language Changes in Clang
 C++20 Feature Support
 ^
 
+- Support capturing structured bindings in lambdas
+  (`P1091R3 `_ and `P1381R1 
`).
+  This fixes issues `GH52720 
`_,
+  `GH54300 `_,
+  `GH54301 `_,
+  and `GH49430 `_.
+
+
+
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST

[PATCH] D122768: [Clang][C++20] Support capturing structured bindings in lambdas

2022-08-04 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG127bf4438542: [Clang][C++20] Support capturing structured 
bindings in lambdas (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122768

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/LambdaCapture.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/CodeGenCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/cxx1z-decomposition.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/decomposition-blocks.cpp
  clang/test/SemaCXX/decomposition-openmp.cpp
  clang/tools/libclang/CIndex.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1140,7 +1140,7 @@
 
   Structured binding extensions
   https://wg21.link/p1091r3";>P1091R3
-  Partial
+  Clang 16
 
   
 https://wg21.link/p1381r1";>P1381R1
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3482,9 +3482,11 @@
C != CEnd; ++C) {
 if (!C->capturesVariable())
   continue;
-
-if (Visit(MakeCursorVariableRef(C->getCapturedVar(), C->getLocation(),
-TU)))
+// TODO: handle structured bindings here ?
+if (!isa(C->getCapturedVar()))
+  continue;
+if (Visit(MakeCursorVariableRef(cast(C->getCapturedVar()),
+C->getLocation(), TU)))
   return true;
   }
   // Visit init captures
Index: clang/test/SemaCXX/decomposition-openmp.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/decomposition-openmp.cpp
@@ -0,0 +1,13 @@
+
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fopenmp %s
+
+// FIXME: OpenMP should support capturing structured bindings
+auto f() {
+  int i[2] = {};
+  auto [a, b] = i; // expected-note 2{{declared here}}
+  return [=, &a] {
+// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
+return a + b;
+// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
+  };
+}
Index: clang/test/SemaCXX/decomposition-blocks.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/decomposition-blocks.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -fblocks
+
+struct S {
+  int i : 1;
+  int j;
+};
+
+void run(void (^)());
+void test() {
+  auto [i, j] = S{1, 42}; // expected-note {{'i' declared here}}
+  run(^{
+(void)i; // expected-error {{reference to local binding 'i' declared in enclosing function 'test'}}
+  });
+}
Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+struct S {
+  int i;
+  int &j;
+};
+
+void check_category() {
+  int a = 42;
+  {
+auto [v, r] = S{1, a};
+(void)[ v, r ] {
+  static_assert(is_same);
+  static_assert(is_same);
+};
+  }
+  {
+auto [v, r] = S{1, a};
+(void)[&v, &r ] {
+  static_assert(is_same);
+  static_assert(is_same);
+};
+  }
+  {
+S s{1, a};
+const auto &[v, r] = s;
+(void)[ v, r ] 

[PATCH] D131062: [docs] Add "C++20 Modules"

2022-08-04 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D131062#3697193 , @Mordante wrote:

> Thanks a lot for working on this!
>
> I wonder whether it would be better to have some of the more technical 
> information in a separate file and let this file mainly have an introduction 
> to modules in general and how to get started using them in Clang.

What do you mean about the `more technical information`? Do you refer to the 
section `How module speed up the compilation`?

I added the `How module speed up the compilation` section since I know people 
are curious about why and how modules could speedup the compilation. And this 
section tries tell them that they may probably get what they want in O0 but not 
so much in O2  (and still some 
improvements after all) and also the reasons.

> let this file mainly have an introduction to modules in general

If I don't misread, do you say that we need make this one like a modules 
tutorial? If yes, I think it is not what I thought. I treat this one like a 
toolchain documentation instead of a language feature documentation. Everything 
in the doc is about the building.
I put the language background since I want to make the doc self-contained. And 
everything else is related to the building. I understand it is good/needed to 
introduce about modules since it really brings many new concepts. Personally, I 
feel like it would be done by somebody else besides of clang docs. The compiler 
and languages are deeply connected but they are still different to me.

> I haven't tested the steps yet, but I intend to see whether the examples work 
> for me.
>
> I haven't validated whether the module explanation is correct; I'm sure there 
> are other reviewers who have a deeper knowledge of modules.

Thanks. I've tested all the examples. It is always good to have more testers. 
It should be good at trunk. If you want to test with 15.x, you may need to wait 
for the merge of https://github.com/llvm/llvm-project-release-prs/pull/40 and 
https://github.com/llvm/llvm-project-release-prs/pull/40




Comment at: clang/docs/CPlusPlus20Modules.rst:35
+tutorial. The document would only introduce concepts about the the
+structure and building of the project.
+

Mordante wrote:
> How about mentioning the state of modules in Clang? In your GitHub repository 
> you mention some limitations. (A link to a status page could be an 
> alternative.)
Yeah, I've added the `Known Problems` section.


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

https://reviews.llvm.org/D131062

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-08-04 Thread Bogdan Graur via Phabricator via cfe-commits
bgraur added a subscriber: tstellar.
bgraur added a comment.

@tstellar FYI the clang crash report from @joanahalili and the new compilation 
errors report from @asmok-g, both introduced by this patch.
Is a revert warranted here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D130015: [clangd] Add "usedAsMutablePointer" highlighting modifier

2022-08-04 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130015

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-08-04 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added inline comments.



Comment at: flang/lib/Lower/Bridge.cpp:203
 //them.
 for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
   std::visit(Fortran::common::visitors{

Doing this can avoid add one variable to the bridge.


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

https://reviews.llvm.org/D130513

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Reverting for @bgraur as he's having some issues with his commit access ATM. To 
sum up the reproducer attached by @joanahalili triggers a crash 
https://reviews.llvm.org/rG4e94f6653150511de434fa7e29b684ae7f0e52b6 with stack 
trace and error:

  $ ~/repos/llvm/build/bin/clang -xc++ -c a.cc
  a.cc:3:38: error: cannot compile this l-value expression yet
template  void ad(c p1) { ab(d()(p1)); }
   ^~
  Unexpected placeholder builtin type!
  UNREACHABLE executed at 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CodeGenTypes.cpp:641!
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: 
/usr/local/google/home/kadircet/repos/llvm/build/bin/clang -xc++ -c a.cc
  1.   parser at end of file
  2.  Per-file LLVM IR generation
  3.  a.cc:3:27: Generating code for declaration 'b::n>::j::n>>::ad'
   #0 0x064fb563 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:569:13
   #1 0x064f92fe llvm::sys::RunSignalHandlers() 
/usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:104:18
   #2 0x0645f823 (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
/usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:76:5
   #3 0x0645f9de CrashRecoverySignalHandler(int) 
/usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:390:1
   #4 0x7f8c235bf200 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12200)
   #5 0x7f8c2302c8a1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:50:1
   #6 0x7f8c23016546 abort ./stdlib/abort.c:81:7
   #7 0x06465531 
(/usr/local/google/home/kadircet/repos/llvm/build/bin/clang+0x6465531)
   #8 0x0689b09f 
(/usr/local/google/home/kadircet/repos/llvm/build/bin/clang+0x689b09f)
   #9 0x068be0f1 
clang::CodeGen::CodeGenFunction::EmitUnsupportedLValue(clang::Expr const*, char 
const*) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExpr.cpp:1250:22
  #10 0x068b4703 
clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExpr.cpp:0:19
  #11 0x068d3fab isSimple 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:265:41
  #12 0x068d3fab getPointer 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:338:5
  #13 0x068d3fab 
clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExpr.cpp:5131:31
  #14 0x068d3c72 isBuiltin 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGCall.h:151:12
  #15 0x068d3c72 
clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, 
clang::CodeGen::ReturnValueSlot) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExpr.cpp:5014:14
  #16 0x069e0518 getInt 
/usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/PointerIntPair.h:62:57
  #17 0x069e0518 isScalar 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:54:37
  #18 0x069e0518 getScalarVal 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:62:5
  #19 0x069e0518 (anonymous 
namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExprScalar.cpp:578:36
  #20 0x069e1338 Visit 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExprScalar.cpp:408:52
  #21 0x069e1338 (anonymous 
namespace)::ScalarExprEmitter::VisitExprWithCleanups(clang::ExprWithCleanups*) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExprScalar.cpp:2447:14
  #22 0x069d1128 Visit 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExprScalar.cpp:408:52
  #23 0x069d1128 
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExprScalar.cpp:4874:8
  #24 0x068b3a47 PointerIntPair 
/usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/PointerIntPair.h:49:12
  #25 0x068b3a47 RValue 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:39:7
  #26 0x068b3a47 get 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGValue.h:90:12
  #27 0x068b3a47 
clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot, bool) 
/usr/local/google/home/kadircet/repos/llvm/clang/lib/CodeGen/CGExpr.cpp:217:12
  #28 0x068b39d1 
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) 
/usr/

[clang] c8b2f3f - [ObjC] type method metadata `_imp`, messenger routine at callsite with program address space

2022-08-04 Thread Matt Jacobson via cfe-commits

Author: Matt Jacobson
Date: 2022-08-04T05:40:32-04:00
New Revision: c8b2f3f51bd923afbf9d3ebd0823bce895629630

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

LOG: [ObjC] type method metadata `_imp`, messenger routine at callsite with 
program address space

On targets with non-default program address space (e.g., Harvard
architectures), clang crashes when emitting Objective-C method metadata,
because the address of the method IMP cannot be bitcast to i8*. It similarly
crashes at messenger callsite with a failed bitcast.

Define the _imp field instead as i8 addrspace(1)* (or whatever the target's
program address space is). And in getMessageSendInfo(), create signatureType by
specifying the program address space.

Add a regression test using the AVR target. Test failed previously and passes
now. Checked codegen of the test for x86_64-apple-darwin19.6.0 and saw no
difference, as expected.

Reviewed By: rjmccall, dylanmckay

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

Added: 
clang/test/CodeGen/avr/objc-method.m

Modified: 
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 46e65eb1ed43d..2d704cec05761 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -174,6 +174,7 @@ class ObjCCommonTypesHelper {
 public:
   llvm::IntegerType *ShortTy, *IntTy, *LongTy;
   llvm::PointerType *Int8PtrTy, *Int8PtrPtrTy;
+  llvm::PointerType *Int8PtrProgramASTy;
   llvm::Type *IvarOffsetVarTy;
 
   /// ObjectPtrTy - LLVM type for object handles (typeof(id))
@@ -5739,11 +5740,13 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
 {
   CodeGen::CodeGenTypes &Types = CGM.getTypes();
   ASTContext &Ctx = CGM.getContext();
+  unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace();
 
   ShortTy = cast(Types.ConvertType(Ctx.ShortTy));
   IntTy = CGM.IntTy;
   LongTy = cast(Types.ConvertType(Ctx.LongTy));
   Int8PtrTy = CGM.Int8PtrTy;
+  Int8PtrProgramASTy = llvm::PointerType::get(CGM.Int8Ty, ProgramAS);
   Int8PtrPtrTy = CGM.Int8PtrPtrTy;
 
   // arm64 targets use "int" ivar offset variables. All others,
@@ -5812,7 +5815,7 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
   //   char *_imp;
   // }
   MethodTy = llvm::StructType::create("struct._objc_method", SelectorPtrTy,
-  Int8PtrTy, Int8PtrTy);
+  Int8PtrTy, Int8PtrProgramASTy);
 
   // struct _objc_cache *
   CacheTy = llvm::StructType::create(VMContext, "struct._objc_cache");
@@ -6771,11 +6774,11 @@ void 
CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder,
 
   if (forProtocol) {
 // Protocol methods have no implementation. So, this entry is always NULL.
-method.addNullPointer(ObjCTypes.Int8PtrTy);
+method.addNullPointer(ObjCTypes.Int8PtrProgramASTy);
   } else {
 llvm::Function *fn = GetMethodDefinition(MD);
 assert(fn && "no definition for method?");
-method.addBitCast(fn, ObjCTypes.Int8PtrTy);
+method.addBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
   }
 
   method.finishAndAddTo(builder);

diff  --git a/clang/lib/CodeGen/CGObjCRuntime.cpp 
b/clang/lib/CodeGen/CGObjCRuntime.cpp
index 550fd3d70bdcc..7780a61aa648a 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.cpp
+++ b/clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -360,13 +360,15 @@ CGObjCRuntime::MessageSendInfo
 CGObjCRuntime::getMessageSendInfo(const ObjCMethodDecl *method,
   QualType resultType,
   CallArgList &callArgs) {
+  unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace();
+
   // If there's a method, use information from that.
   if (method) {
 const CGFunctionInfo &signature =
   CGM.getTypes().arrangeObjCMessageSendSignature(method, callArgs[0].Ty);
 
 llvm::PointerType *signatureType =
-  CGM.getTypes().GetFunctionType(signature)->getPointerTo();
+  CGM.getTypes().GetFunctionType(signature)->getPointerTo(ProgramAS);
 
 const CGFunctionInfo &signatureForCall =
   CGM.getTypes().arrangeCall(signature, callArgs);
@@ -380,7 +382,7 @@ CGObjCRuntime::getMessageSendInfo(const ObjCMethodDecl 
*method,
 
   // Derive the signature to call from that.
   llvm::PointerType *signatureType =
-CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
+CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo(ProgramAS);
   return MessageSendInfo(argsInfo, signatureType);
 }
 

diff  --git a/clang/test/CodeGen/avr/objc-method.m 
b/clang/test/CodeGen/avr/objc-method.m
new file mode 100644
index 0..aeafb8e63466e
--- /dev/null
+++ b/clang/te

[PATCH] D112113: [ObjC] type method metadata `_imp`, messenger routine at callsite with program address space

2022-08-04 Thread Matt Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc8b2f3f51bd9: [ObjC] type method metadata `_imp`, messenger 
routine at callsite with program… (authored by mhjacobson).
Herald added a project: All.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112113

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/test/CodeGen/avr/objc-method.m

Index: clang/test/CodeGen/avr/objc-method.m
===
--- /dev/null
+++ clang/test/CodeGen/avr/objc-method.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm -fobjc-runtime=macosx %s -o /dev/null
+
+__attribute__((objc_root_class))
+@interface Foo
+
+- (id)foo;
+- (id)bar;
+
+@end
+
+@implementation Foo
+
+- (id)foo {
+  return self;
+}
+
+- (id)bar {
+  return [self foo];
+}
+
+@end
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -360,13 +360,15 @@
 CGObjCRuntime::getMessageSendInfo(const ObjCMethodDecl *method,
   QualType resultType,
   CallArgList &callArgs) {
+  unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace();
+
   // If there's a method, use information from that.
   if (method) {
 const CGFunctionInfo &signature =
   CGM.getTypes().arrangeObjCMessageSendSignature(method, callArgs[0].Ty);
 
 llvm::PointerType *signatureType =
-  CGM.getTypes().GetFunctionType(signature)->getPointerTo();
+  CGM.getTypes().GetFunctionType(signature)->getPointerTo(ProgramAS);
 
 const CGFunctionInfo &signatureForCall =
   CGM.getTypes().arrangeCall(signature, callArgs);
@@ -380,7 +382,7 @@
 
   // Derive the signature to call from that.
   llvm::PointerType *signatureType =
-CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
+CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo(ProgramAS);
   return MessageSendInfo(argsInfo, signatureType);
 }
 
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -174,6 +174,7 @@
 public:
   llvm::IntegerType *ShortTy, *IntTy, *LongTy;
   llvm::PointerType *Int8PtrTy, *Int8PtrPtrTy;
+  llvm::PointerType *Int8PtrProgramASTy;
   llvm::Type *IvarOffsetVarTy;
 
   /// ObjectPtrTy - LLVM type for object handles (typeof(id))
@@ -5739,11 +5740,13 @@
 {
   CodeGen::CodeGenTypes &Types = CGM.getTypes();
   ASTContext &Ctx = CGM.getContext();
+  unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace();
 
   ShortTy = cast(Types.ConvertType(Ctx.ShortTy));
   IntTy = CGM.IntTy;
   LongTy = cast(Types.ConvertType(Ctx.LongTy));
   Int8PtrTy = CGM.Int8PtrTy;
+  Int8PtrProgramASTy = llvm::PointerType::get(CGM.Int8Ty, ProgramAS);
   Int8PtrPtrTy = CGM.Int8PtrPtrTy;
 
   // arm64 targets use "int" ivar offset variables. All others,
@@ -5812,7 +5815,7 @@
   //   char *_imp;
   // }
   MethodTy = llvm::StructType::create("struct._objc_method", SelectorPtrTy,
-  Int8PtrTy, Int8PtrTy);
+  Int8PtrTy, Int8PtrProgramASTy);
 
   // struct _objc_cache *
   CacheTy = llvm::StructType::create(VMContext, "struct._objc_cache");
@@ -6771,11 +6774,11 @@
 
   if (forProtocol) {
 // Protocol methods have no implementation. So, this entry is always NULL.
-method.addNullPointer(ObjCTypes.Int8PtrTy);
+method.addNullPointer(ObjCTypes.Int8PtrProgramASTy);
   } else {
 llvm::Function *fn = GetMethodDefinition(MD);
 assert(fn && "no definition for method?");
-method.addBitCast(fn, ObjCTypes.Int8PtrTy);
+method.addBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
   }
 
   method.finishAndAddTo(builder);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131006: [analyzer] Use DisequalityMap while inferring constraints

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Awesome!




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1512-1516
+if (IsFirst) {
+  IsFirst = false;
+  RS = *RSPtr;
+} else
+  RS = RangeFactory.unite(RS, *RSPtr);

`unite` should be working with an empty set as well, shouldn't it?



Comment at: clang/test/Analysis/range-inferring-from-disequality-map.cpp:10-11
+ clang_analyzer_value(x); // expected-warning {{32s:{ [0, 0] }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp; // Keep alive.

Good point.

We should have an additional check in `removeDeadBindings` that goes through 
the disequality map of the dead symbol. And if any of the mapped classes are 
not dead then we shall not delete the dead symbol's equivalent class.



Comment at: clang/test/Analysis/range-inferring-from-disequality-map.cpp:50-51
+if(x != tmp1 && x != tmp2)
+  // TODO: This condition should be infeasible.
+  //   Thus, the branch should be unreachable.
+  clang_analyzer_value(x); // expected-warning {{{ empty }}}

Why can't we return an empty set from `getInvertedRangeFromDisequalityMap` in 
this case? `intersect` should handle the rest then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131006

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


[PATCH] D131153: AArch64: disable asynchronous unwind by default for MachO.

2022-08-04 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
Herald added subscribers: kristof.beyls, mcrosier.
Herald added a project: All.
t.p.northover requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

AArch64 MachO has a compact unwind format where most functions' unwind info can 
be represented in just 4 bytes. But this cannot represent any asynchronous CFI 
function, so it's essentially disabled when that's used. This is a large 
code-size hit that we'd rather not take unless explicitly requested.

So this patch adds a new callback to switch the default on ARM64 MachO to 
synchronous. Command-line options can still turn it on if anyone wants to take 
the hit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131153

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/test/Driver/clang-translation.c
  clang/test/Preprocessor/unwind-tables.c

Index: clang/test/Preprocessor/unwind-tables.c
===
--- clang/test/Preprocessor/unwind-tables.c
+++ clang/test/Preprocessor/unwind-tables.c
@@ -3,7 +3,7 @@
 
 // RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
 // RUN: %clang %s -dM -E -target x86_64 -funwind-tables -fno-asynchronous-unwind-tables -g | FileCheck %s
-// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
+// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s --check-prefix=NO
 // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s
 // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s
 
Index: clang/test/Driver/clang-translation.c
===
--- clang/test/Driver/clang-translation.c
+++ clang/test/Driver/clang-translation.c
@@ -78,7 +78,11 @@
 
 // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-APPLE %s
-// ARM64-APPLE: -funwind-tables=2
+// ARM64-APPLE-NOT: -funwind-tables
+
+// RUN: %clang -target arm64-apple-ios10 -funwind-tables -### -S %s -arch arm64 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM64-APPLE-UNWIND %s
+// ARM64-APPLE-UNWIND: -funwind-tables=1
 
 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s
Index: clang/lib/Driver/ToolChains/Darwin.h
===
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -256,6 +256,9 @@
 
   bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
 
+  bool
+  IsAsyncUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
+
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2894,6 +2894,15 @@
true));
 }
 
+bool MachO::IsAsyncUnwindTablesDefault(const ArgList &Args) const {
+  // AArch64 has compact unwind format, making the size overhead from
+  // asynchronous unwind particularly bad, so disable by default.
+  if (getArch() == llvm::Triple::aarch64)
+return false;
+
+  return IsUnwindTablesDefault(Args);
+}
+
 bool MachO::UseDwarfDebugFlags() const {
   if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
 return S[0] != '\0';
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5387,11 +5387,12 @@
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
   auto SanitizeArgs = TC.getSanitizerArgs(Args);
-  bool AsyncUnwindTables = Args.hasFlag(
-  options::OPT_fasynchronous_unwind_tables,
-  options::OPT_fno_asynchronous_unwind_tables,
-  (TC.IsUnwindTablesDefault(Args) || SanitizeArgs.needsUnwindTables()) &&
-  !Freestanding);
+  bool AsyncUnwindTables =
+  Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
+   options::OPT_fno_asynchronous_unwind_tables,
+   (TC.IsAsyncUnwindTablesDefault(Args) ||
+SanitizeArgs.needsUnwindTables()) &&
+   !Freestanding);
   bool UnwindTables = Args.hasFlag(options::OPT_funwind_tables,
options::OPT_fno_unwind_tables, false);
   if (AsyncUnwindTables)
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolC

[PATCH] D130372: [analyzer] Add a new factory function RangeSet::Factory::invert

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM! Nice work!


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

https://reviews.llvm.org/D130372

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


[PATCH] D128248: [clang] Avoid an assertion in APValue::hasArrayFiller()

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Abandoning as per the discussion in 
https://discourse.llvm.org/t/apvalue-lifetime-problem-when-evaluating-constant-expressions/64002/5.
 This patch just hides a problem.


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

https://reviews.llvm.org/D128248

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


[PATCH] D131006: [analyzer] Use DisequalityMap while inferring constraints

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/range-inferring-from-disequality-map.cpp:10-11
+ clang_analyzer_value(x); // expected-warning {{32s:{ [0, 0] }}}
+  // TODO:  TODO: Keep x range correct even if associated disequalities are
+  // already dead.
+  (void)tmp; // Keep alive.

martong wrote:
> Good point.
> 
> We should have an additional check in `removeDeadBindings` that goes through 
> the disequality map of the dead symbol. And if any of the mapped classes are 
> not dead then we shall not delete the dead symbol's equivalent class.
> Good point.
> 
> We should have an additional check in `removeDeadBindings` that goes through 
> the disequality map of the dead symbol. And if any of the mapped classes are 
> not dead then we shall not delete the dead symbol's equivalent class.

It would be better to address that in a child patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131006

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


[PATCH] D130470: [clang][analyzer] Add more wide-character functions to CStringChecker

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

I think there's only some very minor style nits which are remained, but that 
should not block this any further. Let's land it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130470

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


[PATCH] D131067: [analyzer] Treat values passed as parameter as escaped

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks, looks good with some nits.




Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:556-558
+unsigned numParams = FD->getNumParams();
+for (unsigned i = 0; i < numParams; ++i) {
+  findReferenceParameter(FD->getParamDecl(i), CE->getArg(i));

This could be hoisted into `findCallReferenceParameters(const FunctionDecl 
*FD)` thus avoiding code repetition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131067

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


[clang-tools-extra] df48e3f - Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator overloads"

2022-08-04 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-08-04T12:14:43+02:00
New Revision: df48e3fbcc8be1f4c04bd97517d12e662f54de75

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

LOG: Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator 
overloads"

This reverts commit 4e94f6653150511de434fa7e29b684ae7f0e52b6.
See https://reviews.llvm.org/D129973#3698969 for reasoning.

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/AST/ast-dump-overloaded-operators.cpp
clang/test/Index/annotate-operator-call-expr.cpp
clang/test/Index/cursor-ref-names.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 0d08edb3803ab..63bf34cfafe9e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -210,14 +210,3 @@ template  class U> class 
Bar {};
 // We used to report Q unsued, because we only checked the first template
 // argument.
 Bar *bar;
-
-namespace internal { 
-  struct S {};
-  int operator+(S s1, S s2);
-} 
-
-// Make sure this statement is not reported as unused.
-using internal::operator+; 
-using internal::S;
-
-int j() { return S() + S(); }

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ba86b54dd0ce9..2a8acacc8a8e7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -63,9 +63,8 @@ static ExprResult CreateFunctionRefExpr(
   // being used.
   if (FoundDecl != Fn && S.DiagnoseUseOfDecl(Fn, Loc))
 return ExprError();
-  DeclRefExpr *DRE =
-  DeclRefExpr::Create(S.Context, Fn->getQualifierLoc(), SourceLocation(),
-  Fn, false, Loc, Fn->getType(), VK_LValue, FoundDecl);
+  DeclRefExpr *DRE = new (S.Context)
+  DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, 
LocInfo);
   if (HadMultipleCandidates)
 DRE->setHadMultipleCandidates(true);
 

diff  --git a/clang/test/AST/ast-dump-overloaded-operators.cpp 
b/clang/test/AST/ast-dump-overloaded-operators.cpp
index 4551a6715d4c9..dc6d7bdc9b085 100644
--- a/clang/test/AST/ast-dump-overloaded-operators.cpp
+++ b/clang/test/AST/ast-dump-overloaded-operators.cpp
@@ -24,44 +24,21 @@ void test() {
 // CHECK-NEXT: |-FunctionDecl {{.*}}  col:6{{( imported)?}} 
used operator, 'void (E, E)'
 // CHECK-NEXT: | |-ParmVarDecl {{.*}}  col:17{{( imported)?}} 'E'
 // CHECK-NEXT: | `-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
-// CHECK-NEXT: |-FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
-// CHECK-NEXT: | `-CompoundStmt {{.*}} 
-// CHECK-NEXT: |   |-DeclStmt {{.*}} 
-// CHECK-NEXT: |   | `-VarDecl {{.*}}  col:5{{( imported)?}} 
used e 'E'
-// CHECK-NEXT: |   |-CXXOperatorCallExpr {{.*}}  'void' '+'
-// CHECK-NEXT: |   | |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

-// CHECK-NEXT: |   | | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator+' 'void (E, E)'
-// CHECK-NEXT: |   | |-ImplicitCastExpr {{.*}}  'E':'E' 
-// CHECK-NEXT: |   | | `-DeclRefExpr {{.*}}  'E':'E' lvalue Var {{.*}} 
'e' 'E':'E'
-// CHECK-NEXT: |   | `-ImplicitCastExpr {{.*}}  'E':'E' 
-// CHECK-NEXT: |   |   `-DeclRefExpr {{.*}}  'E':'E' lvalue Var {{.*}} 
'e' 'E':'E'
-// CHECK-NEXT: |   `-CXXOperatorCallExpr {{.*}}  'void' ','
-// CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

-// CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator,' 'void (E, E)'
-// CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'E':'E' 
-// CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'E':'E' lvalue Var {{.*}} 
'e' 'E':'E'
-// CHECK-NEXT: | `-ImplicitCastExpr {{.*}}  'E':'E' 
-// CHECK-NEXT: |   `-DeclRefExpr {{.*}}  'E':'E' lvalue Var {{.*}} 
'e' 'E':'E'
-
-namespace a {
-  void operator-(E, E);
-}
-
-using a::operator-;
-
-void f() {
-  E() - E();
-}
-// CHECK: |-NamespaceDecl {{.*}}  line:46:11{{( imported 
)?}} a
-// CHECK-NEXT: | `-FunctionDecl {{.*}}  col:8{{( 
imported)?}} used operator- 'void (E, E)'
-// CHECK-NEXT: |   |-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
-// CHECK-NEXT: |   `-ParmVarDecl {{.*}}  col:22{{( imported)?}} 'E'
-// CHECK-NEXT: |-UsingDecl {{.*}}  col:10{{( imported)?}} 
a::operator-
-// CHECK-NEXT: |-UsingShadowDecl {{.*}}  col:10{{( imported)?}} 
implicit Function {{.*}} 'operator-' 'void (E, E)'
-// CHECK-NEXT: `-FunctionDecl {{.*}}  line:52:6{{( 
imported)?}} f 'void ()'
-// CHECK-NEXT:   `-CompoundStmt {{.*}} 
-// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}}  'void' '-'
-// CHE

[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-08-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Reverted in df48e3fbcc8be1f4c04bd97517d12e662f54de75 
, 
@tstellar it needs to be cherry-picked into release branch as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D130705: [clang][ASTImporter] Improve import of functions with auto return type.

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thank you, nice and assiduous work!

The changes look good to me, but I think we should have some more tests where 
variable and function template specializations are used as return types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130705

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


[PATCH] D131154: FoldingRanges: Handle LineFoldingsOnly clients.

2022-08-04 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 created this revision.
usaxena95 added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Do not fold the endline which contains tokens after the end of range.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131154

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -196,7 +196,7 @@
   ElementsAre(SourceAnnotations.range("empty")));
 }
 
-TEST(FoldingRanges, All) {
+TEST(FoldingRanges, ASTAll) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -265,7 +265,7 @@
   }
 }
 
-TEST(FoldingRangesPseudoParser, All) {
+TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -359,13 +359,44 @@
   };
   for (const char *Test : Tests) {
 auto T = Annotations(Test);
-EXPECT_THAT(
-gatherFoldingRanges(llvm::cantFail(getFoldingRanges(T.code().str(,
-UnorderedElementsAreArray(T.ranges()))
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/false))),
+UnorderedElementsAreArray(T.ranges()))
 << Test;
   }
 }
 
+TEST(FoldingRanges, PseudoParserLineFoldingsOnly) {
+  const char *Tests[] = {
+  R"cpp(
+void func(int a) {[[
+  if(a == 1) {[[
+a++;]]
+  } else {[[
+a--;
+  ]]}
+  if(a == 1) {[[
+a++;]]
+  } // A token on the end line.
+]]}
+  )cpp",
+  };
+  auto StripColumns = [](const std::vector &Ranges) {
+std::vector Res;
+for (Range R : Ranges) {
+  R.start.character = R.end.character = 0;
+  Res.push_back(R);
+}
+return Res;
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/true))),
+UnorderedElementsAreArray(StripColumns(T.ranges(
+<< Test;
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -33,7 +33,7 @@
 /// Returns a list of ranges whose contents might be collapsible in an editor.
 /// This version uses the pseudoparser which does not require the AST.
 llvm::Expected>
-getFoldingRanges(const std::string &Code);
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly);
 
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -179,7 +179,7 @@
 // statement bodies).
 // Related issue: https://github.com/clangd/clangd/issues/310
 llvm::Expected>
-getFoldingRanges(const std::string &Code) {
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly) {
   auto OrigStream = pseudo::lex(Code, clang::pseudo::genericLangOpts());
 
   auto DirectiveStructure = pseudo::DirectiveTree::parse(OrigStream);
@@ -192,15 +192,21 @@
   pseudo::pairBrackets(ParseableStream);
 
   std::vector Result;
-  auto ToFoldingRange = [](Position Start, Position End,
-   llvm::StringLiteral Kind) {
+  auto AddFoldingRange = [&](Position Start, Position End,
+ llvm::StringLiteral Kind) {
+if (Start.line >= End.line)
+  return;
 FoldingRange FR;
 FR.startLine = Start.line;
-FR.startCharacter = Start.character;
 FR.endLine = End.line;
-FR.endCharacter = End.character;
+if (LineFoldingsOnly)
+  FR.startCharacter = FR.endCharacter = 0;
+else {
+  FR.startCharacter = Start.character;
+  FR.endCharacter = End.character;
+}
 FR.kind = Kind.str();
-return FR;
+Result.push_back(FR);
   };
   auto OriginalToken = [&](const pseudo::Token &T) {
 return OrigStream.tokens()[T.OriginalIndex];
@@ -221,9 +227,16 @@
  

[PATCH] D131155: [clang] Expand array expressions if the filler expression's filler is element dependent

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is about the problem described in 
https://discourse.llvm.org/t/apvalue-lifetime-problem-when-evaluating-constant-expressions/64002/5

The (old) condition in this if statement is meant to handle initializers that 
depend on (other) array elements. In this case, the array needs to be expanded 
before the array filler is evaluated:

  if (NumEltsToInit != NumElts && MaybeElementDependentArrayFiller(FillerExpr))
NumEltsToInit = NumElts;

in the test case described on Discourse (which is attached in the patch), 
`MaybeElementDependentArrayFiller()` returns `false` for the outer array but 
true for the inner array. Since every `InitListExpr` can have an array filler, 
I believe the function should take that into account.

This fixes https://github.com/llvm/llvm-project/issues/56016


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131155

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-array-init.cpp


Index: clang/test/SemaCXX/constexpr-array-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+struct Foo {
+  int a;
+  constexpr Foo()
+  : a(get_int()) {
+  }
+
+  constexpr int get_int() const {
+return 5;
+  }
+};
+
+static constexpr Foo bar[2][1] = {
+{{}},
+};
+static_assert(bar[0][0].a == 5);
+static_assert(bar[1][0].a == 5);
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10695,6 +10695,11 @@
   if (MaybeElementDependentArrayFiller(ILE->getInit(I)))
 return true;
 }
+
+if (ILE->hasArrayFiller() &&
+MaybeElementDependentArrayFiller(ILE->getArrayFiller()))
+  return true;
+
 return false;
   }
   return true;


Index: clang/test/SemaCXX/constexpr-array-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+struct Foo {
+  int a;
+  constexpr Foo()
+  : a(get_int()) {
+  }
+
+  constexpr int get_int() const {
+return 5;
+  }
+};
+
+static constexpr Foo bar[2][1] = {
+{{}},
+};
+static_assert(bar[0][0].a == 5);
+static_assert(bar[1][0].a == 5);
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10695,6 +10695,11 @@
   if (MaybeElementDependentArrayFiller(ILE->getInit(I)))
 return true;
 }
+
+if (ILE->hasArrayFiller() &&
+MaybeElementDependentArrayFiller(ILE->getArrayFiller()))
+  return true;
+
 return false;
   }
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131154: FoldingRanges: Handle LineFoldingsOnly clients.

2022-08-04 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 449928.
usaxena95 added a comment.

Do same for multi-line comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131154

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -196,7 +196,7 @@
   ElementsAre(SourceAnnotations.range("empty")));
 }
 
-TEST(FoldingRanges, All) {
+TEST(FoldingRanges, ASTAll) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -265,7 +265,7 @@
   }
 }
 
-TEST(FoldingRangesPseudoParser, All) {
+TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -359,13 +359,52 @@
   };
   for (const char *Test : Tests) {
 auto T = Annotations(Test);
-EXPECT_THAT(
-gatherFoldingRanges(llvm::cantFail(getFoldingRanges(T.code().str(,
-UnorderedElementsAreArray(T.ranges()))
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/false))),
+UnorderedElementsAreArray(T.ranges()))
 << Test;
   }
 }
 
+TEST(FoldingRanges, PseudoParserLineFoldingsOnly) {
+  const char *Tests[] = {
+  R"cpp(
+void func(int a) {[[
+  if(a == 1) {[[
+a++;]]
+  } else {[[
+a--;
+  /*tokens inside foldings are fine.*/ ]]}
+]]}
+  )cpp",
+  R"cpp(
+void func(int a) {[[
+a++;]]
+} // A token on the end line.
+  )cpp",
+  R"cpp(
+[[/* comment 1
+* comment 1]]
+*/ int a_token = 0;
+  )cpp",
+
+  };
+  auto StripColumns = [](const std::vector &Ranges) {
+std::vector Res;
+for (Range R : Ranges) {
+  R.start.character = R.end.character = 0;
+  Res.push_back(R);
+}
+return Res;
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/true))),
+UnorderedElementsAreArray(StripColumns(T.ranges(
+<< Test;
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -33,7 +33,7 @@
 /// Returns a list of ranges whose contents might be collapsible in an editor.
 /// This version uses the pseudoparser which does not require the AST.
 llvm::Expected>
-getFoldingRanges(const std::string &Code);
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly);
 
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -179,7 +179,7 @@
 // statement bodies).
 // Related issue: https://github.com/clangd/clangd/issues/310
 llvm::Expected>
-getFoldingRanges(const std::string &Code) {
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly) {
   auto OrigStream = pseudo::lex(Code, clang::pseudo::genericLangOpts());
 
   auto DirectiveStructure = pseudo::DirectiveTree::parse(OrigStream);
@@ -192,15 +192,21 @@
   pseudo::pairBrackets(ParseableStream);
 
   std::vector Result;
-  auto ToFoldingRange = [](Position Start, Position End,
-   llvm::StringLiteral Kind) {
+  auto AddFoldingRange = [&](Position Start, Position End,
+ llvm::StringLiteral Kind) {
+if (Start.line >= End.line)
+  return;
 FoldingRange FR;
 FR.startLine = Start.line;
-FR.startCharacter = Start.character;
 FR.endLine = End.line;
-FR.endCharacter = End.character;
+if (LineFoldingsOnly)
+  FR.startCharacter = FR.endCharacter = 0;
+else {
+  FR.startCharacter = Start.character;
+  FR.endCharacter = End.character;
+}
 FR.kind = Kind.str();
-return FR;
+Result.push_back(FR);
   };
   auto OriginalToken = [&](const pseudo::Token &T) {
 return OrigStream.tokens()[T.OriginalIndex];
@@ -214,6 +220,17

[PATCH] D130894: [clang] Print more information about failed static assertions

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

In D130894#3698552 , @tbaeder wrote:

>> +1 to the suggestion to use quotes for a bit of visual distinction between 
>> the diagnostic message and the code embedded within it.
>
> One problem is that both the integer value `0` and the character constant 
> `'0'` are printed as `'0'` (same for all other single-digit numbers). gcc's 
> output doesn't have that problem because it prints chars as integers, but  I 
> don't really like that.

Agreed on not printing chars as integers, but would printing `''0''` in that 
case to make it more "clear" that it's a character constant? I think we'd want 
that for something like `static_assert('a' < 0, "what?")` so it's not printed 
as `'a < 0'`.


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

https://reviews.llvm.org/D130894

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


[PATCH] D131070: [clang][sema] Fix collectConjunctionTerms()

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 449930.

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

https://reviews.llvm.org/D131070

Files:
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3585,9 +3585,8 @@
 if (BinOp->getOpcode() == BO_LAnd) {
   collectConjunctionTerms(BinOp->getLHS(), Terms);
   collectConjunctionTerms(BinOp->getRHS(), Terms);
+  return;
 }
-
-return;
   }
 
   Terms.push_back(Clause);


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3585,9 +3585,8 @@
 if (BinOp->getOpcode() == BO_LAnd) {
   collectConjunctionTerms(BinOp->getLHS(), Terms);
   collectConjunctionTerms(BinOp->getRHS(), Terms);
+  return;
 }
-
-return;
   }
 
   Terms.push_back(Clause);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131154: FoldingRanges: Handle LineFoldingsOnly clients.

2022-08-04 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 449931.
usaxena95 added a comment.

More tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131154

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -196,7 +196,7 @@
   ElementsAre(SourceAnnotations.range("empty")));
 }
 
-TEST(FoldingRanges, All) {
+TEST(FoldingRanges, ASTAll) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -265,7 +265,7 @@
   }
 }
 
-TEST(FoldingRangesPseudoParser, All) {
+TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
   const char *Tests[] = {
   R"cpp(
 #define FOO int foo() {\
@@ -359,13 +359,55 @@
   };
   for (const char *Test : Tests) {
 auto T = Annotations(Test);
-EXPECT_THAT(
-gatherFoldingRanges(llvm::cantFail(getFoldingRanges(T.code().str(,
-UnorderedElementsAreArray(T.ranges()))
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/false))),
+UnorderedElementsAreArray(T.ranges()))
 << Test;
   }
 }
 
+TEST(FoldingRanges, PseudoParserLineFoldingsOnly) {
+  const char *Tests[] = {
+  R"cpp(
+void func(int a) {[[
+  if(a == 1) {[[
+a++;]]
+  } else {[[
+a--;
+  /*tokens inside foldings are fine.*/ ]]}
+]]}
+  )cpp",
+  R"cpp(
+void func(int a) {[[
+a++;]]
+} // A token on the end line.
+  )cpp",
+  R"cpp(
+[[/* comment 1
+* comment 1]]
+*/ int a_token = 0;
+
+/* No folding for this comment.
+*/ int b_token=0;
+  )cpp",
+
+  };
+  auto StripColumns = [](const std::vector &Ranges) {
+std::vector Res;
+for (Range R : Ranges) {
+  R.start.character = R.end.character = 0;
+  Res.push_back(R);
+}
+return Res;
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(
+T.code().str(), /*LineFoldingsOnly=*/true))),
+UnorderedElementsAreArray(StripColumns(T.ranges(
+<< Test;
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.h
===
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -33,7 +33,7 @@
 /// Returns a list of ranges whose contents might be collapsible in an editor.
 /// This version uses the pseudoparser which does not require the AST.
 llvm::Expected>
-getFoldingRanges(const std::string &Code);
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly);
 
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -179,7 +179,7 @@
 // statement bodies).
 // Related issue: https://github.com/clangd/clangd/issues/310
 llvm::Expected>
-getFoldingRanges(const std::string &Code) {
+getFoldingRanges(const std::string &Code, bool LineFoldingsOnly) {
   auto OrigStream = pseudo::lex(Code, clang::pseudo::genericLangOpts());
 
   auto DirectiveStructure = pseudo::DirectiveTree::parse(OrigStream);
@@ -192,15 +192,21 @@
   pseudo::pairBrackets(ParseableStream);
 
   std::vector Result;
-  auto ToFoldingRange = [](Position Start, Position End,
-   llvm::StringLiteral Kind) {
+  auto AddFoldingRange = [&](Position Start, Position End,
+ llvm::StringLiteral Kind) {
+if (Start.line >= End.line)
+  return;
 FoldingRange FR;
 FR.startLine = Start.line;
-FR.startCharacter = Start.character;
 FR.endLine = End.line;
-FR.endCharacter = End.character;
+if (LineFoldingsOnly)
+  FR.startCharacter = FR.endCharacter = 0;
+else {
+  FR.startCharacter = Start.character;
+  FR.endCharacter = End.character;
+}
 FR.kind = Kind.str();
-return FR;
+Result.push_back(FR);
   };
   auto OriginalToken = [&](const pseudo::Token &T) {
 return OrigSt

[PATCH] D130058: [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values

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

In D130058#3697949 , @smeenai wrote:

> Given that we have a non-obvious (at least to me) issue in a widely used 
> third-party library, would we consider giving users some way to opt out of 
> this error, at least as a transition tool?

Thank you for the feedback! I agree that providing information like which 
enumeration type the value is out of range for would be super helpful. 
(Changing the note order might be significantly more involved but I can see how 
it would be helpful here.)

Because the error is happening in boost, I think we have two paths forward: 1) 
targeted workaround for just boost, 2) downgrade the error to a 
warning-defaults-to-error. Because this is the second project to have run into 
some pain, I'm leaning towards downgrading the diagnostic for a release. One 
thing I would recommend is: add information to the release notes to set 
expectations about the warning being upgraded (if we downgrade it but don't 
tell users we're going to upgrade it to an error Real Soon Now, users will come 
to rely on the crutch).


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

https://reviews.llvm.org/D130058

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


[PATCH] D131007: [NFCI] Refactor how KeywordStatus is calculated

2022-08-04 Thread Muhammad Omair Javaid via Phabricator via cfe-commits
omjavaid added a comment.

This breaks clang causes it to crash in LLDB buildbot testsuite breaking the 
LLDB buildbot: https://lab.llvm.org/buildbot/#/builders/96/builds/27003


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131007

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


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

IMO it's clear enough...

  test.cpp:24:1: error: static assertion failed due to requirement 'c != c'
  static_assert(c != c);
  ^ ~~
  test.cpp:24:17: note: expression evaluates to 'a != a'
  static_assert(c != c);
~~^~~~
  test.cpp:25:1: error: static assertion failed due to requirement 'c < 'a''
  static_assert(c < 'a');
  ^ ~~~
  test.cpp:25:15: note: left-hand side of operator '<' evaluates to 'a'
  static_assert(c < 'a');
^
  2 errors generated.

Printing the first note as ''a' != 'a'' doesn't make it clearer. But for

  test.cpp:24:1: error: static assertion failed due to requirement 'c != c'
  static_assert(c != c);
  ^ ~~
  test.cpp:24:17: note: expression evaluates to '0 != 0'
  static_assert(c != c);
~~^~~~
  test.cpp:25:1: error: static assertion failed due to requirement 'c > 'a''
  static_assert(c > 'a');
  ^ ~~~
  test.cpp:25:15: note: left-hand side of operator '>' evaluates to '0'
  static_assert(c > 'a');
^

where `c` is a char variable, the output looks kind of weird. "0 != 0" looks 
like we're comparing two integers.

We might also go the g++ route and use `evaluates to ('0' != '0')` for the full 
expression, but that looks weird for just one side: `evaluates to (6)`. But we 
could also always print the full expression so we only have one case.


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

https://reviews.llvm.org/D130894

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


[PATCH] D131155: [clang] Expand array expressions if the filler expression's filler is element dependent

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 449932.

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

https://reviews.llvm.org/D131155

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-array-init.cpp


Index: clang/test/SemaCXX/constexpr-array-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+
+/// expected-no-diagnostics
+struct Foo {
+  int a;
+  constexpr Foo()
+  : a(get_int()) {
+  }
+
+  constexpr int get_int() const {
+return 5;
+  }
+};
+
+static constexpr Foo bar[2][1] = {
+{{}},
+};
+static_assert(bar[0][0].a == 5);
+static_assert(bar[1][0].a == 5);
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10695,6 +10695,11 @@
   if (MaybeElementDependentArrayFiller(ILE->getInit(I)))
 return true;
 }
+
+if (ILE->hasArrayFiller() &&
+MaybeElementDependentArrayFiller(ILE->getArrayFiller()))
+  return true;
+
 return false;
   }
   return true;


Index: clang/test/SemaCXX/constexpr-array-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+
+/// expected-no-diagnostics
+struct Foo {
+  int a;
+  constexpr Foo()
+  : a(get_int()) {
+  }
+
+  constexpr int get_int() const {
+return 5;
+  }
+};
+
+static constexpr Foo bar[2][1] = {
+{{}},
+};
+static_assert(bar[0][0].a == 5);
+static_assert(bar[1][0].a == 5);
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10695,6 +10695,11 @@
   if (MaybeElementDependentArrayFiller(ILE->getInit(I)))
 return true;
 }
+
+if (ILE->hasArrayFiller() &&
+MaybeElementDependentArrayFiller(ILE->getArrayFiller()))
+  return true;
+
 return false;
   }
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-04 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

personally I dont see huge value to print “ left-hand side of operator '==' 
evaluates to …”

I would like to see the full expression.

+1 to just copy gcc’s approach


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

https://reviews.llvm.org/D130894

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


[PATCH] D131156: [analyzer] Treat values passed as parameter as escaped

2022-08-04 Thread Thomas Weißschuh via Phabricator via cfe-commits
t-8ch created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
t-8ch requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131156

Files:
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/test/Analysis/dead-stores.cpp


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -217,3 +217,26 @@
   return i + j;
 }
 
+//===--===//
+// Dead store checking involving references.
+//===--===//
+
+void functionReferenceParameter(int &i) {
+  i = 5; // no warning
+}
+
+struct constructorReferenceParameter {
+  constructorReferenceParameter(int &i) {
+i = 5; // no warning
+  }
+};
+
+void referenceParameters() {
+  int i = 5;
+  functionReferenceParameter(i);
+  i = 6;
+
+  int j = 7;
+  constructorReferenceParameter k(j);
+  j = 8;
+}
Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -483,12 +483,21 @@
   void operator()(const Stmt *S) {
 // Check for '&'. Any VarDecl whose address has been taken we treat as
 // escaped.
-// FIXME: What about references?
 if (auto *LE = dyn_cast(S)) {
   findLambdaReferenceCaptures(LE);
   return;
 }
 
+if (auto *CE = dyn_cast(S)) {
+  findCallReferenceParameters(CE);
+  return;
+}
+
+if (auto *CE = dyn_cast(S)) {
+  findConstructorReferenceParameters(CE);
+  return;
+}
+
 const UnaryOperator *U = dyn_cast(S);
 if (!U)
   return;
@@ -522,6 +531,29 @@
 Escaped.insert(VD);
 }
   }
+
+  void findReferenceParameter(const FunctionDecl *FD, const Expr *const *Args) 
{
+unsigned numParams = FD->getNumParams();
+for (unsigned i = 0; i < numParams; ++i) {
+  if (FD->getParamDecl(i)->getType()->isReferenceType()) {
+if (auto *DRE = dyn_cast(Args[i])) {
+  if (auto *VD = dyn_cast(DRE->getDecl())) {
+Escaped.insert(VD);
+  }
+}
+  }
+}
+  }
+
+  void findCallReferenceParameters(const CallExpr *CE) {
+if (auto *FD = dyn_cast(CE->getCalleeDecl())) {
+  findReferenceParameter(FD, CE->getArgs());
+}
+  }
+
+  void findConstructorReferenceParameters(const CXXConstructExpr *CE) {
+findReferenceParameter(CE->getConstructor(), CE->getArgs());
+  }
 };
 } // end anonymous namespace
 


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -217,3 +217,26 @@
   return i + j;
 }
 
+//===--===//
+// Dead store checking involving references.
+//===--===//
+
+void functionReferenceParameter(int &i) {
+  i = 5; // no warning
+}
+
+struct constructorReferenceParameter {
+  constructorReferenceParameter(int &i) {
+i = 5; // no warning
+  }
+};
+
+void referenceParameters() {
+  int i = 5;
+  functionReferenceParameter(i);
+  i = 6;
+
+  int j = 7;
+  constructorReferenceParameter k(j);
+  j = 8;
+}
Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -483,12 +483,21 @@
   void operator()(const Stmt *S) {
 // Check for '&'. Any VarDecl whose address has been taken we treat as
 // escaped.
-// FIXME: What about references?
 if (auto *LE = dyn_cast(S)) {
   findLambdaReferenceCaptures(LE);
   return;
 }
 
+if (auto *CE = dyn_cast(S)) {
+  findCallReferenceParameters(CE);
+  return;
+}
+
+if (auto *CE = dyn_cast(S)) {
+  findConstructorReferenceParameters(CE);
+  return;
+}
+
 const UnaryOperator *U = dyn_cast(S);
 if (!U)
   return;
@@ -522,6 +531,29 @@
 Escaped.insert(VD);
 }
   }
+
+  void findReferenceParameter(const FunctionDecl *FD, const Expr *const *Args) {
+unsigned numParams = FD->getNumParams();
+for (unsigned i = 0; i < numParams; ++i) {
+  if (FD->getParamDecl(i)->getType()->isReferenceType()) {
+if (auto *DRE = dyn_cast(Args[i])) {
+  if (auto *VD = dyn_cast(DRE->get

[PATCH] D131007: [NFCI] Refactor how KeywordStatus is calculated

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

In D131007#3699142 , @omjavaid wrote:

> This breaks clang causes it to crash in LLDB buildbot testsuite breaking the 
> LLDB buildbot: https://lab.llvm.org/buildbot/#/builders/96/builds/27003

I believe this was already resolved by 
https://github.com/llvm/llvm-project/commit/bf6db18e52815475baebff2c330763fedac6b5e4
 -- the current failures seem unrelated to the previous one. e.g., 
https://lab.llvm.org/buildbot/#/builders/96/builds/27020


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131007

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


[PATCH] D131156: [analyzer] Treat values passed as parameter as escaped

2022-08-04 Thread Thomas Weißschuh via Phabricator via cfe-commits
t-8ch abandoned this revision.
t-8ch added a comment.

This is an accidental repost of #D131067


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131156

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


[PATCH] D131067: [analyzer] Treat values passed as parameter as escaped

2022-08-04 Thread Thomas Weißschuh via Phabricator via cfe-commits
t-8ch updated this revision to Diff 449934.
t-8ch added a comment.

Hoisted common code into common function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131067

Files:
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/test/Analysis/dead-stores.cpp


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -217,3 +217,26 @@
   return i + j;
 }
 
+//===--===//
+// Dead store checking involving references.
+//===--===//
+
+void functionReferenceParameter(int &i) {
+  i = 5; // no warning
+}
+
+struct constructorReferenceParameter {
+  constructorReferenceParameter(int &i) {
+i = 5; // no warning
+  }
+};
+
+void referenceParameters() {
+  int i = 5;
+  functionReferenceParameter(i);
+  i = 6;
+
+  int j = 7;
+  constructorReferenceParameter k(j);
+  j = 8;
+}
Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -483,12 +483,21 @@
   void operator()(const Stmt *S) {
 // Check for '&'. Any VarDecl whose address has been taken we treat as
 // escaped.
-// FIXME: What about references?
 if (auto *LE = dyn_cast(S)) {
   findLambdaReferenceCaptures(LE);
   return;
 }
 
+if (auto *CE = dyn_cast(S)) {
+  findCallReferenceParameters(CE);
+  return;
+}
+
+if (auto *CE = dyn_cast(S)) {
+  findConstructorReferenceParameters(CE);
+  return;
+}
+
 const UnaryOperator *U = dyn_cast(S);
 if (!U)
   return;
@@ -522,6 +531,29 @@
 Escaped.insert(VD);
 }
   }
+
+  void findReferenceParameter(const FunctionDecl *FD, const Expr *const *Args) 
{
+unsigned numParams = FD->getNumParams();
+for (unsigned i = 0; i < numParams; ++i) {
+  if (FD->getParamDecl(i)->getType()->isReferenceType()) {
+if (auto *DRE = dyn_cast(Args[i])) {
+  if (auto *VD = dyn_cast(DRE->getDecl())) {
+Escaped.insert(VD);
+  }
+}
+  }
+}
+  }
+
+  void findCallReferenceParameters(const CallExpr *CE) {
+if (auto *FD = dyn_cast(CE->getCalleeDecl())) {
+  findReferenceParameter(FD, CE->getArgs());
+}
+  }
+
+  void findConstructorReferenceParameters(const CXXConstructExpr *CE) {
+findReferenceParameter(CE->getConstructor(), CE->getArgs());
+  }
 };
 } // end anonymous namespace
 


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -217,3 +217,26 @@
   return i + j;
 }
 
+//===--===//
+// Dead store checking involving references.
+//===--===//
+
+void functionReferenceParameter(int &i) {
+  i = 5; // no warning
+}
+
+struct constructorReferenceParameter {
+  constructorReferenceParameter(int &i) {
+i = 5; // no warning
+  }
+};
+
+void referenceParameters() {
+  int i = 5;
+  functionReferenceParameter(i);
+  i = 6;
+
+  int j = 7;
+  constructorReferenceParameter k(j);
+  j = 8;
+}
Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -483,12 +483,21 @@
   void operator()(const Stmt *S) {
 // Check for '&'. Any VarDecl whose address has been taken we treat as
 // escaped.
-// FIXME: What about references?
 if (auto *LE = dyn_cast(S)) {
   findLambdaReferenceCaptures(LE);
   return;
 }
 
+if (auto *CE = dyn_cast(S)) {
+  findCallReferenceParameters(CE);
+  return;
+}
+
+if (auto *CE = dyn_cast(S)) {
+  findConstructorReferenceParameters(CE);
+  return;
+}
+
 const UnaryOperator *U = dyn_cast(S);
 if (!U)
   return;
@@ -522,6 +531,29 @@
 Escaped.insert(VD);
 }
   }
+
+  void findReferenceParameter(const FunctionDecl *FD, const Expr *const *Args) {
+unsigned numParams = FD->getNumParams();
+for (unsigned i = 0; i < numParams; ++i) {
+  if (FD->getParamDecl(i)->getType()->isReferenceType()) {
+if (auto *DRE = dyn_cast(Args[i])) {
+  if (auto *VD = dyn_cast(DRE->getDecl())) {
+Escaped.insert(VD);
+  }
+}
+  }
+}
+  }
+
+  void findCallReferenceParameters(const CallExpr *CE) {
+if (auto *FD = dyn_cast(CE->getCall

[PATCH] D131057: [Sema] -Wformat: support C23 format specifier %b %B

2022-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D131057#3697392 , @MaskRay wrote:

> ISTM adding the diagnostic (even if we do) is not so necessary in this patch.

I tend to agree. I think we'll want such a diagnostic at some point, and I 
think it's fine to deviate from the warning group GCC uses. We already have 
diagnostic grouping patterns for this sort of thing and we should use those 
consistently.

LGTM with some minor corrections to the release note. Thanks for this!




Comment at: clang/docs/ReleaseNotes.rst:67-68
   `Issue 50055: `_.
+- ``-Wformat`` now recognizes ``%b`` for printf/scanf family functions and
+  ``%B`` for printf family functions.
+  `Issue 56885: `_.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131057

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


[PATCH] D131067: [analyzer] Treat values passed as parameter as escaped

2022-08-04 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131067

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


[PATCH] D131070: [clang][sema] Fix collectConjunctionTerms()

2022-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Oh shoot, I saw that precommit CI made it past patch application failing (last 
time) and I thought the precommit CI bug was fixed and so it was testing the 
whole stack for once. Drat.

LGTM once we finish up with what this builds on.


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

https://reviews.llvm.org/D131070

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


[PATCH] D130553: [clang][lld][cmake] Simplify header dirs

2022-08-04 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

@tstellar There wasn't a configuration necessitating these changes.

The CMake config file currently distinguishes a main include dir and secondary 
include dir, which feels to me like it is leaking the implementation details of 
which headers are generated or not. I was hoping by replacing the instances 
where those are used with the list one, we'd eventually be able to deprecate 
the two underlying variables and just have the list one left.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130553

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


[PATCH] D130735: [Clang][LLD][cmake] Drop deprecated support for `llvm-config`-based build

2022-08-04 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 abandoned this revision.
Ericson2314 added a comment.

Abandoing based on @phosek's point in D128777 
 about it being nice to have it easy to 
revert them individually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130735

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


[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:345
+// FIXME: Support reference-type returns.
+assert(Val->getKind() != Value::Kind::Reference);
+

sgatev wrote:
> Let's do `if (Val->getKind() == Value::Kind::Reference) return;`. Otherwise 
> the framework will be unusable in practice.
Makes sense, will do.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:348
+auto *Loc = Env.getReturnStorageLocation();
+assert(Loc != nullptr);
+// FIXME: Model NRVO.

sgatev wrote:
> Let's do `if (Loc == nullptr) return;`
I don't think we want to do that, right? Shouldn't the `return` storage 
location always be set? Or is this about the "analyzing fragments rather than 
full functions" thing we discussed yesterday?



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:564
+  assert(ReturnLoc != nullptr);
+  Env.setStorageLocation(*S, *ReturnLoc);
+  Env.popCall(ExitEnv);

sgatev wrote:
> We use stable storage locations to ensure convergence. In that spirit, 
> shouldn't we assign `ReturnLoc`'s value to `S`'s storage location instead of 
> changing the storage location? Alternatively, we can pass `S`'s storage 
> location to `pushCall` so that it can store it as `ReturnLoc`.
Could you clarify how this hurts convergence? My understanding is that 
`ReturnLoc` here is already stable, so this would make `S`'s storage location 
stable too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

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


[PATCH] D131084: Add support for specifying the severity of a SARIF Result.

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

In D131084#3697678 , @cjdb wrote:

> It seems I got confused and conflated the two this morning.
>
> In D131084#3697525 , @vaibhav.y 
> wrote:
>
>>> Hmm, we can probably use "informational" for notes, warnings, and remarks, 
>>> but I'm kinda partial to proposing the latter two upstream.
>>
>> Interesting,  I agree that remarks could fit under "informational".
>>
>> As for notes: As I understand it they are always child diagnostics of 
>> warnings/errors, so seems it would be okay to associate these with the 
>> "fail" kind.
>
> I don't think classifying warnings as "fail" is right unless `-Werror` is 
> being used. For notes, I think there may be two options, if we don't want to 
> use informational:
>
> - inherit from the parent diagnostic
> - use notApplicable, since they don't have any influence on their own
>
>
>
> In D131084#3697308 , @denik wrote:
>
>> In D131084#3697256 , @cjdb wrote:
>>
>>> In D131084#3697211 , @vaibhav.y 
>>> wrote:
>>>
 Submitting for review:

 Some notes:

 There are a couple of ways I think we can acheive this, per the spec:

 1. The reportingDescriptor (rule) objects can be given a default 
 configuration property 
 ,
  which can set the default warning level and other data such as rule 
 parameters etc.
 2. The reportingDescriptor objects can omit the default configuration 
 (which then allows operating with warning as default), and the level is 
 then set when the result is reported.

 The first approach would be "more correct", what are your thoughts on 
 this? Would we benefit from having per-diagnostic configuration?

 There is also the question about the "kind" of results in clang. From my 
 reading of the spec 
 ,
  it seems that "fail" is the only case that applies to us because:

 - "pass": Implies no issue was found.
 - "open": This value is used by proof-based tools. It could also mean 
 additional assertions required
 - "informational": The specified rule was evaluated and produced a purely 
 informational result that does not indicate the presence of a problem
 - "notApplicable": The rule specified by ruleId was not evaluated, because 
 it does not apply to the analysis target.

 Of these "open" and "notApplicable" seem to be ones that *could* come to 
 use but I'm not sure where / what kind of diagnostics would use these. 
 Probably clang-tidy's `bugprone-*` suite?

 Let me know what you think is a good way to approach this wrt clang's 
 diagnostics system.
>>>
>>> Hmm, we can probably use "informational" for notes, warnings, and remarks, 
>>> but I'm kinda partial to proposing the latter two upstream.
>>
>> I think we can skip `kind` in the clang diagnostic. I found this:
>>
>>> If kind is absent, it SHALL default to "fail".
>>> If level has any value other than "none" and kind is present, then kind 
>>> SHALL have the value "fail".
>
> If skipping the kind defaults to fail, then we shouldn't skip it, because 
> getting a warning or remark doesn't necessarily mean that the build has 
> failed.

My suggestion is that we only need to worry about two kinds: `fail` for 
warnings and errors and `informational` for remarks. When the kind if `fail`, 
I'd expect we'd use the level `warning` or `error`.

Notes are interesting though. Sometimes they're extra information about the 
diagnostic on the given line, so I was kind of expecting they'd be specified 
via `attachments` in that case. But they can also sometimes be used to 
represent code flow (like in some CFG based warnings where we're showing where 
something was called from), and they can also sometimes be a related location 
(like "declared here" notes). Perhaps we may want to expose those to SARIF in 
different ways depending on the situation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131084

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


[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:348
+auto *Loc = Env.getReturnStorageLocation();
+assert(Loc != nullptr);
+// FIXME: Model NRVO.

samestep wrote:
> sgatev wrote:
> > Let's do `if (Loc == nullptr) return;`
> I don't think we want to do that, right? Shouldn't the `return` storage 
> location always be set? Or is this about the "analyzing fragments rather than 
> full functions" thing we discussed yesterday?
I think it's related. If we are going with always initializing the `return` 
storage location then I guess at some point we should be able to make 
`Environment::getReturnStorageLocation` return a reference? In that case I'm 
fine with keeping the assert around in the meantime.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:564
+  assert(ReturnLoc != nullptr);
+  Env.setStorageLocation(*S, *ReturnLoc);
+  Env.popCall(ExitEnv);

samestep wrote:
> sgatev wrote:
> > We use stable storage locations to ensure convergence. In that spirit, 
> > shouldn't we assign `ReturnLoc`'s value to `S`'s storage location instead 
> > of changing the storage location? Alternatively, we can pass `S`'s storage 
> > location to `pushCall` so that it can store it as `ReturnLoc`.
> Could you clarify how this hurts convergence? My understanding is that 
> `ReturnLoc` here is already stable, so this would make `S`'s storage location 
> stable too.
If I follow correctly, `ReturnLoc` here is the result of 
`Env.createStorageLocation(ReturnType)` which isn't stable. Each call to 
`createStorageLocation` returns a fresh storage location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

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


[PATCH] D131070: [clang][sema] Fix collectConjunctionTerms()

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

FWIW I switched it around so _this_ patch is now good as-is while 
https://reviews.llvm.org/D130894 now depends on this one.


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

https://reviews.llvm.org/D131070

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from some small corrections. Thank you for this! Do you need me to 
commit on your behalf? If so, what name and email address would you like me to 
use for patch attribution?




Comment at: clang/lib/Sema/SemaChecking.cpp:8719
 }
-
+if (auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+  return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,





Comment at: clang/lib/Sema/SemaChecking.cpp:8840
+  if (E->EvaluateAsRValue(Result, Context) && Result.Val.isLValue()) {
+auto *LVE = Result.Val.getLValueBase().dyn_cast();
+if (isa_and_nonnull(LVE))




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D131134: [X86] Report error if the amx enabled on the non-64-bits target

2022-08-04 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a subscriber: aaron.ballman.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM, but maybe wait one day or two for other FE folks' opinions. @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131134

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


[PATCH] D130894: [clang] Print more information about failed static assertions

2022-08-04 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 449942.

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

https://reviews.llvm.org/D130894

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p3.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
  clang/test/Lexer/cxx1z-trigraphs.cpp
  clang/test/PCH/cxx-templates.cpp
  clang/test/Parser/objc-static-assert.mm
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp
  clang/test/SemaCXX/static-assert-cxx17.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -184,7 +184,8 @@
 
 namespace Diags {
   struct A { int n, m; };
-  template struct X { static_assert(a.n == a.m); }; // expected-error {{static assertion failed due to requirement 'Diags::A{1, 2}.n == Diags::A{1, 2}.m'}}
+  template struct X { static_assert(a.n == a.m); }; // expected-error {{static assertion failed due to requirement 'Diags::A{1, 2}.n == Diags::A{1, 2}.m'}} \
+ // expected-note {{evaluates to '(1 == 2)'}}
   template struct X; // expected-note {{in instantiation of template class 'Diags::X<{1, 2}>' requested here}}
 }
 
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -68,8 +68,10 @@
   struct D : B, C {};
 
   static_assert(trait::specialization == 0);
-  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}}
-  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}}
+  static_assert(trait::specialization == 1); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '(0 == 1)'}}
+  static_assert(trait::specialization == 2); // FIXME expected-error {{failed}} \
+// expected-note {{evaluates to '(0 == 2)'}}
   static_assert(trait::specialization == 0); // FIXME-error {{ambiguous partial specialization}}
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,7 +31,8 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}}
+static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
+   // expected-note {{evaluates to '(1 == 0)'}}
   }
 }
 
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -22,7 +22,8 @@
 T<2> t2;
 
 template struct S {
-static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static assertion failed due to requirement 'sizeof(char) > sizeof(char)': Type not big enough!}}
+static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static assertion failed due to requirement 'sizeof(char) > sizeof(char)': Type not big enough!}} \
+ // expected-note {{1 > 1}}
 };
 
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
@@ -215,3 +216,40 @@
 static_assert(constexprNotBool, "message"); // expected-error {{value of type 'const NotBool' is not contextually convertible to 'bool'}}
 
 static_assert(1 , "") // expected-error {{expected ';' after 'static_assert'}}
+
+
+namespace Diagnostics {
+  /// No notes for literals.
+  static_assert(false, ""); // expected-error {{failed}}
+  static_assert(1.0 > 2.0, ""); // expected-error {{failed}}
+  static_assert('c' == 'd', ""); // expected-error {{failed}}
+  static_assert(1 == 2, ""); // expected-error {{failed}}
+
+  /// Simple things are ignored.
+  static_assert(1 == (-(1)), ""); //expected-error {{failed}}
+
+  /// Chars are printed as chars.
+  constexpr char getChar() {
+return 'c';
+  }

[PATCH] D131007: [NFCI] Refactor how KeywordStatus is calculated

2022-08-04 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D131007#3699162 , @aaron.ballman 
wrote:

> In D131007#3699142 , @omjavaid 
> wrote:
>
>> This breaks clang causes it to crash in LLDB buildbot testsuite breaking the 
>> LLDB buildbot: https://lab.llvm.org/buildbot/#/builders/96/builds/27003
>
> I believe this was already resolved by 
> https://github.com/llvm/llvm-project/commit/bf6db18e52815475baebff2c330763fedac6b5e4
>  -- the current failures seem unrelated to the previous one. e.g., 
> https://lab.llvm.org/buildbot/#/builders/96/builds/27020

Yep, this is the same break I fixed that @labath alerted me to just above this 
discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131007

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via Phabricator via cfe-commits
inclyc added a comment.

Thank you!  I already have the commit access, I can commit this myself ^_^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 449947.
inclyc added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -163,3 +163,48 @@
   t::func4("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
 }
 }
+#if __cplusplus >= 201103L
+namespace evaluated {
+
+constexpr const char *basic() { 
+  return 
+"%s %d"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *correct_fmt() { 
+  return 
+"%d %d";
+}
+
+constexpr const char *string_linebreak() { 
+  return 
+"%d %d"
+"%d %s"; // expected-note {{format string is defined here}}
+}
+
+/*non-constexpr*/ const char *not_literal() { 
+  return 
+"%d %d"
+"%d %s";
+}
+
+constexpr const char *inner_call() {
+  return "%d %s"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *wrap_constexpr() {
+  return inner_call();
+}
+
+
+void f() {
+  printf(basic(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(correct_fmt(), 1, 2);
+  printf(string_linebreak(), 1, 2, 3, 4); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(not_literal(), 1, 2, 3, 4); // expected-warning {{format string is not a string literal}}
+  printf(wrap_constexpr(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8473,6 +8473,9 @@
 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
 bool IgnoreStringsWithoutSpecifiers);
 
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E);
+
 // Determine if an expression is a string literal or constant string.
 // If this function returns false on the arguments to a function expecting a
 // format string, we will usually need to emit a warning.
@@ -8713,7 +8716,11 @@
 }
   }
 }
-
+if (const auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+  return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,
+   Type, CallType, /*InFunctionCall*/ false,
+   CheckedVarArgs, UncoveredArg, Offset,
+   IgnoreStringsWithoutSpecifiers);
 return SLCT_NotALiteral;
   }
   case Stmt::ObjCMessageExprClass: {
@@ -8823,6 +8830,20 @@
   }
 }
 
+// If this expression can be evaluated at compile-time,
+// check if the result is a StringLiteral and return it
+// otherwise return nullptr
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E) {
+  Expr::EvalResult Result;
+  if (E->EvaluateAsRValue(Result, Context) && Result.Val.isLValue()) {
+const auto *LVE = Result.Val.getLValueBase().dyn_cast();
+if (isa_and_nonnull(LVE))
+  return LVE;
+  }
+  return nullptr;
+}
+
 Sema::FormatStringType Sema::GetFormatStringType(const FormatAttr *Format) {
   return llvm::StringSwitch(Format->getType()->getName())
   .Case("scanf", FST_Scanf)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,6 +67,8 @@
   enum without a fixed underlying type is set to a value outside the range of
   the enumeration's values. Fixes
   `Issue 50055: `_.
+- Clang will now check compile-time determinable string literals as format strings.
+  This fixes `Issue 55805: `_.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f417583 - [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via cfe-commits

Author: YingChi Long
Date: 2022-08-04T21:07:30+08:00
New Revision: f417583f319bd60d1e32cdf9d0242e42f86101bf

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

LOG: [clang] format string checking for conpile-time evaluated str literal

This patch enhances clang's ability to check compile-time determinable
string literals as format strings, and can give FixIt hints at literals
(unlike gcc). Issue https://github.com/llvm/llvm-project/issues/55805
mentiond two compile-time string cases. And this patch partially fixes
one.

```
constexpr const char* foo() {
  return "%s %d";
}
int main() {
   printf(foo(), "abc", "def");
   return 0;
}
```

This patch enables clang check format string for this:

```
:4:24: warning: format specifies type 'int' but the argument has type 
'const char *' [-Wformat]
  printf(foo(), "abc", "def");
 ~ ^
:2:42: note: format string is defined here
constexpr const char *foo() { return "%s %d"; }
 ^~
 %s
1 warning generated.
```

Reviewed By: aaron.ballman

Signed-off-by: YingChi Long 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/format-strings.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 878effe08294c..85d360eb9cdac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -67,6 +67,8 @@ Improvements to Clang's diagnostics
   enum without a fixed underlying type is set to a value outside the range of
   the enumeration's values. Fixes
   `Issue 50055: `_.
+- Clang will now check compile-time determinable string literals as format 
strings.
+  This fixes `Issue 55805: 
`_.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 6b6031268b757..6428be13f0610 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8473,6 +8473,9 @@ static void CheckFormatString(
 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
 bool IgnoreStringsWithoutSpecifiers);
 
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E);
+
 // Determine if an expression is a string literal or constant string.
 // If this function returns false on the arguments to a function expecting a
 // format string, we will usually need to emit a warning.
@@ -8713,7 +8716,11 @@ checkFormatStringExpr(Sema &S, const Expr *E, 
ArrayRef Args,
 }
   }
 }
-
+if (const auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+  return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,
+   Type, CallType, /*InFunctionCall*/ false,
+   CheckedVarArgs, UncoveredArg, Offset,
+   IgnoreStringsWithoutSpecifiers);
 return SLCT_NotALiteral;
   }
   case Stmt::ObjCMessageExprClass: {
@@ -8823,6 +8830,20 @@ checkFormatStringExpr(Sema &S, const Expr *E, 
ArrayRef Args,
   }
 }
 
+// If this expression can be evaluated at compile-time,
+// check if the result is a StringLiteral and return it
+// otherwise return nullptr
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E) {
+  Expr::EvalResult Result;
+  if (E->EvaluateAsRValue(Result, Context) && Result.Val.isLValue()) {
+const auto *LVE = Result.Val.getLValueBase().dyn_cast();
+if (isa_and_nonnull(LVE))
+  return LVE;
+  }
+  return nullptr;
+}
+
 Sema::FormatStringType Sema::GetFormatStringType(const FormatAttr *Format) {
   return llvm::StringSwitch(Format->getType()->getName())
   .Case("scanf", FST_Scanf)

diff  --git a/clang/test/SemaCXX/format-strings.cpp 
b/clang/test/SemaCXX/format-strings.cpp
index a0dcf01910bb7..2378eea9b3c07 100644
--- a/clang/test/SemaCXX/format-strings.cpp
+++ b/clang/test/SemaCXX/format-strings.cpp
@@ -163,3 +163,48 @@ void f() {
   t::func4("Hello %s"); // expected-warning {{more '%' conversions than data 
arguments}}
 }
 }
+#if __cplusplus >= 201103L
+namespace evaluated {
+
+constexpr const char *basic() { 
+  return 
+"%s %d"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *correct_fmt() { 
+  return 
+"%d %d";
+}
+
+constexpr const char *string_linebreak() { 
+  return 
+"%d %d"
+"%d %s"; // expected-note {{format stri

[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf417583f319b: [clang] format string checking for 
conpile-time evaluated str literal (authored by inclyc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -163,3 +163,48 @@
   t::func4("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
 }
 }
+#if __cplusplus >= 201103L
+namespace evaluated {
+
+constexpr const char *basic() { 
+  return 
+"%s %d"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *correct_fmt() { 
+  return 
+"%d %d";
+}
+
+constexpr const char *string_linebreak() { 
+  return 
+"%d %d"
+"%d %s"; // expected-note {{format string is defined here}}
+}
+
+/*non-constexpr*/ const char *not_literal() { 
+  return 
+"%d %d"
+"%d %s";
+}
+
+constexpr const char *inner_call() {
+  return "%d %s"; // expected-note {{format string is defined here}}
+}
+
+constexpr const char *wrap_constexpr() {
+  return inner_call();
+}
+
+
+void f() {
+  printf(basic(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(correct_fmt(), 1, 2);
+  printf(string_linebreak(), 1, 2, 3, 4); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+  printf(not_literal(), 1, 2, 3, 4); // expected-warning {{format string is not a string literal}}
+  printf(wrap_constexpr(), 1, 2); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
+}
+
+
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8473,6 +8473,9 @@
 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
 bool IgnoreStringsWithoutSpecifiers);
 
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E);
+
 // Determine if an expression is a string literal or constant string.
 // If this function returns false on the arguments to a function expecting a
 // format string, we will usually need to emit a warning.
@@ -8713,7 +8716,11 @@
 }
   }
 }
-
+if (const auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+  return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,
+   Type, CallType, /*InFunctionCall*/ false,
+   CheckedVarArgs, UncoveredArg, Offset,
+   IgnoreStringsWithoutSpecifiers);
 return SLCT_NotALiteral;
   }
   case Stmt::ObjCMessageExprClass: {
@@ -8823,6 +8830,20 @@
   }
 }
 
+// If this expression can be evaluated at compile-time,
+// check if the result is a StringLiteral and return it
+// otherwise return nullptr
+static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
+   const Expr *E) {
+  Expr::EvalResult Result;
+  if (E->EvaluateAsRValue(Result, Context) && Result.Val.isLValue()) {
+const auto *LVE = Result.Val.getLValueBase().dyn_cast();
+if (isa_and_nonnull(LVE))
+  return LVE;
+  }
+  return nullptr;
+}
+
 Sema::FormatStringType Sema::GetFormatStringType(const FormatAttr *Format) {
   return llvm::StringSwitch(Format->getType()->getName())
   .Case("scanf", FST_Scanf)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,6 +67,8 @@
   enum without a fixed underlying type is set to a value outside the range of
   the enumeration's values. Fixes
   `Issue 50055: `_.
+- Clang will now check compile-time determinable string literals as format strings.
+  This fixes `Issue 55805: `_.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

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

In D130906#3699323 , @inclyc wrote:

> Thank you!  I already have the commit access, I can commit this myself ^_^

Excellent! Feel free to land when you're ready. :-)




Comment at: clang/lib/Sema/SemaChecking.cpp:8719
 }
-
+if (auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+  return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,

aaron.ballman wrote:
> 
This one should still be `const Expr *` -- we only use `auto` when the type is 
spelled out explicitly in the initialization.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D131062: [docs] Add "C++20 Modules"

2022-08-04 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

Aside from a couple typos, I was wondering if it would be welcome to do a pass 
w.r.t stylistic improvements (e.g. "Modules have a lot of meanings." --> "The 
term 'modules' has a lot of meanings"). I don't want to be too nit-picky - the 
sentences are all understandable, but sometimes slightly unusual to a native 
speaker in their formulation.


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

https://reviews.llvm.org/D131062

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via Phabricator via cfe-commits
inclyc added a comment.

In D130906#3699335 , @aaron.ballman 
wrote:

> In D130906#3699323 , @inclyc wrote:
>
>> Thank you!  I already have the commit access, I can commit this myself ^_^
>
> Excellent! Feel free to land when you're ready. :-)

Sorry I haven't noticed this yet, should I revert changes and commit again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D131134: [X86] Report error if the amx enabled on the non-64-bits target

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

I think the precommit CI failures might be relevant here -- can you 
double-check those?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131134

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

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

In D130906#3699342 , @inclyc wrote:

> In D130906#3699335 , @aaron.ballman 
> wrote:
>
>> In D130906#3699323 , @inclyc wrote:
>>
>>> Thank you!  I already have the commit access, I can commit this myself ^_^
>>
>> Excellent! Feel free to land when you're ready. :-)
>
> Sorry I haven't noticed this yet, should I revert changes and commit again?

No worries! And no need to revert; you can land an NFC change that switches the 
`auto` to `Expr` (no need for a review).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[clang] 282d475 - [clang] change `auto` to `Expr` in last commit [NFC]

2022-08-04 Thread YingChi Long via cfe-commits

Author: YingChi Long
Date: 2022-08-04T21:15:45+08:00
New Revision: 282d4755c37ced7c2b36526d79033c5c76a006a8

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

LOG: [clang] change `auto` to `Expr` in last commit [NFC]

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 6428be13f061..d71114e33f31 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8716,7 +8716,7 @@ checkFormatStringExpr(Sema &S, const Expr *E, 
ArrayRef Args,
 }
   }
 }
-if (const auto *SLE = maybeConstEvalStringLiteral(S.Context, E))
+if (const Expr *SLE = maybeConstEvalStringLiteral(S.Context, E))
   return checkFormatStringExpr(S, SLE, Args, APK, format_idx, firstDataArg,
Type, CallType, /*InFunctionCall*/ false,
CheckedVarArgs, UncoveredArg, Offset,



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


[PATCH] D131155: [clang] Expand array expressions if the filler expression's filler is element dependent

2022-08-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Your logic makes sense to me and these changes look correct; good catch! Please 
be sure to add a release note when landing. Thanks for the fix!


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

https://reviews.llvm.org/D131155

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

2022-08-04 Thread YingChi Long via Phabricator via cfe-commits
inclyc added a comment.

Last question, issue https://github.com/llvm/llvm-project/issues/55805 
mentioned another case, some `initListExpr` evaulated as 
"StringLiteral"(`Array` in fact, but maybe able to consider as a literal), 
should we implement this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:348
+auto *Loc = Env.getReturnStorageLocation();
+assert(Loc != nullptr);
+// FIXME: Model NRVO.

sgatev wrote:
> samestep wrote:
> > sgatev wrote:
> > > Let's do `if (Loc == nullptr) return;`
> > I don't think we want to do that, right? Shouldn't the `return` storage 
> > location always be set? Or is this about the "analyzing fragments rather 
> > than full functions" thing we discussed yesterday?
> I think it's related. If we are going with always initializing the `return` 
> storage location then I guess at some point we should be able to make 
> `Environment::getReturnStorageLocation` return a reference? In that case I'm 
> fine with keeping the assert around in the meantime.
OK; yeah, I think the intention is that we're always initializing it. I'll 
leave this code as is for now, then.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:564
+  assert(ReturnLoc != nullptr);
+  Env.setStorageLocation(*S, *ReturnLoc);
+  Env.popCall(ExitEnv);

sgatev wrote:
> samestep wrote:
> > sgatev wrote:
> > > We use stable storage locations to ensure convergence. In that spirit, 
> > > shouldn't we assign `ReturnLoc`'s value to `S`'s storage location instead 
> > > of changing the storage location? Alternatively, we can pass `S`'s 
> > > storage location to `pushCall` so that it can store it as `ReturnLoc`.
> > Could you clarify how this hurts convergence? My understanding is that 
> > `ReturnLoc` here is already stable, so this would make `S`'s storage 
> > location stable too.
> If I follow correctly, `ReturnLoc` here is the result of 
> `Env.createStorageLocation(ReturnType)` which isn't stable. Each call to 
> `createStorageLocation` returns a fresh storage location.
Ah I see, you're right. Is there a way to make a stable storage location for 
the `return`? My intuition is that we can't just pass `S`'s storage location to 
`pushCall`, because we want the storage location for the `return` to be the 
same across analysis of different callsites to the callee (similar to how we 
currently use the same storage location for a given parameter of the callee, 
regardless of how many times we analyze it). But maybe it would be fine; 
@ymandel do you have any thoughts on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

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


[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

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

In D130906#3699361 , @inclyc wrote:

> Last question, issue https://github.com/llvm/llvm-project/issues/55805 
> mentioned another case, some `initListExpr` evaulated as 
> "StringLiteral"(`Array` in fact, but maybe able to consider as a literal), 
> should we implement this?

Yes, I think we should. The following are functionally equivalent:

  static constexpr const char *str1 = "%s";
  static constexpr const char str2[] = { '%', 's', 0 };


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130906

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


[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 449958.
samestep added a comment.

Don't assert returns to not be references


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4121,4 +4121,112 @@
/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
 }
 
+TEST(TransferTest, ContextSensitiveReturnVoid) {
+  std::string Code = R"(
+void Noop() { return; }
+
+void target() {
+  Noop();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+// This just tests that the analysis doesn't crash.
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnTrue) {
+  std::string Code = R"(
+bool GiveBool() { return true; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnFalse) {
+  std::string Code = R"(
+bool GiveBool() { return false; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnArg) {
+  std::string Code = R"(
+bool GiveBool();
+bool GiveBack(bool Arg) { return Arg; }
+
+void target() {
+  bool Foo = GiveBool();
+  bool Bar = GiveBack(Foo);
+  bool Baz = Foo == Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+auto &BazVal =
+*cast(Env.getValue(*BazDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(BazVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -332,6 +332,25 @@
   std::make_unique(*ThisPointeeLoc)));
   }
 
+  void VisitReturnStmt(const ReturnStmt *S) {
+auto *Ret = S->getRetValue();
+if (Ret == nullptr)
+  return;
+
+auto *Val = Env.getValue(*Ret, SkipPast::None);
+if (Val == nullptr)
+  return;
+
+// FIXME: Support r

[PATCH] D130268: [NFC] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-08-04 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 updated this revision to Diff 449963.
yurai007 edited the summary of this revision.
yurai007 added a comment.

Rebase and fix last comment. Remove dependency to 
https://reviews.llvm.org/D129781 by moving relevant part of change here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

Files:
  llvm/include/llvm/ADT/SmallVector.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/unittests/ADT/SmallVectorTest.cpp

Index: llvm/unittests/ADT/SmallVectorTest.cpp
===
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -202,6 +202,11 @@
   }
 }
 
+template 
+static unsigned NumBuiltinElts(const SmallVector &) {
+  return N;
+}
+
 class SmallVectorTestBase : public testing::Test {
 protected:
   void SetUp() override { Constructable::reset(); }
@@ -241,6 +246,17 @@
   assertValuesInOrder(V, 3u, 1, 2, 3);
 }
 
+// Constructor test.
+TYPED_TEST(SmallVectorTest, ConstructorFromArrayRefSimpleTest) {
+  SCOPED_TRACE("ConstructorFromArrayRefSimpleTest");
+  ArrayRef Array = {Constructable(1), Constructable(2),
+   Constructable(3)};
+  auto &V = this->theVector;
+  V = SmallVector(Array);
+  assertValuesInOrder(V, 3u, 1, 2, 3);
+  ASSERT_EQ(NumBuiltinElts(TypeParam{}), NumBuiltinElts(V));
+}
+
 // New vector test.
 TYPED_TEST(SmallVectorTest, EmptyVectorTest) {
   SCOPED_TRACE("EmptyVectorTest");
@@ -862,9 +878,6 @@
 protected:
   VectorT1 theVector;
   VectorT2 otherVector;
-
-  template 
-  static unsigned NumBuiltinElts(const SmallVector&) { return N; }
 };
 
 typedef ::testing::Types<
@@ -904,7 +917,7 @@
 
   // If the source vector (otherVector) was in small-mode, assert that we just
   // moved the data pointer over.
-  EXPECT_TRUE(this->NumBuiltinElts(U) == 4 || V.data() == OrigDataPtr);
+  EXPECT_TRUE(NumBuiltinElts(U) == 4 || V.data() == OrigDataPtr);
 
   // There shouldn't be any live objects any more.
   V.clear();
@@ -1128,6 +1141,44 @@
   EXPECT_TRUE(makeArrayRef(V2).equals({4, 5, 3, 2}));
 }
 
+struct To {
+  int Content;
+  friend bool operator==(const To &LHS, const To &RHS) {
+return LHS.Content == RHS.Content;
+  }
+};
+
+class From {
+public:
+  From() = default;
+  From(To M) { T = M; }
+  operator To() const { return T; }
+
+private:
+  To T;
+};
+
+TEST(SmallVectorTest, ConstructFromArrayRefOfConvertibleType) {
+  To to1{1}, to2{2}, to3{3};
+  std::vector StdVector = {From(to1), From(to2), From(to3)};
+  ArrayRef Array = StdVector;
+  {
+llvm::SmallVector Vector(Array);
+
+ASSERT_EQ(Array.size(), Vector.size());
+for (size_t I = 0; I < Array.size(); ++I)
+  EXPECT_EQ(Array[I], Vector[I]);
+  }
+  {
+llvm::SmallVector Vector(Array);
+
+ASSERT_EQ(Array.size(), Vector.size());
+ASSERT_EQ(4u, NumBuiltinElts(Vector));
+for (size_t I = 0; I < Array.size(); ++I)
+  EXPECT_EQ(Array[I], Vector[I]);
+  }
+}
+
 template 
 class SmallVectorReferenceInvalidationTest : public SmallVectorTestBase {
 protected:
@@ -1137,11 +1188,6 @@
 
   VectorT V;
 
-  template 
-  static unsigned NumBuiltinElts(const SmallVector &) {
-return N;
-  }
-
   template  static bool isValueType() {
 return std::is_same::value;
   }
@@ -1167,7 +1213,7 @@
 TYPED_TEST(SmallVectorReferenceInvalidationTest, PushBack) {
   // Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
   auto &V = this->V;
-  int N = this->NumBuiltinElts(V);
+  int N = NumBuiltinElts(V);
 
   // Push back a reference to last element when growing from small storage.
   V.push_back(V.back());
@@ -1189,7 +1235,7 @@
 TYPED_TEST(SmallVectorReferenceInvalidationTest, PushBackMoved) {
   // Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
   auto &V = this->V;
-  int N = this->NumBuiltinElts(V);
+  int N = NumBuiltinElts(V);
 
   // Push back a reference to last element when growing from small storage.
   V.push_back(std::move(V.back()));
@@ -1218,7 +1264,7 @@
 TYPED_TEST(SmallVectorReferenceInvalidationTest, Resize) {
   auto &V = this->V;
   (void)V;
-  int N = this->NumBuiltinElts(V);
+  int N = NumBuiltinElts(V);
   V.resize(N + 1, V.back());
   EXPECT_EQ(N, V.back());
 
@@ -1233,7 +1279,7 @@
   auto &V = this->V;
   (void)V;
   V.append(1, V.back());
-  int N = this->NumBuiltinElts(V);
+  int N = NumBuiltinElts(V);
   EXPECT_EQ(N, V[N - 1]);
 
   // Append enough mor

[PATCH] D130984: [clang][AArch64][SVE] Add unary +/- operators for SVE types

2022-08-04 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes accepted this revision.
c-rhodes added a comment.
This revision is now accepted and ready to land.

LGTM, just one minor comment




Comment at: clang/test/CodeGen/aarch64-sve-vector-arith-ops.c:1654
+
+// UNARY PROMOTION
+

should we add FP tests as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130984

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


[PATCH] D130268: [NFC] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-08-04 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.

Still LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130268: [NFC] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-08-04 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Looks like a nice improvement, thanks!




Comment at: llvm/unittests/ADT/SmallVectorTest.cpp:867
-  template 
-  static unsigned NumBuiltinElts(const SmallVector&) { return N; }
 };

This seems like an unrelated change unless I am missing something? If so, this 
could likely be pulled out and just submitted separately as NFC


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 449975.
samestep added a comment.

Use CallExpr location for ReturnLoc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4121,4 +4121,112 @@
/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
 }
 
+TEST(TransferTest, ContextSensitiveReturnVoid) {
+  std::string Code = R"(
+void Noop() { return; }
+
+void target() {
+  Noop();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+// This just tests that the analysis doesn't crash.
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnTrue) {
+  std::string Code = R"(
+bool GiveBool() { return true; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnFalse) {
+  std::string Code = R"(
+bool GiveBool() { return false; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnArg) {
+  std::string Code = R"(
+bool GiveBool();
+bool GiveBack(bool Arg) { return Arg; }
+
+void target() {
+  bool Foo = GiveBool();
+  bool Bar = GiveBack(Foo);
+  bool Baz = Foo == Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+auto &BazVal =
+*cast(Env.getValue(*BazDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(BazVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -332,6 +332,25 @@
   std::make_unique(*ThisPointeeLoc)));
   }
 
+  void VisitReturnStmt(const ReturnStmt *S) {
+auto *Ret = S->getRetValue();
+if (Ret == nullptr)
+  return;
+
+auto *Val = Env.getValue(*Ret, SkipPast::None);
+if (Val == nullptr)
+  return;
+
+// FIXME: Support referen

[PATCH] D130600: [clang][dataflow] Handle return statements

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 449976.
samestep added a comment.

Revert an unnecessary little change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130600

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4121,4 +4121,112 @@
/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
 }
 
+TEST(TransferTest, ContextSensitiveReturnVoid) {
+  std::string Code = R"(
+void Noop() { return; }
+
+void target() {
+  Noop();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+// This just tests that the analysis doesn't crash.
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnTrue) {
+  std::string Code = R"(
+bool GiveBool() { return true; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnFalse) {
+  std::string Code = R"(
+bool GiveBool() { return false; }
+
+void target() {
+  bool Foo = GiveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveReturnArg) {
+  std::string Code = R"(
+bool GiveBool();
+bool GiveBack(bool Arg) { return Arg; }
+
+void target() {
+  bool Foo = GiveBool();
+  bool Bar = GiveBack(Foo);
+  bool Baz = Foo == Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ASSERT_THAT(BazDecl, NotNull());
+
+auto &BazVal =
+*cast(Env.getValue(*BazDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(BazVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -332,6 +332,25 @@
   std::make_unique(*ThisPointeeLoc)));
   }
 
+  void VisitReturnStmt(const ReturnStmt *S) {
+auto *Ret = S->getRetValue();
+if (Ret == nullptr)
+  return;
+
+auto *Val = Env.getValue(*Ret, SkipPast::None);
+if (Val == nullptr)
+  return;
+
+// FIXME: Support referen

[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
samestep requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131170

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4229,4 +4229,143 @@
/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
 }
 
+TEST(TransferTest, ContextSensitiveMethodLiteral) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool giveBool() { return true; }
+};
+
+void target() {
+  MyClass MyObj;
+  bool Foo = MyObj.giveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodGetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool getField() { return Field; }
+
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.Field = true;
+  bool Foo = MyObj.getField();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodSetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool setField(bool Val) { Field = Val; }
+
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.setField(true);
+  bool Foo = MyObj.Field;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodGetterAndSetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool getField() { return Field; }
+  bool setField(bool Val) { Field = Val; }
+
+private:
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.setField(true);
+  bool Foo = MyObj.getField();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flo

[PATCH] D131155: [clang] Expand array expressions if the filler expression's filler is element dependent

2022-08-04 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

This seems reasonable to me as well.


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

https://reviews.llvm.org/D131155

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


[PATCH] D131172: [clang][llvm][doc] Add more information for the ABI change in FP16

2022-08-04 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: kparzysz, thieta, abdulras, tstellar.
Herald added a project: All.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131172

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -186,9 +186,25 @@
 Changes to the X86 Backend
 --
 
-* Support ``half`` type on SSE2 and above targets.
+* Support ``half`` type on SSE2 and above targets following X86 psABI.
 * Support ``rdpru`` instruction on Zen2 and above targets.
 
+During this release, ``half`` type has an ABI breaking change to provide the
+support for the ABI of ``_Float16`` type on SSE2 and above following X86 psABI.
+(`D107082 `_)
+
+The change may affect the current use of ``half`` includes (but is not limited
+to):
+
+* Frontends generating ``half`` type in function passing and/or returning
+arguments.
+* Downstream runtimes providing any ``half`` conversion builtins assuming the
+old ABI.
+* Projects built with LLVM 15.0 but using early versions of compiler-rt.
+
+When you find failures with ``half`` type, check the calling conversion of the
+code and switch it to the new ABI.
+
 Changes to the OCaml bindings
 -
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -619,6 +619,19 @@
   will be used by Linux kernel mitigations for RETBLEED. The corresponding flag
   ``-mfunction-return=keep`` may be appended to disable the feature.
 
+The ``_Float16`` type requires SSE2 feature and above due to the instruction
+limitations. When using it on i386 targets, you need to specify ``-msse2``
+explicitly.
+
+For targets without F16C feature or above, please make sure:
+
+- Use GCC 12.0 and above if you are using libgcc.
+- If you are using compiler-rt, use the same version with the compiler.
+Early versions provided FP16 builtins in a different ABI. A workaround is to 
use
+a small code snippet to check the ABI if you cannot make sure of it.
+- If you are using downstream runtimes that provide FP16 conversions, update
+them with the new ABI.
+
 DWARF Support in Clang
 --
 


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -186,9 +186,25 @@
 Changes to the X86 Backend
 --
 
-* Support ``half`` type on SSE2 and above targets.
+* Support ``half`` type on SSE2 and above targets following X86 psABI.
 * Support ``rdpru`` instruction on Zen2 and above targets.
 
+During this release, ``half`` type has an ABI breaking change to provide the
+support for the ABI of ``_Float16`` type on SSE2 and above following X86 psABI.
+(`D107082 `_)
+
+The change may affect the current use of ``half`` includes (but is not limited
+to):
+
+* Frontends generating ``half`` type in function passing and/or returning
+arguments.
+* Downstream runtimes providing any ``half`` conversion builtins assuming the
+old ABI.
+* Projects built with LLVM 15.0 but using early versions of compiler-rt.
+
+When you find failures with ``half`` type, check the calling conversion of the
+code and switch it to the new ABI.
+
 Changes to the OCaml bindings
 -
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -619,6 +619,19 @@
   will be used by Linux kernel mitigations for RETBLEED. The corresponding flag
   ``-mfunction-return=keep`` may be appended to disable the feature.
 
+The ``_Float16`` type requires SSE2 feature and above due to the instruction
+limitations. When using it on i386 targets, you need to specify ``-msse2``
+explicitly.
+
+For targets without F16C feature or above, please make sure:
+
+- Use GCC 12.0 and above if you are using libgcc.
+- If you are using compiler-rt, use the same version with the compiler.
+Early versions provided FP16 builtins in a different ABI. A workaround is to use
+a small code snippet to check the ABI if you cannot make sure of it.
+- If you are using downstream runtimes that provide FP16 conversions, update
+them with the new ABI.
+
 DWARF Support in Clang
 --
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131172: [clang][llvm][doc] Add more information for the ABI change in FP16

2022-08-04 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

This is for LLVM 15.0 release per to #56854.

Forgive me my bad English. Suggestions are welcome.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131172

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


[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:383
   StorageLocation *ReturnLoc = nullptr;
-  // FIXME: Move `ThisPointeeLoc` here from `DataflowAnalysisContext`.
+  StorageLocation *ThisPointeeLoc = nullptr;
 

Let's add a brief comment explaining what this is and when it is expected to be 
non-null.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:217
+const Expr *Arg = MethodCall->getImplicitObjectArgument();
+Env.ThisPointeeLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
+  }

What if `Arg` is null?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131170

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


[PATCH] D131172: [clang][llvm][doc] Add more information for the ABI change in FP16

2022-08-04 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131172

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


[PATCH] D130268: [NFC] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-08-04 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 marked an inline comment as done.
yurai007 added inline comments.



Comment at: llvm/unittests/ADT/SmallVectorTest.cpp:867
-  template 
-  static unsigned NumBuiltinElts(const SmallVector&) { return N; }
 };

fhahn wrote:
> This seems like an unrelated change unless I am missing something? If so, 
> this could likely be pulled out and just submitted separately as NFC
Addressed here: https://reviews.llvm.org/D131173


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:383
   StorageLocation *ReturnLoc = nullptr;
-  // FIXME: Move `ThisPointeeLoc` here from `DataflowAnalysisContext`.
+  StorageLocation *ThisPointeeLoc = nullptr;
 

sgatev wrote:
> Let's add a brief comment explaining what this is and when it is expected to 
> be non-null.
Will do, thanks.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:217
+const Expr *Arg = MethodCall->getImplicitObjectArgument();
+Env.ThisPointeeLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
+  }

sgatev wrote:
> What if `Arg` is null?
Good point, thanks; under what circumstances can that happen? In any case, I'm 
adding a guard for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131170

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


[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 449986.
samestep added a comment.

Address Stanislav's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131170

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4229,4 +4229,143 @@
/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
 }
 
+TEST(TransferTest, ContextSensitiveMethodLiteral) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool giveBool() { return true; }
+};
+
+void target() {
+  MyClass MyObj;
+  bool Foo = MyObj.giveBool();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodGetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool getField() { return Field; }
+
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.Field = true;
+  bool Foo = MyObj.getField();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodSetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool setField(bool Val) { Field = Val; }
+
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.setField(true);
+  bool Foo = MyObj.Field;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodGetterAndSetter) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool getField() { return Field; }
+  bool setField(bool Val) { Field = Val; }
+
+private:
+  bool Field;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.setField(true);
+  bool Foo = MyObj.getField();
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTran

[clang] 54d24ea - [clang][dataflow][NFC] Fix outdated comment on getStableStorageLocation

2022-08-04 Thread Eric Li via cfe-commits

Author: Eric Li
Date: 2022-08-04T11:15:14-04:00
New Revision: 54d24eae98726e37867bc3a683cd58af6ec128df

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

LOG: [clang][dataflow][NFC] Fix outdated comment on getStableStorageLocation

Follow-up to D129097.

It is no longer a requirement that the `QualType` passed to to
`DataflowAnalysisContext::getStableStorageLocation()` is not null. A
null type pass as an argument is only applicable as the pointee type
of a `std::nullptr_t` pointer.

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index a31e08fd16c48..ab60d313f242c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -93,9 +93,7 @@ class DataflowAnalysisContext {
 
   /// Returns a new storage location appropriate for `Type`.
   ///
-  /// Requirements:
-  ///
-  ///  `Type` must not be null.
+  /// A null `Type` is interpreted as the pointee type of `std::nullptr_t`.
   StorageLocation &createStorageLocation(QualType Type);
 
   /// Returns a stable storage location for `D`.



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


[PATCH] D131109: [clang][dataflow][NFC] Fix outdated comment on getStableStorageLocation

2022-08-04 Thread Eric Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54d24eae9872: [clang][dataflow][NFC] Fix outdated comment on 
getStableStorageLocation (authored by li.zhe.hua).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131109

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h


Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -93,9 +93,7 @@
 
   /// Returns a new storage location appropriate for `Type`.
   ///
-  /// Requirements:
-  ///
-  ///  `Type` must not be null.
+  /// A null `Type` is interpreted as the pointee type of `std::nullptr_t`.
   StorageLocation &createStorageLocation(QualType Type);
 
   /// Returns a stable storage location for `D`.


Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -93,9 +93,7 @@
 
   /// Returns a new storage location appropriate for `Type`.
   ///
-  /// Requirements:
-  ///
-  ///  `Type` must not be null.
+  /// A null `Type` is interpreted as the pointee type of `std::nullptr_t`.
   StorageLocation &createStorageLocation(QualType Type);
 
   /// Returns a stable storage location for `D`.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131134: [X86] Report error if the amx enabled on the non-64-bits target

2022-08-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

How does this interact with `-march=native -m32`. Won't that pick up the amx 
flag from CPUID?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131134

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


[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449994.
ellis added a comment.

Fix case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2895,46 +2895,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.
   if (ProfileList.isEmpty())
-return false;
+return ProfileList::Allow;
   CodeGenOptions::ProfileInstrKind Kind = getCodeGenOpts().getProfileIn

[PATCH] D130807: [InstrProf] Add the skipprofile attribute

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449995.
ellis added a comment.

Rebase and update docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() skipprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the skipprofile attribute disables profiling.
+define dso_local i32 @skip_instr(i32 %a) skipprofile {
+; CHECK-LABEL: @skip_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[SKIPPROFILE:#[0-9]+]]
+define void @f88() skipprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::SkipProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1574,6 +1574,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -698,6 +698,8 @@
 return bitc::ATTR_KIND_NOCF_CHECK;
   case Attribute::NoProfile:
 return bitc::ATTR_KIND_NO_PROFILE;
+  case Attribute::SkipProfile:
+return bitc::ATTR_KIND_SKIP_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NoSanitizeBounds:
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeRea

[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:217
+const Expr *Arg = MethodCall->getImplicitObjectArgument();
+Env.ThisPointeeLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
+  }

samestep wrote:
> sgatev wrote:
> > What if `Arg` is null?
> Good point, thanks; under what circumstances can that happen? In any case, 
> I'm adding a guard for this.
It can be null if the argument isn't modeled and there's no value assigned to 
its storage location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131170

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


[clang] 12e78ff - [InstrProf] Add the skipprofile attribute

2022-08-04 Thread Ellis Hoag via cfe-commits

Author: Ellis Hoag
Date: 2022-08-04T08:45:27-07:00
New Revision: 12e78ff88105f2dc6cb1449d6fcd5d8f69e0512f

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

LOG: [InstrProf] Add the skipprofile attribute

As discussed in [0], this diff adds the `skipprofile` attribute to
prevent the function from being profiled while allowing profiled
functions to be inlined into it. The `noprofile` attribute remains
unchanged.

The `noprofile` attribute is used for functions where it is
dangerous to add instrumentation to while the `skipprofile` attribute is
used to reduce code size or performance overhead.

[0] 
https://discourse.llvm.org/t/why-does-the-noprofile-attribute-restrict-inlining/64108

Reviewed By: phosek

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenPGO.cpp
clang/test/CodeGen/profile-function-groups.c
llvm/docs/LangRef.rst
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Bitcode/attributes.ll
llvm/test/Transforms/GCOVProfiling/noprofile.ll
llvm/test/Transforms/PGOProfile/noprofile.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index b61a2a68687d9..30cf162e36206 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1522,7 +1522,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// If \p StepV is null, the default increment is 1.
   void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) {
 if (CGM.getCodeGenOpts().hasProfileClangInstr() &&
-!CurFn->hasFnAttribute(llvm::Attribute::NoProfile))
+!CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
+!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile))
   PGO.emitCounterIncrement(Builder, S, StepV);
 PGO.setCurrentStmt(S);
   }

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 587bcef78ee51..03531e32f1267 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -822,6 +822,8 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, 
llvm::Function *Fn) {
   CGM.ClearUnusedCoverageMapping(D);
   if (Fn->hasFnAttribute(llvm::Attribute::NoProfile))
 return;
+  if (Fn->hasFnAttribute(llvm::Attribute::SkipProfile))
+return;
 
   setFuncName(Fn);
 

diff  --git a/clang/test/CodeGen/profile-function-groups.c 
b/clang/test/CodeGen/profile-function-groups.c
index 9e04c9060df48..232abd767a8fd 100644
--- a/clang/test/CodeGen/profile-function-groups.c
+++ b/clang/test/CodeGen/profile-function-groups.c
@@ -1,9 +1,9 @@
-// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s 
--check-prefixes=CHECK,SELECT0
-// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s 
--check-prefixes=CHECK,SELECT1
-// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s 
--check-prefixes=CHECK,SELECT2
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s 
--implicit-check-not="; {{.* (noprofile|skipprofile)}}" 
--check-prefixes=CHECK,SELECT0
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s 
--implicit-check-not="; {{.* (noprofile|skipprofile)}}" 
--check-prefixes=CHECK,SELECT1
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 
-fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s 
--implicit-check-not="; {{.* (noprofile|skipprofile)}}" 
--check-prefixes=CHECK,SELECT2
 
 // Group 0
-// SELECT0-NOT: noprofile
+
 // SELECT1: noprofile
 // SELECT2: noprofile
 // CHECK: define {{.*}} @hoo()
@@ -11,7 +11,7 @@ void hoo() {}
 
 // Group 1
 // SELECT0: noprofile
-// SELECT1-NOT: noprofile
+
 // SELECT2: noprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
@@ -19,6 +19,6 @@ void goo() {}
 // Group 2
 // SELECT0: noprofile
 // SELECT1: noprofile
-// SELECT2-NOT: noprofile
+
 // CHECK: define {{.*}} @boo()
 void boo() {}

diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 2abe628cee8f2..a3c0824f16c6c 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1803,8 +18

[PATCH] D130807: [InstrProf] Add the skipprofile attribute

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12e78ff88105: [InstrProf] Add the skipprofile attribute 
(authored by ellis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() skipprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the skipprofile attribute disables profiling.
+define dso_local i32 @skip_instr(i32 %a) skipprofile {
+; CHECK-LABEL: @skip_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[SKIPPROFILE:#[0-9]+]]
+define void @f88() skipprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::SkipProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1574,6 +1574,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -698,6 +698,8 @@
 return bitc::ATTR_KIND_NOCF_CHECK;
   case Attribute::NoProfile:
 return bitc::ATTR_KIND_NO_PROFILE;
+  case Attribute::SkipProfile:
+return bitc::ATTR_KIND_SKIP_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NoSanitizeBounds:
Index: llvm/lib/Bitc

[clang] bcf6ffb - Reland "[lldb/Fuzzer] Add fuzzer for expression evaluator"

2022-08-04 Thread Chelsea Cassanova via cfe-commits

Author: Chelsea Cassanova
Date: 2022-08-04T11:47:06-04:00
New Revision: bcf6ffb87ec67ba41daeaab905b2c57a50568aa0

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

LOG: Reland "[lldb/Fuzzer] Add fuzzer for expression evaluator"

This reverts commit d959324e1efec12c3924c17b7d90db0b37eb84c3.

The target_include_directories in the clang-fuzzer CMake files
are set to PRIVATE instead of PUBLIC to prevent the clang buildbots
from breaking when symlinking clang into llvm.

The expression evaluator fuzzer itself has been modified to prevent a
bug that occurs when running it without a target.

Added: 
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Modified: 
clang/cmake/modules/ProtobufMutator.cmake
clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
lldb/tools/lldb-fuzzer/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/ProtobufMutator.cmake 
b/clang/cmake/modules/ProtobufMutator.cmake
index 15fe95ed6e8e9..071f11bc343de 100644
--- a/clang/cmake/modules/ProtobufMutator.cmake
+++ b/clang/cmake/modules/ProtobufMutator.cmake
@@ -1,5 +1,9 @@
 include(ExternalProject)
-set(PBM_PREFIX protobuf_mutator)
+
+if (NOT PBM_PREFIX)
+  set (PBM_PREFIX protobuf_mutator)
+endif()
+
 set(PBM_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PBM_PREFIX}/src/${PBM_PREFIX})
 set(PBM_LIB_PATH ${PBM_PATH}-build/src/libprotobuf-mutator.a)
 set(PBM_FUZZ_LIB_PATH 
${PBM_PATH}-build/src/libfuzzer/libprotobuf-mutator-libfuzzer.a)

diff  --git a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
index 6d62421d9a69a..184d467b9c365 100644
--- a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
@@ -11,3 +11,5 @@ add_clang_library(clangHandleCXX
   clangSerialization
   clangTooling
   )
+
+target_include_directories(clangHandleCXX PRIVATE .)

diff  --git a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
index 339959b81af0c..baefc8a301410 100644
--- a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -14,6 +14,8 @@ add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
   DEPENDS clangCXXLoopProto
   LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
   )
+target_include_directories(clangProtoToCXX PRIVATE .)
+target_include_directories(clangLoopProtoToCXX PRIVATE .)
 
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
 add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)

diff  --git a/lldb/tools/lldb-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/CMakeLists.txt
index 867a41961c13c..4c081a9de53e2 100644
--- a/lldb/tools/lldb-fuzzer/CMakeLists.txt
+++ b/lldb/tools/lldb-fuzzer/CMakeLists.txt
@@ -1,3 +1,4 @@
 add_subdirectory(lldb-commandinterpreter-fuzzer)
+add_subdirectory(lldb-expression-fuzzer)
 add_subdirectory(lldb-target-fuzzer)
 add_subdirectory(utils)

diff  --git a/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
new file mode 100644
index 0..1850e8e0ce352
--- /dev/null
+++ b/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
@@ -0,0 +1,60 @@
+if(CLANG_ENABLE_PROTO_FUZZER)
+  set(LLVM_LINK_COMPONENTS
+Support
+)
+
+  add_llvm_fuzzer(lldb-expression-fuzzer
+EXCLUDE_FROM_ALL
+lldb-expression-fuzzer.cpp
+)
+
+  if(TARGET lldb-expression-fuzzer)
+target_include_directories(lldb-expression-fuzzer PRIVATE ..)
+find_package(Protobuf REQUIRED)
+add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
+include_directories(${PROTOBUF_INCLUDE_DIRS})
+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../../clang/tools/clang-fuzzer
 PRIVATE ..)
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer)
+
+set(CLANG_CMAKE_MODULE_PATH
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/cmake/modules)
+
+set(CMAKE_MODULE_PATH
+  ${CMAKE_MODULE_PATH}
+  ${CLANG_CMAKE_MODULE_PATH})
+
+
+set (PBM_PREFIX lldb_protobuf_mutator)
+include(ProtobufMutator)
+include_directories(${ProtobufMutator_INCLUDE_DIRS})
+
+target_link_libraries(lldb-expression-fuzzer
+  PRIVATE
+  ${ProtobufMutator_LIBRARIES}
+  ${LLVM_LIB_FUZZING_ENGINE}
+  clangHandleCXX
+  clangCXXProto
+  clangProtoToCXX
+  liblldb
+  )
+
+add_custom_command(TARGET lldb-expression-fuzzer PRE_BUILD
+  COMMAND ${CMAKE_COMMAND} -E make_directory 
${CMAKE_BINARY_DIR}/fuzzer-art

[PATCH] D131170: [clang][dataflow] Analyze method bodies

2022-08-04 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:217
+const Expr *Arg = MethodCall->getImplicitObjectArgument();
+Env.ThisPointeeLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
+  }

sgatev wrote:
> samestep wrote:
> > sgatev wrote:
> > > What if `Arg` is null?
> > Good point, thanks; under what circumstances can that happen? In any case, 
> > I'm adding a guard for this.
> It can be null if the argument isn't modeled and there's no value assigned to 
> its storage location.
Hmm I don't quite follow; `Arg` just comes from calling 
`getImplicitObjectArgument` on the `CXXMemberCallExpr`, right? So shouldn't it 
only depend on the AST, and be completely independent of what we do or don't 
model?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131170

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


[clang] b692312 - [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via cfe-commits

Author: Ellis Hoag
Date: 2022-08-04T08:49:43-07:00
New Revision: b692312ca432d9a379f67a8d83177a6f1722baaa

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

LOG: [InstrProf] Add new format for -fprofile-list=

In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

Reviewed By: phosek

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

Added: 
clang/test/CodeGen/profile-filter-new.c

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/ProfileList.h
clang/lib/Basic/ProfileList.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/profile-function-groups.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 15df488e802de..f9ccca65f3889 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2500,43 +2500,66 @@ This can be done using the ``-fprofile-list`` option.
 
   .. code-block:: console
 
-$ echo "fun:test" > fun.list
 $ clang++ -O2 -fprofile-instr-generate -fprofile-list=fun.list code.cc -o 
code
 
-The option can be specified multiple times to pass multiple files.
+  The option can be specified multiple times to pass multiple files.
 
-.. code-block:: console
+  .. code-block:: console
+
+$ clang++ -O2 -fprofile-instr-generate -fcoverage-mapping 
-fprofile-list=fun.list -fprofile-list=code.list code.cc -o code
+
+Supported sections are ``[clang]``, ``[llvm]``, and ``[csllvm]`` representing
+clang PGO, IRPGO, and CSIRPGO, respectively. Supported prefixes are 
``function``
+and ``source``. Supported categories are ``allow``, ``skip``, and ``forbid``.
+``skip`` adds the ``skipprofile`` attribute while ``forbid`` adds the
+``noprofile`` attribute to the appropriate function. Use
+``default:`` to specify the default category.
+
+  .. code-block:: console
+
+$ cat fun.list
+# The following cases are for clang instrumentation.
+[clang]
+
+# We might not want to profile functions that are inlined in many places.
+function:inlinedLots=skip
+
+# We want to forbid profiling where it might be dangerous.
+source:lib/unsafe/*.cc=forbid
 
-$ echo "!fun:*test*" > fun.list
-$ echo "src:code.cc" > src.list
-% clang++ -O2 -fprofile-instr-generate -fcoverage-mapping 
-fprofile-list=fun.list -fprofile-list=code.list code.cc -o code
+# Otherwise we allow profiling.
+default:allow
 
-To filter individual functions or entire source files using ``fun:`` or
-``src:`` respectively. To exclude a function or a source file, use
-``!fun:`` or ``!src:`` respectively. The format also supports
-wildcard expansion. The compiler generated functions are assumed to be located
-in the main source file.  It is also possible to restrict the filter to a
-particular instrumentation type by using a named section.
+Older Prefixes
+""
+  An older format is also supported, but it is only able to add the
+  ``noprofile`` attribute.
+  To filter individual functions or entire source files use ``fun:`` or
+  ``src:`` respectively. To exclude a function or a source file, use
+  ``!fun:`` or ``!src:`` respectively. The format also supports
+  wildcard expansion. The compiler generated functions are assumed to be 
located
+  in the main source file.  It is also possible to restrict the filter to a
+  particular instrumentation type by using a named section.
 
-.. code-block:: none
+  .. code-block:: none
 
-  # all functions whose name starts with foo will be instrumented.
-  fun:foo*
+# all functions whose name starts with foo will be instrumented.
+fun:foo*
 
-  # except for foo1 which will be excluded from instrumentation.
-  !fun:foo1
+# except for foo1 which will be excluded from instrumentation.
+!fun:foo1
 
-  # every function in path/to/foo.cc will be instrumented.
-  src:path/to/foo.cc
+# every function in path/to/foo.cc will be instrumented.
+src:path/to/foo.cc
 
-  # bar will be instrumented only when using backend instrumentation.
-  # Recognized section names are clang, llvm and csllvm.
-  [llvm]
-  fun:bar
+# bar will be instrumented only when using backend instrumentation.
+# Recognized section names are clang, llvm and csllvm.
+[llvm]
+fun:bar
 
-When the file contains only excludes, all files and functions except for the
-excluded ones will be instrumented. Otherwise, only the files and functions
-specified will be instrumented.
+  When the file

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb692312ca432: [InstrProf] Add new format for -fprofile-list= 
(authored by ellis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2895,46 +2895,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.

  1   2   3   >