[clang] ffcf214 - [analyzer] NonParamVarRegion should prefer definition over canonical decl

2023-07-11 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2023-07-11T08:50:59+02:00
New Revision: ffcf214b5d27453119575d4e075cac483d659024

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

LOG: [analyzer] NonParamVarRegion should prefer definition over canonical decl

When we construct a `NonParamVarRegion`, we canonicalize the decl to
always use the same entity for consistency.
At the moment that is the canonical decl - which is the first decl in
the redecl chain.

However, this can cause problems with tentative declarations and extern
declarations if we declare an array with unknown bounds.

Consider this C example: https://godbolt.org/z/Kdvr11EqY
```lang=C
typedef typeof(sizeof(int)) size_t;
size_t clang_analyzer_getExtent(const void *p);
void clang_analyzer_dump(size_t n);

extern const unsigned char extern_redecl[];
const unsigned char extern_redecl[] = { 1,2,3,4 };
const unsigned char tentative_redecl[];
const unsigned char tentative_redecl[] = { 1,2,3,4 };

const unsigned char direct_decl[] = { 1,2,3,4 };

void test_redeclaration_extent(void) {
  clang_analyzer_dump(clang_analyzer_getExtent(direct_decl));  // 4
  clang_analyzer_dump(clang_analyzer_getExtent(extern_redecl));// should be 
4 instead of Unknown
  clang_analyzer_dump(clang_analyzer_getExtent(tentative_redecl)); // should be 
4 instead of Unknown
}
```

The `getType()` of the canonical decls for the forward declared globals,
will return `IncompleteArrayType`, unlike the
`getDefinition()->getType()`, which would have returned
`ConstantArrayType` of 4 elements.

This makes the `MemRegionManager::getStaticSize()` return `Unknown` as
the extent for the array variables, leading to FNs.

To resolve this, I think we should prefer the definition decl (if
present) over the canonical decl when constructing `NonParamVarRegion`s.

FYI The canonicalization of the decl was introduced by D57619 in 2019.

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

Added: 
clang/test/Analysis/globals.c

Modified: 
clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp 
b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
index f89e71a4f157b7..16db6b249dc92b 100644
--- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1077,13 +1077,16 @@ const VarRegion *MemRegionManager::getVarRegion(const 
VarDecl *D,
 }
   }
 
-  return getSubRegion(D, sReg);
+  return getNonParamVarRegion(D, sReg);
 }
 
 const NonParamVarRegion *
 MemRegionManager::getNonParamVarRegion(const VarDecl *D,
const MemRegion *superR) {
+  // Prefer the definition over the canonical decl as the canonical form.
   D = D->getCanonicalDecl();
+  if (const VarDecl *Def = D->getDefinition())
+D = Def;
   return getSubRegion(D, superR);
 }
 

diff  --git a/clang/test/Analysis/globals.c b/clang/test/Analysis/globals.c
new file mode 100644
index 00..a0dae9d64b3c2e
--- /dev/null
+++ b/clang/test/Analysis/globals.c
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+typedef typeof(sizeof(int)) size_t;
+size_t clang_analyzer_getExtent(const void *p);
+void clang_analyzer_dump(size_t n);
+
+extern const unsigned char extern_redecl[];
+const unsigned char extern_redecl[] = { 1,2,3,4 };
+const unsigned char tentative_redecl[];
+const unsigned char tentative_redecl[] = { 1,2,3,4 };
+
+const unsigned char direct_decl[] = { 1,2,3,4 };
+
+void test_redeclaration_extent(void) {
+  clang_analyzer_dump(clang_analyzer_getExtent(direct_decl));  // 
expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(extern_redecl));// 
expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(tentative_redecl)); // 
expected-warning {{4 S64b}}
+}



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


[PATCH] D154903: clangd: Provide the resource dir via environment variable

2023-07-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: sammccall.
nridge added a comment.

Looks reasonable to me but Sam should OK this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154903

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


[PATCH] D154923: [CodeGen] Support bitcode input containing multiple modules

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: ormris, efriedma, rjmccall, aaron.ballman.
Herald added subscribers: steven_wu, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When using -fsplit-lto-unit (explicitly specified or due to using
-fsanitize=cfi/-fwhole-program-vtables), the emitted LLVM IR contains a module
flag metadata `"EnableSplitLTOUnit"`. If a module contains both type metadata 
and
`"EnableSplitLTOUnit"`, `ThinLTOBitcodeWriter.cpp` will write two modules into
the bitcode file. Compiling the bitcode will lead to an error due to `parseIR`
requiring a single module.

  % clang -flto=thin a.cc -c -o a.bc
  % clang -c a.bc
  % clang -fsplit-lto-unit -flto=thin a.cc -c -o a.bc
  % clang -c a.bc
  error: Expected a single module
  1 error generated.

Let's place the extra module (if present) into CodeGenOptions::LinkBitcodeFiles
(originally for -cc1 -mlink-bitcode-file). Linker::linkModules will link the two
modules together. This patch makes the following commands work:

  clang -S -emit-llvm a.bc
  clang -S a.bc
  clang -c a.bc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154923

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/split-lto-unit-input.cpp

Index: clang/test/CodeGen/split-lto-unit-input.cpp
===
--- /dev/null
+++ clang/test/CodeGen/split-lto-unit-input.cpp
@@ -0,0 +1,32 @@
+// REQUIRES: x86-registered-target
+/// When the input is a -fsplit-lto-unit bitcode file, link the regular LTO file like -mlink-bitcode-file.
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm-bc -flto=thin -flto-unit -fsplit-lto-unit %s -o %t.bc
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-obj %t.bc -o %t.o
+// RUN: llvm-nm %t.o | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %t.bc -o - | FileCheck %s --check-prefix=CHECK-IR
+
+// CHECK:  V _ZTI1A
+// CHECK-NEXT: V _ZTI1B
+// CHECK-NEXT: V _ZTS1A
+// CHECK-NEXT: V _ZTS1B
+// CHECK-NEXT: V _ZTV1A
+// CHECK-NEXT: V _ZTV1B
+
+// CHECK-IR-DAG: _ZTS1B = linkonce_odr constant
+// CHECK-IR-DAG: _ZTS1A = linkonce_odr constant
+// CHECK-IR-DAG: _ZTV1B = linkonce_odr unnamed_addr constant
+// CHECK-IR-DAG: _ZTI1A = linkonce_odr constant
+// CHECK-IR-DAG: _ZTI1B = linkonce_odr constant
+// CHECK-IR-DAG: _ZTV1A = linkonce_odr unnamed_addr constant
+
+struct A {
+  virtual int c(int i) = 0;
+};
+
+struct B : A {
+  virtual int c(int i) { return i; }
+};
+
+int use() {
+  return (new B)->c(0);
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1112,21 +1112,21 @@
   CompilerInstance  = getCompilerInstance();
   SourceManager  = CI.getSourceManager();
 
+  auto DiagErrors = [&](Error E) -> std::unique_ptr {
+unsigned DiagID =
+CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
+  CI.getDiagnostics().Report(DiagID) << EIB.message();
+});
+return {};
+  };
+
   // For ThinLTO backend invocations, ensure that the context
   // merges types based on ODR identifiers. We also need to read
   // the correct module out of a multi-module bitcode file.
   if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
 VMContext->enableDebugTypeODRUniquing();
 
-auto DiagErrors = [&](Error E) -> std::unique_ptr {
-  unsigned DiagID =
-  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
-  handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
-CI.getDiagnostics().Report(DiagID) << EIB.message();
-  });
-  return {};
-};
-
 Expected> BMsOrErr = getBitcodeModuleList(MBRef);
 if (!BMsOrErr)
   return DiagErrors(BMsOrErr.takeError());
@@ -1151,10 +1151,35 @@
   if (loadLinkModules(CI))
 return nullptr;
 
+  // Handle textual IR and bitcode file with one single module.
   llvm::SMDiagnostic Err;
   if (std::unique_ptr M = parseIR(MBRef, Err, *VMContext))
 return M;
 
+  // If MBRef is a bitcode with multiple modules (e.g., -fsplit-lto-unit
+  // output), place the extra modules (actually only one, a regular LTO module)
+  // into LinkModules as if we are using -mlink-bitcode-file.
+  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+  if (BMsOrErr && BMsOrErr->size()) {
+std::unique_ptr M;
+for (auto  : *BMsOrErr) {
+  Expected> MOrErr =
+  BM.parseModule(*VMContext);
+  if (!MOrErr)
+return DiagErrors(MOrErr.takeError());
+  if (M)
+LinkModules.push_back({std::move(*MOrErr), /*PropagateAttrs=*/false,
+   /*Internalize=*/false, /*LinkFlags=*/{}});
+  else
+M = std::move(*MOrErr);
+}
+if (M)
+  return M;
+  }
+  // If BMsOrErr fails, 

[PATCH] D78038: [clangd] WIP: fix several bugs relating to include insertion

2023-07-11 Thread Thilo Vörtler via Phabricator via cfe-commits
voertler added a comment.

We stumbled upon this issue too. What is needed to pull in this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78038

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


[clang] e53da3e - [clang][dataflow][NFC] Expand a comment.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-11T06:32:08Z
New Revision: e53da3eab42e6efd448c1c60c14668e1eb3d907c

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

LOG: [clang][dataflow][NFC] Expand a comment.

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index c3de50894c9ede..73e20705cff501 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -123,6 +123,9 @@ static Value *mergeDistinctValues(QualType Type, Value 
,
   // returns false to avoid storing unneeded values in `DACtx`.
   // FIXME: Creating the value based on the type alone creates misshapen values
   // for lvalues, since the type does not reflect the need for 
`ReferenceValue`.
+  // This issue will be resolved when `ReferenceValue` is eliminated as part
+  // of the ongoing migration to strict handling of value categories (see
+  // https://discourse.llvm.org/t/70086 for details).
   if (Value *MergedVal = MergedEnv.createValue(Type))
 if (Model.merge(Type, Val1, Env1, Val2, Env2, *MergedVal, MergedEnv))
   return MergedVal;



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


[PATCH] D154834: [clang][dataflow][NFC] Expand a comment.

2023-07-11 Thread Martin Böhme 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 rGe53da3eab42e: [clang][dataflow][NFC] Expand a comment. 
(authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154834

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -123,6 +123,9 @@
   // returns false to avoid storing unneeded values in `DACtx`.
   // FIXME: Creating the value based on the type alone creates misshapen values
   // for lvalues, since the type does not reflect the need for 
`ReferenceValue`.
+  // This issue will be resolved when `ReferenceValue` is eliminated as part
+  // of the ongoing migration to strict handling of value categories (see
+  // https://discourse.llvm.org/t/70086 for details).
   if (Value *MergedVal = MergedEnv.createValue(Type))
 if (Model.merge(Type, Val1, Env1, Val2, Env2, *MergedVal, MergedEnv))
   return MergedVal;


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -123,6 +123,9 @@
   // returns false to avoid storing unneeded values in `DACtx`.
   // FIXME: Creating the value based on the type alone creates misshapen values
   // for lvalues, since the type does not reflect the need for `ReferenceValue`.
+  // This issue will be resolved when `ReferenceValue` is eliminated as part
+  // of the ongoing migration to strict handling of value categories (see
+  // https://discourse.llvm.org/t/70086 for details).
   if (Value *MergedVal = MergedEnv.createValue(Type))
 if (Model.merge(Type, Val1, Env1, Val2, Env2, *MergedVal, MergedEnv))
   return MergedVal;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-11 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/SemaCXX/static-assert-cxx26.cpp:1
+// RUN: %clang_cc1 -std=c++2c -fsyntax-only %s -verify
+

How about a test case w/ `data()` and or `size()` has default arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-11 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 539383.
xgupta added a comment.

.


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

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-tidy --checks='-*,misc-incomplete-switch' %s -- | FileCheck %s
+
+void Positive() {
+  int i = 0;
+  // CHECK: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [misc-incomplete-switch]
+  switch (i) {
+  case 0:
+break;
+  }
+}
+
+void Negative() {
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+}
Index: clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -14,6 +14,7 @@
 #include "DefinitionsInHeadersCheck.h"
 #include "HeaderIncludeCycleCheck.h"
 #include "IncludeCleanerCheck.h"
+#include "IncompleteSwitchCheck.h"
 #include "MisleadingBidirectional.h"
 #include "MisleadingIdentifier.h"
 #include "MisplacedConstCheck.h"
@@ -46,6 +47,7 @@
 CheckFactories.registerCheck(
 "misc-header-include-cycle");
 CheckFactories.registerCheck("misc-include-cleaner");
+CheckFactories.registerCheck("misc-incomplete-switch");
 CheckFactories.registerCheck(
 "misc-misleading-bidirectional");
 CheckFactories.registerCheck(
Index: clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
@@ -0,0 +1,31 @@
+//===--- IncompleteSwitchCheck.h - clang-tidy *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
+
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+
+class IncompleteSwitchCheck : public ClangTidyCheck {
+public:
+  IncompleteSwitchCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
Index: clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
@@ -0,0 +1,35 @@
+//===--- IncompleteSwitchCheck.cpp - clang-tidy ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncompleteSwitchCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+void IncompleteSwitchCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(hasDescendant(implicitCastExpr().bind("cast")),
+ unless(hasDescendant(defaultStmt(.bind("switch"),
+  this);
+}
+
+void IncompleteSwitchCheck::check(
+const ast_matchers::MatchFinder::MatchResult ) {
+  const auto *c = Result.Nodes.getNodeAs("cast");
+  if (c->getCastKind() == CK_IntegralCast)
+return;
+
+  const auto *s = Result.Nodes.getNodeAs("switch");
+  diag(s->getSwitchLoc(), "switching on non-enum value without "
+  "default case may not cover all cases");
+}
+
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/clang-tidy/misc/CMakeLists.txt
===
--- 

[clang] 2902ea3 - [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:23Z
New Revision: 2902ea3d817bf381817ff76228c3212f4dc87d47

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

LOG: [clang][dataflow] Introduce `getFieldValue()` test helpers.

These insulate tests against changes to the `getChild()` functions of 
`AggregateStorageLocation` and `StructValue` that will happen as part of the 
migration to strict handling of value categories (see 
https://discourse.llvm.org/t/70086 for details):

- `AggregateStorageLocation::getChild()` will soon return a `StorageLocation *`
  instead of a `StorageLocation &`. When this happens, `getFieldValue()` will be
  changed to return null if `AggregateStorageLocation::getChild()` returns null;
  test code will not need to change as it should already be checking whether the
  return value of `getFieldValue()` is null.

- `StructValue::getChild()` will soon return a `StorageLocation *` instead of a
  `Value *`. When this happens, `getFieldValue()` will be changed to look up the
  `Value *` in the `Environment`. Again, test code will not need to change.

The test helpers will continue to serve a useful purpose once the API changes 
are complete, so the intent is to leave them in place.

This patch changes DataflowEnvironmentTest.cpp and RecordOpsTest.cpp to use the 
test helpers. TransferTest.cpp will be changed in an upcoming patch to help 
keep patch sizes manageable for review.

Depends On D154934

Reviewed By: ymandel, xazax.hun, gribozavr2

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index 1c78dd380c7742..17c0f7b16c1c71 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "TestingSupport.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -23,6 +24,7 @@ namespace {
 
 using namespace clang;
 using namespace dataflow;
+using ::clang::dataflow::test::getFieldValue;
 using ::testing::ElementsAre;
 using ::testing::NotNull;
 using ::testing::Pair;
@@ -89,14 +91,9 @@ TEST_F(EnvironmentTest, CreateValueRecursiveType) {
   // Verify that the struct and the field (`R`) with first appearance of the
   // type is created successfully.
   Environment Env(DAContext, *Fun);
-  Value *Val = Env.createValue(Ty);
-  ASSERT_NE(Val, nullptr);
-  StructValue *SVal = clang::dyn_cast(Val);
-  ASSERT_NE(SVal, nullptr);
-  Val = SVal->getChild(*R);
-  ASSERT_NE(Val, nullptr);
-  PointerValue *PV = clang::dyn_cast(Val);
-  EXPECT_NE(PV, nullptr);
+  StructValue *SVal = cast(Env.createValue(Ty));
+  PointerValue *PV = cast_or_null(getFieldValue(SVal, *R, Env));
+  EXPECT_THAT(PV, NotNull());
 }
 
 TEST_F(EnvironmentTest, InitGlobalVarsFun) {
@@ -175,8 +172,7 @@ TEST_F(EnvironmentTest, 
IncludeFieldsFromDefaultInitializers) {
   // constructor, even though it is not referenced directly in the constructor.
   Environment Env(DAContext, *Constructor);
   auto *Val = cast(Env.createValue(QTy));
-  ASSERT_THAT(Val, NotNull());
-  EXPECT_THAT(Val->getChild(*XDecl), NotNull());
+  EXPECT_THAT(getFieldValue(Val, *XDecl, Env), NotNull());
 }
 
 TEST_F(EnvironmentTest, InitGlobalVarsFieldFun) {
@@ -221,8 +217,7 @@ TEST_F(EnvironmentTest, InitGlobalVarsFieldFun) {
   const auto *GlobalLoc =
   cast(Env.getStorageLocation(*GlobalDecl));
   const auto *GlobalVal = cast(Env.getValue(*GlobalLoc));
-  const auto *BarVal = GlobalVal->getChild(*BarDecl);
-  ASSERT_THAT(BarVal, NotNull());
+  auto *BarVal = getFieldValue(GlobalVal, *BarDecl, Env);
   EXPECT_TRUE(isa(BarVal));
 }
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
index 1f5fce1f2dd467..dc81e9594b6914 100644
--- a/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -63,12 +63,12 @@ TEST(RecordOpsTest, CopyRecord) {
 auto  = cast(S1.getChild(*InnerDecl));
 auto  = cast(S2.getChild(*InnerDecl));
 
-EXPECT_NE(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+

[clang] 103a0fc - [clang][dataflow] Use `getFieldValue()` in TransferTest.cpp.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:25Z
New Revision: 103a0fc0846050dd671e6485ab52491042f905c6

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

LOG: [clang][dataflow] Use `getFieldValue()` in TransferTest.cpp.

For context, see https://reviews.llvm.org/D154935.

Depends On D154935

Reviewed By: ymandel, xazax.hun

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index baadea57e43751..3ae3106bca4673 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -262,7 +262,8 @@ TEST(TransferTest, StructVarDecl) {
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -310,7 +311,8 @@ TEST(TransferTest, StructVarDeclWithInit) {
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -357,7 +359,8 @@ TEST(TransferTest, ClassVarDecl) {
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -470,37 +473,37 @@ TEST(TransferTest, SelfReferentialReferenceVarDecl) {
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooReferentVal = cast(Env.getValue(*FooLoc));
+const auto  =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto  = *cast(Env.getValue(FooLoc));
 
-const auto *BarVal =
-cast(FooReferentVal->getChild(*BarDecl));
-const auto *BarReferentVal =
-cast(Env.getValue(BarVal->getReferentLoc()));
+const auto  =
+*cast(FooReferentVal.getChild(*BarDecl));
+const auto  =
+*cast(Env.getValue(BarVal.getReferentLoc()));
 
-const auto *FooRefVal =
-cast(BarReferentVal->getChild(*FooRefDecl));
+const auto  =
+*cast(getFieldValue(, *FooRefDecl, 
Env));
 const auto  =
-cast(FooRefVal->getReferentLoc());
+cast(FooRefVal.getReferentLoc());
 EXPECT_THAT(Env.getValue(FooReferentLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooReferentLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *FooPtrVal =
-cast(BarReferentVal->getChild(*FooPtrDecl));
+const auto  =
+*cast(getFieldValue(, *FooPtrDecl, Env));
 const auto  =
-cast(FooPtrVal->getPointeeLoc());
+cast(FooPtrVal.getPointeeLoc());
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooPtrPointeeLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *BazRefVal =
-cast(BarReferentVal->getChild(*BazRefDecl));
-const StorageLocation  = BazRefVal->getReferentLoc();
+const auto  =
+*cast(getFieldValue(, *BazRefDecl, 
Env));
+const StorageLocation  = BazRefVal.getReferentLoc();
 EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
 
-const auto *BazPtrVal =
-cast(BarReferentVal->getChild(*BazPtrDecl));
-const StorageLocation  = BazPtrVal->getPointeeLoc();
+const auto  =
+*cast(getFieldValue(, *BazPtrDecl, Env));
+const StorageLocation  = BazPtrVal.getPointeeLoc();
 EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
   });
 }
@@ -630,35 +633,36 @@ TEST(TransferTest, SelfReferentialPointerVarDecl) {
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *FooPointeeVal =
-cast(Env.getValue(FooVal->getPointeeLoc()));
-
-const auto *BarVal =
-cast(FooPointeeVal->getChild(*BarDecl));
-const auto *BarPointeeVal =
-

[clang] 0014aab - [clang][dataflow] Use `IntegerValue` instead of `StructValue` in `ValueTest`.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:22Z
New Revision: 0014aab2d5882525c23130108e17fbbb5a2120f1

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

LOG: [clang][dataflow] Use `IntegerValue` instead of `StructValue` in 
`ValueTest`.

Soon, it will no longer be possible to default-construct `StructValue`. For 
details, see https://discourse.llvm.org/t/70086.

For completeness, also add a test that `areEquivalentValues()` on different 
`IntegerValue`s returns false.

Reviewed By: xazax.hun, gribozavr2

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/ValueTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/ValueTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
index 02f3adeaeda756..19ea7a04928f28 100644
--- a/clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@ using namespace clang;
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);



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


[clang] 1e9b4fc - [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:27Z
New Revision: 1e9b4fc1dcf27ae43477efe0329f738e4419871b

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

LOG: [clang][dataflow] Various refactorings in 
TypeErasedDataflowAnalysisTest.cpp

These simplify the code in their own right, but they are also useful in that 
they minimize the number of changes that will need to be made when then API of 
`AggregateStorageLocation` and `StructValue` changes as part of the migration 
to strict handling of value categories (see https://discourse.llvm.org/t/70086).

Depends On D154949

Reviewed By: xazax.hun, gribozavr2

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 473750ad7a6cb4..d811aed8fddd99 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@ TEST_F(NoreturnDestructorTest, 
ConditionalOperatorNestedBranchReturns) {
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue (AggregateStorageLocation ,
+  Environment ) {
+  auto  = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models an analysis that uses flow conditions.
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
@@ -390,23 +397,18 @@ class SpecialBoolAnalysis final
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), 
*S,
   getASTContext( {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", 
match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(

SpecialBoolRecordDecl
  .bind("call"),
  *S, getASTContext( {
-  auto *Object = E->getImplicitObjectArgument();
-  assert(Object != nullptr);
-
-  auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
-  assert(ObjectLoc != nullptr);
+  auto  =
+  *cast(getImplicitObjectLocation(*E, Env));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("is_set", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -551,21 +553,19 @@ class OptionalIntAnalysis final
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
-  assert(ObjectLoc != nullptr);
+  auto  = *cast(
+  Env.getStorageLocation(*Object, SkipPast::Reference));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("has_value", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -1227,9 +1227,7 @@ class TopAnalysis final : public 
DataflowAnalysis {
 match(callExpr(callee(functionDecl(hasName("makeTop".bind("top"),
   *S, getASTContext());
 if (const auto *E = selectFirst("top", Matches)) {
-  auto  = Env.createStorageLocation(*E);
-  Env.setValue(Loc, Env.makeTopBoolValue());
-  Env.setStorageLocation(*E, Loc);
+  Env.setValueStrict(*E, Env.makeTopBoolValue());
 }
   }
 



___
cfe-commits mailing list

[clang] b47bdcb - [clang][dataflow] Include fields initialized in an `InitListExpr` in `getModeledFields()`.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:29Z
New Revision: b47bdcbc7207aac617d3c35dfc029f79b0a46fd8

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

LOG: [clang][dataflow] Include fields initialized in an `InitListExpr` in 
`getModeledFields()`.

Previously, we were including these fields only in the specific instance that 
was initialized by the `InitListExpr`, but not in other instances of the same 
type. This is inconsistent and error-prone.

Depends On D154952

Reviewed By: xazax.hun, gribozavr2

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

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 7c1d01ce816e2b..5bd2e5518a5463 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -644,6 +644,10 @@ getImplicitObjectLocation(const CXXMemberCallExpr , 
const Environment );
 AggregateStorageLocation *getBaseObjectLocation(const MemberExpr ,
 const Environment );
 
+/// Returns the fields of `RD` that are initialized by an `InitListExpr`, in 
the
+/// order in which they appear in `InitListExpr::inits()`.
+std::vector getFieldsForInitListExpr(const RecordDecl *RD);
+
 } // namespace dataflow
 } // namespace clang
 

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 73e20705cff501..9b1fca41e911cc 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -215,6 +215,10 @@ getFieldsGlobalsAndFuncs(const Stmt , FieldSet ,
 insertIfFunction(*VD, Funcs);
 if (const auto *FD = dyn_cast(VD))
   Fields.insert(FD);
+  } else if (auto *InitList = dyn_cast()) {
+if (RecordDecl *RD = InitList->getType()->getAsRecordDecl())
+  for (const auto *FD : getFieldsForInitListExpr(RD))
+Fields.insert(FD);
   }
 }
 
@@ -958,5 +962,17 @@ AggregateStorageLocation *getBaseObjectLocation(const 
MemberExpr ,
   return cast(Loc);
 }
 
+std::vector getFieldsForInitListExpr(const RecordDecl *RD) {
+  // Unnamed bitfields are only used for padding and do not appear in
+  // `InitListExpr`'s inits. However, those fields do appear in `RecordDecl`'s
+  // field list, and we thus need to remove them before mapping inits to
+  // fields to avoid mapping inits to the wrongs fields.
+  std::vector Fields;
+  llvm::copy_if(
+  RD->fields(), std::back_inserter(Fields),
+  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  return Fields;
+}
+
 } // namespace dataflow
 } // namespace clang

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index ac971f69150f1e..e1a2606de81033 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -715,14 +715,8 @@ class TransferVisitor : public 
ConstStmtVisitor {
 Env.setValue(Loc, *Val);
 
 if (Type->isStructureOrClassType()) {
-  // Unnamed bitfields are only used for padding and are not appearing in
-  // `InitListExpr`'s inits. However, those fields do appear in 
RecordDecl's
-  // field list, and we thus need to remove them before mapping inits to
-  // fields to avoid mapping inits to the wrongs fields.
-  std::vector Fields;
-  llvm::copy_if(
-  Type->getAsRecordDecl()->fields(), std::back_inserter(Fields),
-  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  std::vector Fields =
+  getFieldsForInitListExpr(Type->getAsRecordDecl());
   for (auto It : llvm::zip(Fields, S->inits())) {
 const FieldDecl *Field = std::get<0>(It);
 assert(Field != nullptr);

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 3ae3106bca4673..254226fd6d3ee9 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2833,6 +2833,7 @@ TEST(TransferTest, AggregateInitialization) {
 
 void target(int BarArg, int FooArg, int QuxArg) {
   B Quux{BarArg, {FooArg}, QuxArg};
+  B OtherB;
   /*[[p]]*/
 }
   )";
@@ -2849,6 +2850,7 @@ TEST(TransferTest, AggregateInitialization) {
 
  

[PATCH] D154949: [clang][dataflow] Use `getFieldValue()` in TransferTest.cpp.

2023-07-11 Thread Martin Böhme 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 rG103a0fc08460: [clang][dataflow] Use `getFieldValue()` in 
TransferTest.cpp. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154949

Files:
  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
@@ -262,7 +262,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -310,7 +311,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -357,7 +359,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -470,37 +473,37 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooReferentVal = cast(Env.getValue(*FooLoc));
+const auto  =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto  = *cast(Env.getValue(FooLoc));
 
-const auto *BarVal =
-cast(FooReferentVal->getChild(*BarDecl));
-const auto *BarReferentVal =
-cast(Env.getValue(BarVal->getReferentLoc()));
+const auto  =
+*cast(FooReferentVal.getChild(*BarDecl));
+const auto  =
+*cast(Env.getValue(BarVal.getReferentLoc()));
 
-const auto *FooRefVal =
-cast(BarReferentVal->getChild(*FooRefDecl));
+const auto  =
+*cast(getFieldValue(, *FooRefDecl, Env));
 const auto  =
-cast(FooRefVal->getReferentLoc());
+cast(FooRefVal.getReferentLoc());
 EXPECT_THAT(Env.getValue(FooReferentLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooReferentLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *FooPtrVal =
-cast(BarReferentVal->getChild(*FooPtrDecl));
+const auto  =
+*cast(getFieldValue(, *FooPtrDecl, Env));
 const auto  =
-cast(FooPtrVal->getPointeeLoc());
+cast(FooPtrVal.getPointeeLoc());
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooPtrPointeeLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *BazRefVal =
-cast(BarReferentVal->getChild(*BazRefDecl));
-const StorageLocation  = BazRefVal->getReferentLoc();
+const auto  =
+*cast(getFieldValue(, *BazRefDecl, Env));
+const StorageLocation  = BazRefVal.getReferentLoc();
 EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
 
-const auto *BazPtrVal =
-cast(BarReferentVal->getChild(*BazPtrDecl));
-const StorageLocation  = BazPtrVal->getPointeeLoc();
+const auto  =
+*cast(getFieldValue(, *BazPtrDecl, Env));
+const StorageLocation  = BazPtrVal.getPointeeLoc();
 EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
   });
 }
@@ -630,35 +633,36 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *FooPointeeVal =
-cast(Env.getValue(FooVal->getPointeeLoc()));
-
-const auto *BarVal =
-cast(FooPointeeVal->getChild(*BarDecl));
-const auto *BarPointeeVal =
-cast(Env.getValue(BarVal->getPointeeLoc()));
-
-const auto *FooRefVal =
-cast(BarPointeeVal->getChild(*FooRefDecl));
-const StorageLocation  = FooRefVal->getReferentLoc();
+const auto  =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto  = *cast(Env.getValue(FooLoc));
+const auto  =
+*cast(Env.getValue(FooVal.getPointeeLoc()));
+
+const auto  =
+*cast(getFieldValue(, *BarDecl, Env));
+const auto  =
+

[PATCH] D154952: [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Böhme 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 rG1e9b4fc1dcf2: [clang][dataflow] Various refactorings in 
TypeErasedDataflowAnalysisTest.cpp (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154952

Files:
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue (AggregateStorageLocation ,
+  Environment ) {
+  auto  = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models an analysis that uses flow conditions.
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
@@ -390,23 +397,18 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), 
*S,
   getASTContext( {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", 
match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(

SpecialBoolRecordDecl
  .bind("call"),
  *S, getASTContext( {
-  auto *Object = E->getImplicitObjectArgument();
-  assert(Object != nullptr);
-
-  auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
-  assert(ObjectLoc != nullptr);
+  auto  =
+  *cast(getImplicitObjectLocation(*E, Env));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("is_set", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -551,21 +553,19 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
-  assert(ObjectLoc != nullptr);
+  auto  = *cast(
+  Env.getStorageLocation(*Object, SkipPast::Reference));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("has_value", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -1227,9 +1227,7 @@
 match(callExpr(callee(functionDecl(hasName("makeTop".bind("top"),
   *S, getASTContext());
 if (const auto *E = selectFirst("top", Matches)) {
-  auto  = Env.createStorageLocation(*E);
-  Env.setValue(Loc, Env.makeTopBoolValue());
-  Env.setStorageLocation(*E, Loc);
+  Env.setValueStrict(*E, Env.makeTopBoolValue());
 }
   }
 


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue (AggregateStorageLocation ,
+  Environment ) {
+  auto  = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models an analysis that uses flow conditions.
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
@@ -390,23 +397,18 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S,
  

[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Böhme 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 rG2902ea3d817b: [clang][dataflow] Introduce `getFieldValue()` 
test helpers. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

Files:
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -451,6 +451,28 @@
   return *cast(Env.getValue(*VD));
 }
 
+/// Returns the value of a `Field` on the record referenced by `Loc.`
+/// Returns null if `Loc` is null.
+inline Value *getFieldValue(const AggregateStorageLocation *Loc,
+const ValueDecl , const Environment ) {
+  if (Loc == nullptr)
+return nullptr;
+  return Env.getValue(Loc->getChild(Field));
+}
+
+/// Returns the value of a `Field` on a `Struct.
+/// Returns null if `Struct` is null.
+///
+/// Note: This function currently does not use the `Env` parameter, but it will
+/// soon be needed to look up the `Value` when `setChild()` changes to return a
+/// `StorageLocation *`.
+inline Value *getFieldValue(const StructValue *Struct, const ValueDecl ,
+const Environment ) {
+  if (Struct == nullptr)
+return nullptr;
+  return Struct->getChild(Field);
+}
+
 /// Creates and owns constraints which are boolean values.
 class ConstraintContext {
   unsigned NextAtom = 0;
Index: clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -63,12 +63,12 @@
 auto  = cast(S1.getChild(*InnerDecl));
 auto  = cast(S2.getChild(*InnerDecl));
 
-EXPECT_NE(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_NE(getFieldValue(, *OuterIntDecl, Env),
+  getFieldValue(, *OuterIntDecl, Env));
 EXPECT_NE(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_NE(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_NE(getFieldValue(, *InnerIntDecl, Env),
+  getFieldValue(, *InnerIntDecl, Env));
 
 auto *S1Val = cast(Env.getValue(S1));
 auto *S2Val = cast(Env.getValue(S2));
@@ -78,12 +78,12 @@
 
 copyRecord(S1, S2, Env);
 
-EXPECT_EQ(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_EQ(getFieldValue(, *OuterIntDecl, Env),
+  getFieldValue(, *OuterIntDecl, Env));
 EXPECT_EQ(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_EQ(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_EQ(getFieldValue(, *InnerIntDecl, Env),
+  getFieldValue(, *InnerIntDecl, Env));
 
 S1Val = cast(Env.getValue(S1));
 S2Val = cast(Env.getValue(S2));
Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "TestingSupport.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -23,6 +24,7 @@
 
 using namespace clang;
 using namespace dataflow;
+using ::clang::dataflow::test::getFieldValue;
 using ::testing::ElementsAre;
 using ::testing::NotNull;
 using ::testing::Pair;
@@ -89,14 +91,9 @@
   // Verify that the struct and the field (`R`) with first appearance of the
   // type is created successfully.
   Environment Env(DAContext, *Fun);
-  Value *Val = Env.createValue(Ty);
-  ASSERT_NE(Val, nullptr);
-  StructValue *SVal = clang::dyn_cast(Val);
-  ASSERT_NE(SVal, nullptr);
-  Val = SVal->getChild(*R);
-  ASSERT_NE(Val, nullptr);
-  PointerValue *PV = clang::dyn_cast(Val);
-  EXPECT_NE(PV, nullptr);
+  StructValue *SVal = cast(Env.createValue(Ty));
+  PointerValue *PV = cast_or_null(getFieldValue(SVal, *R, Env));
+  

[PATCH] D154965: [clang][dataflow] Fix initializing a reference field with an `InitListExpr`.

2023-07-11 Thread Martin Böhme 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 rGbd9b57de4ff7: [clang][dataflow] Fix initializing a reference 
field with an `InitListExpr`. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154965

Files:
  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
@@ -2912,6 +2912,34 @@
   }
 }
 
+TEST(TransferTest, AggregateInitializationReferenceField) {
+  std::string Code = R"(
+struct S {
+  int 
+};
+
+void target(int i) {
+  S s = { i };
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *RefFieldDecl = findValueDecl(ASTCtx, "RefField");
+
+auto  = getLocForDecl(ASTCtx, Env, "i");
+auto  = getLocForDecl(ASTCtx, Env, "s");
+
+auto  =
+*cast(getFieldValue(, *RefFieldDecl, Env));
+EXPECT_EQ((), );
+  });
+}
+
 TEST(TransferTest, AssignToUnionMember) {
   std::string Code = R"(
 union A {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -717,14 +717,15 @@
 if (Type->isStructureOrClassType()) {
   std::vector Fields =
   getFieldsForInitListExpr(Type->getAsRecordDecl());
-  for (auto It : llvm::zip(Fields, S->inits())) {
-const FieldDecl *Field = std::get<0>(It);
+  for (auto [Field, Init] : llvm::zip(Fields, S->inits())) {
 assert(Field != nullptr);
-
-const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
-if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+if (Field->getType()->isReferenceType()) {
+  if (StorageLocation *Loc = Env.getStorageLocationStrict(*Init))
+cast(Val)->setChild(*Field,
+ Env.create(*Loc));
+} else if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
   cast(Val)->setChild(*Field, *InitVal);
   }
 }


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2912,6 +2912,34 @@
   }
 }
 
+TEST(TransferTest, AggregateInitializationReferenceField) {
+  std::string Code = R"(
+struct S {
+  int 
+};
+
+void target(int i) {
+  S s = { i };
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *RefFieldDecl = findValueDecl(ASTCtx, "RefField");
+
+auto  = getLocForDecl(ASTCtx, Env, "i");
+auto  = getLocForDecl(ASTCtx, Env, "s");
+
+auto  =
+*cast(getFieldValue(, *RefFieldDecl, Env));
+EXPECT_EQ((), );
+  });
+}
+
 TEST(TransferTest, AssignToUnionMember) {
   std::string Code = R"(
 union A {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -717,14 +717,15 @@
 if (Type->isStructureOrClassType()) {
   std::vector Fields =
   getFieldsForInitListExpr(Type->getAsRecordDecl());
-  for (auto It : llvm::zip(Fields, S->inits())) {
-const FieldDecl *Field = std::get<0>(It);
+  for (auto [Field, Init] : llvm::zip(Fields, S->inits())) {
 assert(Field != nullptr);
-
-const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
-if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+if (Field->getType()->isReferenceType()) {
+  if (StorageLocation *Loc = Env.getStorageLocationStrict(*Init))
+cast(Val)->setChild(*Field,
+ Env.create(*Loc));
+} else if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
   cast(Val)->setChild(*Field, *InitVal);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bd9b57d - [clang][dataflow] Fix initializing a reference field with an `InitListExpr`.

2023-07-11 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-12T04:52:30Z
New Revision: bd9b57de4ff7c65be0d69179232ba2d5fe832195

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

LOG: [clang][dataflow] Fix initializing a reference field with an 
`InitListExpr`.

I added a test for this as the ongoing migration to strict handling of value 
categories (see https://discourse.llvm.org/t/70086) will change the code that 
handles this case. It turns out we already didn't handle this correctly, so I 
fixed the existing implementation.

Depends On D154961

Reviewed By: xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index e1a2606de81033..4c97e81184bba3 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -717,14 +717,15 @@ class TransferVisitor : public 
ConstStmtVisitor {
 if (Type->isStructureOrClassType()) {
   std::vector Fields =
   getFieldsForInitListExpr(Type->getAsRecordDecl());
-  for (auto It : llvm::zip(Fields, S->inits())) {
-const FieldDecl *Field = std::get<0>(It);
+  for (auto [Field, Init] : llvm::zip(Fields, S->inits())) {
 assert(Field != nullptr);
-
-const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
-if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+if (Field->getType()->isReferenceType()) {
+  if (StorageLocation *Loc = Env.getStorageLocationStrict(*Init))
+cast(Val)->setChild(*Field,
+ Env.create(*Loc));
+} else if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
   cast(Val)->setChild(*Field, *InitVal);
   }
 }

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 254226fd6d3ee9..a89ff8e7bc5ab5 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2912,6 +2912,34 @@ TEST(TransferTest, AggregateInitialization) {
   }
 }
 
+TEST(TransferTest, AggregateInitializationReferenceField) {
+  std::string Code = R"(
+struct S {
+  int 
+};
+
+void target(int i) {
+  S s = { i };
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> ,
+ ASTContext ) {
+const Environment  = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *RefFieldDecl = findValueDecl(ASTCtx, "RefField");
+
+auto  = getLocForDecl(ASTCtx, Env, "i");
+auto  = getLocForDecl(ASTCtx, Env, "s");
+
+auto  =
+*cast(getFieldValue(, *RefFieldDecl, Env));
+EXPECT_EQ((), );
+  });
+}
+
 TEST(TransferTest, AssignToUnionMember) {
   std::string Code = R"(
 union A {



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


[PATCH] D154934: [clang][dataflow] Use `IntegerValue` instead of `StructValue` in `ValueTest`.

2023-07-11 Thread Martin Böhme 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 rG0014aab2d588: [clang][dataflow] Use `IntegerValue` instead 
of `StructValue` in `ValueTest`. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154934

Files:
  clang/unittests/Analysis/FlowSensitive/ValueTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154961: [clang][dataflow] Include fields initialized in an `InitListExpr` in `getModeledFields()`.

2023-07-11 Thread Martin Böhme 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 rGb47bdcbc7207: [clang][dataflow] Include fields initialized 
in an `InitListExpr` in… (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154961

Files:
  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
@@ -2833,6 +2833,7 @@
 
 void target(int BarArg, int FooArg, int QuxArg) {
   B Quux{BarArg, {FooArg}, QuxArg};
+  B OtherB;
   /*[[p]]*/
 }
   )";
@@ -2849,6 +2850,7 @@
 
 void target(int BarArg, int FooArg, int QuxArg) {
   B Quux = {BarArg, FooArg, QuxArg};
+  B OtherB;
   /*[[p]]*/
 }
   )";
@@ -2898,6 +2900,14 @@
   EXPECT_EQ(getFieldValue(QuuxVal, *BarDecl, Env), BarArgVal);
   EXPECT_EQ(getFieldValue(BazVal, *FooDecl, Env), FooArgVal);
   EXPECT_EQ(getFieldValue(QuuxVal, *QuxDecl, Env), QuxArgVal);
+
+  // Check that fields initialized in an initializer list are always
+  // modeled in other instances of the same type.
+  const auto  =
+  getValueForDecl(ASTCtx, Env, "OtherB");
+  EXPECT_THAT(OtherBVal.getChild(*BarDecl), NotNull());
+  EXPECT_THAT(OtherBVal.getChild(*BazDecl), NotNull());
+  EXPECT_THAT(OtherBVal.getChild(*QuxDecl), NotNull());
 });
   }
 }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -715,14 +715,8 @@
 Env.setValue(Loc, *Val);
 
 if (Type->isStructureOrClassType()) {
-  // Unnamed bitfields are only used for padding and are not appearing in
-  // `InitListExpr`'s inits. However, those fields do appear in RecordDecl's
-  // field list, and we thus need to remove them before mapping inits to
-  // fields to avoid mapping inits to the wrongs fields.
-  std::vector Fields;
-  llvm::copy_if(
-  Type->getAsRecordDecl()->fields(), std::back_inserter(Fields),
-  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  std::vector Fields =
+  getFieldsForInitListExpr(Type->getAsRecordDecl());
   for (auto It : llvm::zip(Fields, S->inits())) {
 const FieldDecl *Field = std::get<0>(It);
 assert(Field != nullptr);
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -215,6 +215,10 @@
 insertIfFunction(*VD, Funcs);
 if (const auto *FD = dyn_cast(VD))
   Fields.insert(FD);
+  } else if (auto *InitList = dyn_cast()) {
+if (RecordDecl *RD = InitList->getType()->getAsRecordDecl())
+  for (const auto *FD : getFieldsForInitListExpr(RD))
+Fields.insert(FD);
   }
 }
 
@@ -958,5 +962,17 @@
   return cast(Loc);
 }
 
+std::vector getFieldsForInitListExpr(const RecordDecl *RD) {
+  // Unnamed bitfields are only used for padding and do not appear in
+  // `InitListExpr`'s inits. However, those fields do appear in `RecordDecl`'s
+  // field list, and we thus need to remove them before mapping inits to
+  // fields to avoid mapping inits to the wrongs fields.
+  std::vector Fields;
+  llvm::copy_if(
+  RD->fields(), std::back_inserter(Fields),
+  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  return Fields;
+}
+
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -644,6 +644,10 @@
 AggregateStorageLocation *getBaseObjectLocation(const MemberExpr ,
 const Environment );
 
+/// Returns the fields of `RD` that are initialized by an `InitListExpr`, in the
+/// order in which they appear in `InitListExpr::inits()`.
+std::vector getFieldsForInitListExpr(const RecordDecl *RD);
+
 } // namespace dataflow
 } // namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D153701: [WIP][Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-07-11 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:8901-8914
+  // [P2718R0] Lifetime extension in range-based for loops.
+  //
+  // 6.7.7 [class.temporary] p5:
+  // There are four contexts in which temporaries are destroyed at a different
+  // point than the end of the full-expression.
+  //
+  // 6.7.7 [class.temporary] p6:

yronglin wrote:
> rsmith wrote:
> > This isn't the right way to model the behavior here -- the presence or 
> > absence of an `ExprWithCleanups` is just a convenience to tell consumers of 
> > the AST whether they should expect to see cleanups later or not, and 
> > doesn't carry an implication of affecting the actual temporary lifetimes 
> > and storage durations.
> > 
> > The outcome that we should be aiming to reach is that all 
> > `MaterializeTemporaryExpr`s created as part of processing the 
> > for-range-initializer are marked as being lifetime-extended by the 
> > for-range variable. Probably the simplest way to handle that would be to 
> > track the current enclosing for-range-initializer variable in the 
> > `ExpressionEvaluationContextRecord`, and whenever a 
> > `MaterializeTemporaryExpr` is created, if there is a current enclosing 
> > for-range-initializer, mark that `MaterializeTemporaryExpr` as being 
> > lifetime-extended by it.
> Awesome! Thanks a lot for your advice, this is very helpful! I want to take a 
> longer look at it.
As mentioned in D139586, `CXXDefaultArgExpr`s may need additional handling. 
Similarly for `CXXDefaultInitExpr`s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-11 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 539378.
xgupta retitled this revision from "[clang-tidy] Add check for possibly 
incomplete switch statements
" to "[clang-tidy] Add check for possibly incomplete switch statements".
xgupta added a reviewer: PiotrZSL.
xgupta added a comment.
Herald added a reviewer: njames93.
Herald added a project: clang-tools-extra.

Just updated the patch to trunk


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

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/incomplete-switch.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-tidy --checks='-*,misc-incomplete-switch' %s -- | FileCheck %s
+
+void Positive() {
+  int i = 0;
+  // CHECK: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [misc-incomplete-switch]
+  switch (i) {
+  case 0:
+break;
+  }
+}
+
+void Negative() {
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+}
Index: clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -14,6 +14,7 @@
 #include "DefinitionsInHeadersCheck.h"
 #include "HeaderIncludeCycleCheck.h"
 #include "IncludeCleanerCheck.h"
+#include "IncompleteSwitchCheck.h"
 #include "MisleadingBidirectional.h"
 #include "MisleadingIdentifier.h"
 #include "MisplacedConstCheck.h"
@@ -46,6 +47,7 @@
 CheckFactories.registerCheck(
 "misc-header-include-cycle");
 CheckFactories.registerCheck("misc-include-cleaner");
+CheckFactories.registerCheck("misc-incomplete-switch");
 CheckFactories.registerCheck(
 "misc-misleading-bidirectional");
 CheckFactories.registerCheck(
Index: clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.h
@@ -0,0 +1,23 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
+
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+
+class IncompleteSwitchCheck : public ClangTidyCheck {
+public:
+  IncompleteSwitchCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCOMPLETESWITCHCHECK_H
Index: clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/misc/IncompleteSwitchCheck.cpp
@@ -0,0 +1,27 @@
+#include "IncompleteSwitchCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+void IncompleteSwitchCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(hasDescendant(implicitCastExpr().bind("cast")),
+ unless(hasDescendant(defaultStmt(.bind("switch"),
+  this);
+}
+
+void IncompleteSwitchCheck::check(
+const ast_matchers::MatchFinder::MatchResult ) {
+  const auto *c = Result.Nodes.getNodeAs("cast");
+  if (c->getCastKind() == CK_IntegralCast)
+return;
+
+  const auto *s = Result.Nodes.getNodeAs("switch");
+  diag(s->getSwitchLoc(), "switching on non-enum value without "
+  "default case may not cover all cases");
+}
+
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/clang-tidy/misc/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -22,6 +22,7 @@
   ConfusableIdentifierCheck.cpp
   HeaderIncludeCycleCheck.cpp
   IncludeCleanerCheck.cpp
+  IncompleteSwitchCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] fa68972 - [dataflow] document flow condition

2023-07-11 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-07-12T07:20:46+02:00
New Revision: fa689726768b7b5cae01970cce2e59a72a0229b4

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

LOG: [dataflow] document flow condition

There's some documentation of this concept at
https://clang.llvm.org/docs/DataFlowAnalysisIntro.html
but it would be nice to have it closer to the code.

I also was laboring under an obvious but wrong mental model that
the flow condition token represented "execution reached this point",
I'd like to explicitly call that out as wrong.

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 5bd2e5518a5463..512f66073da457 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -22,6 +22,7 @@
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
 #include "clang/Analysis/FlowSensitive/Logger.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -524,16 +525,30 @@ class Environment {
 arena().makeEquals(LHS.formula(), RHS.formula()));
   }
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition (FC).
+  ///
+  /// The flow condition is a set of facts that are necessarily true when the
+  /// program reaches the current point, expressed as boolean formulas.
+  /// The flow condition token is equivalent to the AND of these facts.
+  ///
+  /// These may e.g. constrain the value of certain variables. A pointer
+  /// variable may have a consistent modeled PointerValue throughout, but at a
+  /// given point the Environment may tell us that the value must be non-null.
+  ///
+  /// The FC is necessary but not sufficient for this point to be reachable.
+  /// In particular, where the FC token appears in flow conditions of successor
+  /// environments, it means "point X may have been reached", not
+  /// "point X was reached".
   Atom getFlowConditionToken() const { return FlowConditionToken; }
 
-  /// Adds `Val` to the set of clauses that constitute the flow condition.
+  /// Record a fact that must be true if this point in the program is reached.
   void addToFlowCondition(const Formula &);
   /// Deprecated: Use Formula version instead.
   void addToFlowCondition(BoolValue );
 
-  /// Returns true if and only if the clauses that constitute the flow 
condition
-  /// imply that `Val` is true.
+  /// Returns true if the formula is always true when this point is reached.
+  /// Returns false if the formula may be false, or if the flow condition isn't
+  /// sufficiently precise to prove that it is true.
   bool flowConditionImplies(const Formula &) const;
   /// Deprecated: Use Formula version instead.
   bool flowConditionImplies(BoolValue ) const;



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


[PATCH] D154969: [dataflow] document flow condition

2023-07-11 Thread Sam McCall 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 rGfa689726768b: [dataflow] document flow condition (authored 
by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D154969?vs=539086=539381#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154969

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


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -22,6 +22,7 @@
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
 #include "clang/Analysis/FlowSensitive/Logger.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -524,16 +525,30 @@
 arena().makeEquals(LHS.formula(), RHS.formula()));
   }
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition (FC).
+  ///
+  /// The flow condition is a set of facts that are necessarily true when the
+  /// program reaches the current point, expressed as boolean formulas.
+  /// The flow condition token is equivalent to the AND of these facts.
+  ///
+  /// These may e.g. constrain the value of certain variables. A pointer
+  /// variable may have a consistent modeled PointerValue throughout, but at a
+  /// given point the Environment may tell us that the value must be non-null.
+  ///
+  /// The FC is necessary but not sufficient for this point to be reachable.
+  /// In particular, where the FC token appears in flow conditions of successor
+  /// environments, it means "point X may have been reached", not
+  /// "point X was reached".
   Atom getFlowConditionToken() const { return FlowConditionToken; }
 
-  /// Adds `Val` to the set of clauses that constitute the flow condition.
+  /// Record a fact that must be true if this point in the program is reached.
   void addToFlowCondition(const Formula &);
   /// Deprecated: Use Formula version instead.
   void addToFlowCondition(BoolValue );
 
-  /// Returns true if and only if the clauses that constitute the flow 
condition
-  /// imply that `Val` is true.
+  /// Returns true if the formula is always true when this point is reached.
+  /// Returns false if the formula may be false, or if the flow condition isn't
+  /// sufficiently precise to prove that it is true.
   bool flowConditionImplies(const Formula &) const;
   /// Deprecated: Use Formula version instead.
   bool flowConditionImplies(BoolValue ) const;


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -22,6 +22,7 @@
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
 #include "clang/Analysis/FlowSensitive/Logger.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -524,16 +525,30 @@
 arena().makeEquals(LHS.formula(), RHS.formula()));
   }
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition (FC).
+  ///
+  /// The flow condition is a set of facts that are necessarily true when the
+  /// program reaches the current point, expressed as boolean formulas.
+  /// The flow condition token is equivalent to the AND of these facts.
+  ///
+  /// These may e.g. constrain the value of certain variables. A pointer
+  /// variable may have a consistent modeled PointerValue throughout, but at a
+  /// given point the Environment may tell us that the value must be non-null.
+  ///
+  /// The FC is necessary but not sufficient for this point to be reachable.
+  /// In particular, where the FC token appears in flow conditions of successor
+  /// environments, it means "point X may have been reached", not
+  /// "point X was reached".
   Atom getFlowConditionToken() const { return FlowConditionToken; }
 
-  /// Adds `Val` to the set of clauses that constitute the flow condition.
+  /// Record a fact that must be true if this point in the program is reached.
   void addToFlowCondition(const Formula &);
   /// 

[PATCH] D154822: [clang] Support '-fgpu-default-stream=per-thread' for NVIDIA CUDA

2023-07-11 Thread boxu.zhang via Phabricator via cfe-commits
boxu-zhang added a comment.

I don't have the permission to push to main branch. Can anyone push this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154822

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


[PATCH] D154701: [clang] Overridden CXXMethodDecl::isVirtual() assertion failed before fully imported.

2023-07-11 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/test/Analysis/ctu-astimport-virtual-assertion/main.cpp:22
+
+#include "Inputs/input.h"

balazske wrote:
> Such tests are not in the //Analysis// folder but in the //ASTMerge// folder 
> instead. I would say that this test is not necessary if the other test (in my 
> added note) is inserted.
Thanks for the testcase! The orignal one will be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154701

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


[PATCH] D143241: [Clang] Reset FP options before function instantiations

2023-07-11 Thread Sam James via Phabricator via cfe-commits
thesamesam added a comment.

During our regular snapshot testing, we've hit this in Gentoo on 32-bit Linux 
x86: https://github.com/llvm/llvm-project/issues/63704#issuecomment-1631791518.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143241

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther added a comment.

Thanks for the comments. Yes, `powerpc-*-eabi` should be valid (sorry if I was 
unclear about that – my parenthetical was only about AArch64). There is a 
PowerPC EABI: https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I 
wouldn’t know if Clang/LLD obey it, but it works for us…

I am fine with removing the vendor check if that is the consensus.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D154357#4487896 , @cwalther wrote:

> [...] There is a PowerPC EABI: 
> https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I wouldn’t know if 
> Clang/LLD obey it, but it works for us…

Good to know! I read a newer ABI named Power Architecture® 32-bit Application 
Binary Interface Supplement 1.0 - Linux® & Embedded which contains `EABI` as 
well but I forgot it after I implemented ld.lld PPC32 back in 2019 (D62464 
 and a few others) :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154931: [LoongArch] Support InlineAsm for LSX and LASX

2023-07-11 Thread 陈荔 via Phabricator via cfe-commits
leecheechen created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
leecheechen added reviewers: xen0n, xry111, hev, gonglingqin, SixWeining, 
wangleiat.
leecheechen published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

The author of the following files is licongtian :

- clang/lib/Basic/Targets/LoongArch.cpp
- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

The files mentioned above implement InlineAsm for LSX and LASX as follows:

- Enable clang parsing LSX/LASX register name, such as $vr0.
- Support the case which operand type is 128bit or 256bit when the constraints 
is 'f'.
- Support the way of specifying LSX/LASX register by using constraint, such as 
"={$xr0}".
- Support the operand modifiers 'u' and 'w'.
- Support and legalize the data types and register classes involved in LSX/LASX 
in the lowering process.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154931

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/lasx/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/lasx/inline-asm-gcc-regs.c
  clang/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-gcc-regs.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll
  llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
  llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
  llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll

Index: llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
+
+define void @register_vr1() nounwind {
+; CHECK-LABEL: register_vr1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr1, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr1}"()
+  ret void
+}
+
+define void @register_vr7() nounwind {
+; CHECK-LABEL: register_vr7:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr7, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr7}"()
+  ret void
+}
+
+define void @register_vr23() nounwind {
+; CHECK-LABEL: register_vr23:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr23, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr23}"()
+  ret void
+}
+
+;; The lower half of the vector register '$vr31' is same as the
+;; floating-point register '$f31'. And '$f31' is a callee-saved
+;; register which is preserved across calls. That's why the
+;; fst.d and fld.d instructions are emitted.
+define void @register_vr31() nounwind {
+; CHECK-LABEL: register_vr31:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addi.d $sp, $sp, -16
+; CHECK-NEXT:fst.d $fs7, $sp, 8 # 8-byte Folded Spill
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr31, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:fld.d $fs7, $sp, 8 # 8-byte Folded Reload
+; CHECK-NEXT:addi.d $sp, $sp, 16
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr31}"()
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
+
+define void @test_w() nounwind {
+; CHECK-LABEL: test_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr0, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "=f"()
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lasx < %s | FileCheck %s
+
+define void 

[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-07-11 Thread Shreyas via Phabricator via cfe-commits
SAtacker added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:288
+  }
+  for (auto  : LazySpecializations) {
+Record.push_back(SpecInfo.DeclID);

ChuanqiXu wrote:
> v.g.vassilev wrote:
> > We should not store the lazy specialization information as an array of 
> > items because that makes the search slow. Instead we should use the 
> > `OnDiskHashTable` approach which we use already to store the identifier 
> > data.
> Do you want to implement it in this patch? Or this is a note for future 
> optimizations?
I tried it here https://reviews.llvm.org/D144831 but to my surprise it gives 
worse performance for my testing environment which generates random 
specializations per module and a single main file.


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

https://reviews.llvm.org/D41416

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


[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-07-11 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Seems that it caused:
https://github.com/llvm/llvm-project/issues/63799


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp:62
+};
+struct Tree{
+  int height();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154948

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


[PATCH] D153659: [RISCV] Fix name mangling for LMUL!=1 vector types with attribute(rvv_vector_bits)

2023-07-11 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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153659

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


[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

2023-07-11 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1305
+  std::string Note =
+  llvm::formatv(Case.getNote().str().c_str(),
+cast(Call.getDecl())->getDeclName());

donat.nagy wrote:
> Consider using the method `StringRef::data()` which directly converts a 
> `StringRef` to a `const char *`. Your two-step conversion has the advantage 
> that it adds a `\0` terminator even if the `StringRef` isn't null-terminated, 
> but I cannot imagine a "natural" code change that would introduce references 
> to non-null-terminated char arrays as note message templates.
I would prefer not to rely on that `StringRef`s (here) are expected to be 
null-terminated, unless benchmarks demonstrate that this is important. If that 
would turn out to be the case, then we would need to enforce this using some 
sort of `assert` expression.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1337
+// if 'errno' is interesting.
+if (const auto *D = dyn_cast_or_null(Call.getDecl()))
+  if (const NoteTag *NT =

Previously, we had a `cast<>(Call.getDecl())`, thus we should only have a 
`dyn_cast` here.



Comment at: clang/test/Analysis/stream-note.c:61-62
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
+  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F1)

Why are these notes doubled?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153612

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 538948.
Ami-zhang added a comment.

Addressed @xen0n's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK-LABEL:  .Lxray_fn_idx0:
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream ) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr );
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr );
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr );
+  void emitSled(const MachineInstr , SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer ,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===
--- 

[PATCH] D154853: [clangd][c++20]Consider the constraint of a constrained auto in FindTarget.

2023-07-11 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 538952.
massberg added a comment.

clang-format code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154853

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -487,6 +487,46 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "int";
}},
+  // constraint of constrained auto
+  {R"cpp(
+template  concept Fooable = true;
+[[Foo^able]] auto x = 1;
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  {R"cpp(
+template  concept Fooable = true;
+template<[[Fooa^ble]] auto x> void Foo() {}
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  // concept
+  {R"cpp(
+template 
+concept Fooable = requires (T t) { t.foo(); };
+
+template  requires [[Fo^oable]]
+void bar(T t) {
+  t.foo();
+}
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = requires(T t) { t.foo(); }";
+   }},
   // auto on lambda
   {R"cpp(
 void foo() {
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -572,6 +572,23 @@
   )cpp";
   EXPECT_DECLS("ConceptSpecializationExpr",
{"template  concept Fooable = true"});
+
+  // Constrained auto
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+[[Fooable]] auto i = 42;
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template  concept Fooable = 
true"});
+
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+template<[[Fooable]] auto x> void Foo() {}
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template  concept Fooable = 
true"});
 }
 
 TEST_F(TargetDeclTest, Coroutine) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -471,6 +471,12 @@
   void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
 Outer.add(OIT->getDecl(), Flags);
   }
+  void VisitAutoType(const AutoType *T) {
+if (T->isConstrained()) {
+  Outer.add(T->getTypeConstraintConcept(), Flags);
+}
+TypeVisitor::VisitAutoType(T);
+  }
 };
 Visitor(*this, Flags).Visit(T.getTypePtr());
   }


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -487,6 +487,46 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "int";
}},
+  // constraint of constrained auto
+  {R"cpp(
+template  concept Fooable = true;
+[[Foo^able]] auto x = 1;
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  {R"cpp(
+template  concept Fooable = true;
+template<[[Fooa^ble]] auto x> void Foo() {}
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  // concept
+  {R"cpp(
+template 
+concept Fooable = requires (T t) { t.foo(); };
+
+template  requires [[Fo^oable]]
+void bar(T t) {
+  t.foo();
+}
+)cpp",
+   [](HoverInfo ) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+

[PATCH] D146054: [RISCV] Add --print-supported-extensions support

2023-07-11 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat marked an inline comment as done.
4vtomat added a comment.

@MaskRay if you are available, please help me to check the revision, thanks!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146054

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


[PATCH] D154471: [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I believe the fix is correct.

Though the fix has been verified by a real-world example, I think it would be 
nice to get a reproducible testcase. Looking at the stacktrace:

- the crash occurs during the pch deserialization
- and we miss handling the case where LValue base is a `DynamicAllocLValue`

so it looks like we can construct a `DynamicAllocLValue` case, and try to 
deserialize it (e.g. emitting a pch), and it should reproduce the crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154471

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


[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-07-11 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D41416#4487516 , @ChuanqiXu wrote:

> But some local in tree tests got failed. I took some time to investigate them 
> but I didn't get insights :  (

If the failures involve template template parameters, please note that you need 
https://reviews.llvm.org/D153003 for that to properly hash and find in the list 
of lazy specializations.




Comment at: clang/lib/AST/DeclTemplate.cpp:366
+  Args,
+  TemplateParameterList 
*TPL) const {
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();

ChuanqiXu wrote:
> TPL here looks not used.
This is required because of the argument forwarding from 
`findSpecializationImpl` below...


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

https://reviews.llvm.org/D41416

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


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:27
 using namespace dataflow;
+using test::getFieldValue;
 using ::testing::ElementsAre;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

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


[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,7 +300,8 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle ) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle );
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,7 +300,8 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
Index: 

[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:303
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"

can you also have a test in which we insert "d.h" and it gets put into the 
right place?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

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


[PATCH] D151697: [clang] Add test for CWG1710 and related issues

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bbaabb90dd7: [clang] Add test for CWG1710 and related 
issues (authored by Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151697

Files:
  clang/test/CXX/drs/dr17xx.cpp
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -1923,7 +1923,7 @@
 https://cplusplus.github.io/CWG/issues/314.html;>314
 C++17
 template in base class specifier
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/315.html;>315
@@ -2097,7 +2097,7 @@
 https://cplusplus.github.io/CWG/issues/343.html;>343
 C++17
 Make template optional in contexts that require a type
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/344.html;>344
@@ -10067,7 +10067,7 @@
 https://cplusplus.github.io/CWG/issues/1710.html;>1710
 C++17
 Missing template keyword in class-or-decltype
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/1711.html;>1711
@@ -10571,7 +10571,7 @@
 https://cplusplus.github.io/CWG/issues/1794.html;>1794
 C++17
 template keyword and alias templates
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/1795.html;>1795
@@ -10679,7 +10679,7 @@
 https://cplusplus.github.io/CWG/issues/1812.html;>1812
 C++17
 Omission of template in a typename-specifier
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/1813.html;>1813
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -208,14 +208,20 @@
 #endif
 }
 
-namespace dr314 { // FIXME 314: dup 1710
-  template struct A {
-template struct B {};
-  };
-  template struct C : public A::template B {
-C() : A::template B() {}
-  };
-}
+namespace dr314 { // dr314: no
+  // NB: dup 1710
+template  struct A {
+  template  struct B {};
+};
+template  struct C : public A::template B {
+  C() : A::template B() {}
+};
+template  struct C2 : public A::B {
+  // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+  C2() : A::B() {}
+  // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+};
+} // namespace dr314
 
 // dr315: na
 // dr316: sup 1004
@@ -591,7 +597,7 @@
 
 // dr342: na
 
-namespace dr343 { // FIXME 343: no
+namespace dr343 { // dr343: no
   // FIXME: dup 1710
   template struct A {
 template struct B {};
Index: clang/test/CXX/drs/dr18xx.cpp
===
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -4,12 +4,23 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr1812 { // dr1812: no
+   // NB: dup 1710
+#if __cplusplus >= 201103L
+template  struct A {
+  using B = typename T::C;
+  // expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
+};
+#endif
+} // namespace dr1812
+
 namespace dr1813 { // dr1813: 7
   struct B { int i; };
   struct C : B {};
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -1,7 +1,22 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions 

[clang] 1bbaabb - [clang] Add test for CWG1710 and related issues

2023-07-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-07-11T16:24:39+03:00
New Revision: 1bbaabb90dd72f78ea290b71dfe3bf2689ad7403

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

LOG: [clang] Add test for CWG1710 and related issues

Those issues focus on `template` keyword being optional in certain type-only 
contexts (base specifiers, member initializers, typename specifiers), as 
opposed to be disallowed by the grammar, or required by some implementations. 
GCC accepts all the tests this patch touches since 10, others fail on various 
tests: https://godbolt.org/z/1M6KE3W1a

It should be noted that the wording in [[ 
https://cplusplus.github.io/CWG/issues/1710.html | 1710 ]] that resolves those 
issues has been substantially changed by [[ https://wg21.link/p1787 | P1787 ]]. 
I can't find the post-P1787 wording that covers those issues, but I can't find 
the intent of changing relevant behavior in P1787 either, so I assume that 
intent of the 1710 resolution is preserved somewhere.

This patch covers the following issues:
[[ https://cplusplus.github.io/CWG/issues/314.html  | CWG314 ]]
[[ https://cplusplus.github.io/CWG/issues/343.html  | CWG343 ]]
[[ https://cplusplus.github.io/CWG/issues/1710.html | CWG1710 ]]
[[ https://cplusplus.github.io/CWG/issues/1794.html | CWG1794 ]]
[[ https://cplusplus.github.io/CWG/issues/1812.html | CWG1812 ]]

Reviewed By: #clang-language-wg, cor3ntin

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

Added: 


Modified: 
clang/test/CXX/drs/dr17xx.cpp
clang/test/CXX/drs/dr18xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index e91f4a6d69b3ac..219119d1a4cd08 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -1,7 +1,22 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+
+namespace dr1710 { // dr1710: no
+// FIXME: all of the following is well-formed
+template  struct D1 : T::template B::template C {};
+template  struct D2 : T::B::template C {};
+// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent 
template name}}
+template  struct D3 : T::template B::C {};
+// expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent 
template name}}
+template  struct D4 : T::B::C {};
+// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent 
template name}}
+// expected-error@-2 {{use 'template' keyword to treat 'C' as a dependent 
template name}}
+} // namespace dr1710
 
 namespace dr1715 { // dr1715: 3.9
 #if __cplusplus >= 201103L
@@ -146,3 +161,18 @@ namespace dr1778 { // dr1778: 9
   static_assert(noexcept(D()), "");
 #endif
 }
+
+namespace dr1794 { // dr1794: yes
+   // NB: dup 1710
+#if __cplusplus >= 201103L
+template  class Template> struct Internal {
+  template  using Bind = Template;
+};
+
+template  class Template, typename Arg>
+using Instantiate = Template;
+
+template  class Template, typename Argument>
+using Bind = Instantiate::template Bind, Argument>;
+#endif
+} // namespace dr1794

diff  --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 3d57f5e5b74dbd..7ac26737382281 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -4,12 +4,23 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr1812 { // dr1812: no
+   // NB: dup 1710

[PATCH] D154827: [analyzer] NonParamVarRegion should prefer definition over canonical decl

2023-07-11 Thread Balázs Benics 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 rGffcf214b5d27: [analyzer] NonParamVarRegion should prefer 
definition over canonical decl (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D154827?vs=538567=538927#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154827

Files:
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/globals.c


Index: clang/test/Analysis/globals.c
===
--- /dev/null
+++ clang/test/Analysis/globals.c
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+typedef typeof(sizeof(int)) size_t;
+size_t clang_analyzer_getExtent(const void *p);
+void clang_analyzer_dump(size_t n);
+
+extern const unsigned char extern_redecl[];
+const unsigned char extern_redecl[] = { 1,2,3,4 };
+const unsigned char tentative_redecl[];
+const unsigned char tentative_redecl[] = { 1,2,3,4 };
+
+const unsigned char direct_decl[] = { 1,2,3,4 };
+
+void test_redeclaration_extent(void) {
+  clang_analyzer_dump(clang_analyzer_getExtent(direct_decl));  // 
expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(extern_redecl));// 
expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(tentative_redecl)); // 
expected-warning {{4 S64b}}
+}
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1077,13 +1077,16 @@
 }
   }
 
-  return getSubRegion(D, sReg);
+  return getNonParamVarRegion(D, sReg);
 }
 
 const NonParamVarRegion *
 MemRegionManager::getNonParamVarRegion(const VarDecl *D,
const MemRegion *superR) {
+  // Prefer the definition over the canonical decl as the canonical form.
   D = D->getCanonicalDecl();
+  if (const VarDecl *Def = D->getDefinition())
+D = Def;
   return getSubRegion(D, superR);
 }
 


Index: clang/test/Analysis/globals.c
===
--- /dev/null
+++ clang/test/Analysis/globals.c
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+typedef typeof(sizeof(int)) size_t;
+size_t clang_analyzer_getExtent(const void *p);
+void clang_analyzer_dump(size_t n);
+
+extern const unsigned char extern_redecl[];
+const unsigned char extern_redecl[] = { 1,2,3,4 };
+const unsigned char tentative_redecl[];
+const unsigned char tentative_redecl[] = { 1,2,3,4 };
+
+const unsigned char direct_decl[] = { 1,2,3,4 };
+
+void test_redeclaration_extent(void) {
+  clang_analyzer_dump(clang_analyzer_getExtent(direct_decl));  // expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(extern_redecl));// expected-warning {{4 S64b}}
+  clang_analyzer_dump(clang_analyzer_getExtent(tentative_redecl)); // expected-warning {{4 S64b}}
+}
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1077,13 +1077,16 @@
 }
   }
 
-  return getSubRegion(D, sReg);
+  return getNonParamVarRegion(D, sReg);
 }
 
 const NonParamVarRegion *
 MemRegionManager::getNonParamVarRegion(const VarDecl *D,
const MemRegion *superR) {
+  // Prefer the definition over the canonical decl as the canonical form.
   D = D->getCanonicalDecl();
+  if (const VarDecl *Def = D->getDefinition())
+D = Def;
   return getSubRegion(D, superR);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154928: [clang][Interp] Call dtor or Floating values

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  The APFloat might heap-allocate some memory, so we need to call its
  destructor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154928

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -137,3 +137,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -189,6 +189,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -137,3 +137,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -189,6 +189,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154910: [ARM][AArch64] Make ACLE __clzl/__clzll return unsigned int instead of unsigned long/uint64_t.

2023-07-11 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision is now accepted and ready to land.

LGTM, thanks. Seems odd that the ACLE mixes `uint32_t` and `unsigned int`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154910

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


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:95
-  StructValue *SVal = clang::dyn_cast(Val);
-  ASSERT_NE(SVal, nullptr);
-  Val = SVal->getChild(*R);

Using the opportunity to simplify the code here a bit: If we `cast<>`, we don't 
need to assert for non-nullness because `cast<>` already does that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

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


[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-11 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

This is a bit confusing but I think it is correct.
LGTM modulo typos.




Comment at: clang/docs/ReleaseNotes.rst:70
 ---
-- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
-  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
+- Two bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable before.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-11 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 539017.
koops added a comment.

1. Taking care of Alexy & David suggestions: a) Using update_cc_test_checks.py 
to generate CHECK statements. b) Change in error message from "handled" to 
"allowed". c) Adding comments for the bind clause. d) Mangled names of the 
functions in the CHECK statements are more generic with regular expressions.


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

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/generic_loop_ast_print.cpp
  clang/test/OpenMP/loop_bind_codegen.cpp
  clang/test/OpenMP/loop_bind_enclosed.cpp
  clang/test/OpenMP/loop_bind_messages.cpp
  clang/test/OpenMP/nested_loop_codegen.cpp

Index: clang/test/OpenMP/nested_loop_codegen.cpp
===
--- clang/test/OpenMP/nested_loop_codegen.cpp
+++ clang/test/OpenMP/nested_loop_codegen.cpp
@@ -58,6 +58,12 @@
 // CHECK1-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
+// CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IV:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_LB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_UB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
@@ -66,35 +72,27 @@
 // CHECK1-NEXT:store i32 0, ptr [[TMP0]], align 4
 // CHECK1-NEXT:br label [[FOR_COND:%.*]]
 // CHECK1:   for.cond:
-// CHECK1-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 10
-// CHECK1-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END7:%.*]]
 // CHECK1:   for.body:
-// CHECK1-NEXT:store i32 0, ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1:%.*]]
-// CHECK1:   for.cond1:
-// CHECK1-NEXT:[[TMP2:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[CMP2:%.*]] = icmp slt i32 [[TMP2]], 5
-// CHECK1-NEXT:br i1 [[CMP2]], label [[FOR_BODY3:%.*]], label [[FOR_END:%.*]]
-// CHECK1:   for.body3:
-// CHECK1-NEXT:[[TMP3:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC:%.*]] = add nsw i32 [[TMP3]], 1
-// CHECK1-NEXT:store i32 [[INC]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_INC:%.*]]
-// CHECK1:   for.inc:
-// CHECK1-NEXT:[[TMP4:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC4:%.*]] = add nsw i32 [[TMP4]], 1
-// CHECK1-NEXT:store i32 [[INC4]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1]], !llvm.loop [[LOOP3:![0-9]+]]
-// CHECK1:   for.end:
-// CHECK1-NEXT:br label [[FOR_INC5:%.*]]
-// CHECK1:   for.inc5:
-// CHECK1-NEXT:[[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[INC6:%.*]] = add nsw i32 [[TMP5]], 1
-// CHECK1-NEXT:store i32 [[INC6]], ptr [[TMP0]], align 4
-// CHECK1-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP5:![0-9]+]]
-// CHECK1:   for.end7:
-// CHECK1-NEXT:ret void
+// CHECK1-NEXT [[TMP2:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_init_4(ptr @1, i32 [[TMP3]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+//CHECK1 cond.end:
+//CHECK1 omp.inner.for.cond:
+//CHECK1 omp.inner.for.body:
+//CHECK1 omp.body.continue:
+//CHECK1 omp.inner.for.inc:
+//CHECK1 omp.inner.for.end:
+//CHECK1 omp.loop.exit:
+// CHECK1-NEXT [[TMP13:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP14:%.*]] = load i32, ptr [[TMP12]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_fini(ptr @1, i32 [[TMP14]])
+// CHECK1-NEXT [[TMP15:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP16:%.*]] = load i32, ptr [[TMP15]], align 4
+// CHECK1-NEXT call void @__kmpc_barrier(ptr @2, i32 [[TMP16]])
+//CHECK1 for.inc:
+//CHECK1 for.end:
+// CHECK1-NEXT ret void
+//
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@_Z11inline_declv
@@ -114,45 +112,36 @@
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[RES_ADDR:%.*]] = alloca ptr, align 8
-// CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8

[PATCH] D154951: [clang][Interp] __builtin_bit_cast, Take 2

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements `__builtin_bit_cast()`.

The new opcodes are `BitCast`, which bitcasts to a non-floating primitive type, 
`BitCastFP`, which bitcasts to a floating type, and `BitCastPtr`, which 
bitcasts to a composite type. Everything is implemented in `InterpBitcast.cpp`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154951

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBitcast.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/builtin-bit-cast.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -98,6 +98,11 @@
 static_assert(p != nullptr, "");
 static_assert(*p == 10, "");
 
+constexpr const void *cp = (void *)p;
+// FIXME: This should be an error in the new interpreter.
+constexpr const int *pm = (int*)cp; // ref-error {{ must be initialized by a constant expression}} \
+// ref-note {{cast from 'const void *' is not allowed}}
+
 constexpr const int* getIntPointer() {
   return 
 }
Index: clang/test/AST/Interp/builtin-bit-cast.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtin-bit-cast.cpp
@@ -0,0 +1,683 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter -triple powerpc64le-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple powerpc64le-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter -triple powerpc64-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple powerpc64-unknown-unknown -mabi=ieeelongdouble %s
+
+/// FIXME: This is a version of
+///   clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp with the currently
+///   supported subset of operations. They should *all* be supported though.
+
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define LITTLE_END 0
+#else
+#  error "huh?"
+#endif
+
+typedef decltype(nullptr) nullptr_t;
+
+static_assert(sizeof(int) == 4);
+static_assert(sizeof(long long) == 8);
+
+template 
+constexpr To bit_cast(const From ) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from); // ref-note 2{{indeterminate value can only initialize}} \
+   // expected-note 2{{indeterminate value can only initialize}}
+}
+
+template 
+constexpr bool round_trip(const Init ) {
+  return bit_cast(bit_cast(init)) == init;
+}
+
+/// We can ignore it.
+constexpr int foo() {
+  (void)__builtin_bit_cast(int, 3);
+  return 1;
+}
+static_assert(foo() == 1, "");
+
+namespace Ints {
+  static_assert(round_trip((int)-1));
+  static_assert(round_trip((int)0x12345678));
+  static_assert(round_trip((int)0x87654321));
+  static_assert(round_trip((int)0x0C05FEFE));
+  static_assert(round_trip((int)0x0C05FEFE));
+}
+
+namespace FloatToDouble {
+  constexpr float F1[] = {1.0f, 2.0f};
+  constexpr double D1 = __builtin_bit_cast(double, F1);
+  static_assert(D1 > 0);
+}
+
+namespace Arrays {
+  constexpr unsigned char input[] = {0xCA, 0xFE, 0xBA, 0xBE};
+  constexpr unsigned expected = LITTLE_END ? 0xBEBAFECA : 0xCAFEBABE;
+  static_assert(bit_cast(input) == expected);
+
+  constexpr short S[] = {10, 20};
+  constexpr int I = __builtin_bit_cast(int, S);
+  static_assert(I == (LITTLE_END ? 1310730 : 655380));
+}
+
+struct int_splicer {
+  unsigned x;
+  unsigned y;
+
+  constexpr int_splicer() : x(1), y(2) {}
+  constexpr int_splicer(unsigned x, unsigned y) : x(x), y(y) {}
+
+  constexpr bool operator==(const int_splicer ) const {
+return other.x == x && other.y == y;
+  }
+};
+
+constexpr int_splicer splice(0x0C05FEFE, 0xCAFEBABE);
+
+static_assert(bit_cast(splice) == (LITTLE_END
+  

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Ah, the patch summary probably needs some update as well. We no longer care 
about version 0 and the backend changes for `R_LARCH_64_PCREL` are already in, 
for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Thanks for following up with the suggestions. This now looks mostly okay to me; 
let's wait for more people to chip in!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-07-11 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D154784#4486721 , @rjmccall wrote:

> We had that discussion in the bug report.  Let's just increase the widths 
> unconditionally; this is not such a common expression class that we need to 
> worry about using an extra word.

Thanks for your review!

> Let's just increase the widths unconditionally

Do you mean:

  class PseudoObjectExprBitfields {
  friend class ASTStmtReader; // deserialization
  friend class PseudoObjectExpr;
  
  unsigned : NumExprBits;
  unsigned NumSubExprs : 16;
  unsigned ResultIndex : 16;
};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154784

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


[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-11 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 updated this revision to Diff 539031.
simpal01 added a comment.

Addressing Review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154786

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/baremetal.cpp

Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECk-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include"
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
@@ -34,7 +34,7 @@
 // CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
 // CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
 // CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
@@ -42,7 +42,7 @@
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
 // CHECK-V6M-LIBCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
-// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBSTDCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-V6M-LIBSTDCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}6.0.0"
-// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
@@ -77,7 +77,7 @@
 // RUN: -nodefaultlibs \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
 // CHECK-V6M-NDL: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-NDL: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-NDL: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-NDL-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-NDL-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 
@@ -117,6 +117,46 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
 // CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"
 
+// RUN: %clang -### %s --target=armebv7-none-eabi --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+// CHECK-ARMV7EB: "{{.*}}ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "--be8" "-EB"
+
+// RUN: %clang -### %s --target=armv7-none-eabi -mbig-endian --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -### %s --target=armebv7-none-eabi -mbig-endian --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -### %s --target=armv7-none-eabi --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | 

[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-07-11 Thread Petr Hosek via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
phosek marked an inline comment as done.
Closed by commit rGdae9d1b52469: [compiler-rt] Move crt into builtins (authored 
by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D153989?vs=535452=538935#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/builtins/crtbegin.c
  compiler-rt/lib/builtins/crtend.c
  compiler-rt/lib/crt/CMakeLists.txt
  compiler-rt/lib/crt/crtbegin.c
  compiler-rt/lib/crt/crtend.c
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/builtins/CMakeLists.txt
  compiler-rt/test/builtins/Unit/ctor_dtor.c
  compiler-rt/test/builtins/Unit/dso_handle.cpp
  compiler-rt/test/builtins/Unit/lit.cfg.py
  compiler-rt/test/builtins/Unit/lit.site.cfg.py.in
  compiler-rt/test/crt/CMakeLists.txt
  compiler-rt/test/crt/ctor_dtor.c
  compiler-rt/test/crt/dso_handle.cpp
  compiler-rt/test/crt/lit.cfg.py
  compiler-rt/test/crt/lit.site.cfg.py.in

Index: compiler-rt/test/crt/lit.site.cfg.py.in
===
--- compiler-rt/test/crt/lit.site.cfg.py.in
+++ /dev/null
@@ -1,14 +0,0 @@
-@LIT_SITE_CFG_IN_HEADER@
-
-# Tool-specific config options.
-config.name_suffix = "@CRT_TEST_CONFIG_SUFFIX@"
-config.crt_lit_source_dir = "@CRT_LIT_SOURCE_DIR@"
-config.target_cflags = "@CRT_TEST_TARGET_CFLAGS@"
-config.target_arch = "@CRT_TEST_TARGET_ARCH@"
-config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@"
-
-# Load common config for all compiler-rt lit tests
-lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
-
-# Load tool-specific config that would do the real work.
-lit_config.load_config(config, "@CRT_LIT_SOURCE_DIR@/lit.cfg.py")
Index: compiler-rt/test/crt/lit.cfg.py
===
--- compiler-rt/test/crt/lit.cfg.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# -*- Python -*-
-
-import os
-import subprocess
-import shlex
-
-# Setup config name.
-config.name = "CRT" + config.name_suffix
-
-# Setup source root.
-config.test_source_root = os.path.dirname(__file__)
-
-
-# Choose between lit's internal shell pipeline runner and a real shell.  If
-# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
-use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
-if use_lit_shell:
-# 0 is external, "" is default, and everything else is internal.
-execute_external = use_lit_shell == "0"
-else:
-# Otherwise we default to internal on Windows and external elsewhere, as
-# bash on Windows is usually very slow.
-execute_external = not sys.platform in ["win32"]
-
-
-def get_library_path(file):
-cmd = subprocess.Popen(
-[config.clang.strip(), "-print-file-name=%s" % file]
-+ shlex.split(config.target_cflags),
-stdout=subprocess.PIPE,
-env=config.environment,
-universal_newlines=True,
-)
-if not cmd.stdout:
-lit_config.fatal("Couldn't find the library path for '%s'" % file)
-dir = cmd.stdout.read().strip()
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-dir = dir.replace("\\", "/")
-return dir
-
-
-def get_libgcc_file_name():
-cmd = subprocess.Popen(
-[config.clang.strip(), "-print-libgcc-file-name"]
-+ shlex.split(config.target_cflags),
-stdout=subprocess.PIPE,
-env=config.environment,
-universal_newlines=True,
-)
-if not cmd.stdout:
-lit_config.fatal("Couldn't find the library path for '%s'" % file)
-dir = cmd.stdout.read().strip()
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-dir = dir.replace("\\", "/")
-return dir
-
-
-def build_invocation(compile_flags):
-return " " + " ".join([config.clang] + compile_flags) + " "
-
-
-# Setup substitutions.
-config.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
-config.substitutions.append(
-("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
-)
-
-base_lib = os.path.join(
-config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix
-)
-
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-base_lib = base_lib.replace("\\", "/")
-
-config.substitutions.append(("%crtbegin", base_lib % "crtbegin"))
-config.substitutions.append(("%crtend", base_lib % "crtend"))
-
-config.substitutions.append(("%crt1", get_library_path("crt1.o")))
-config.substitutions.append(("%crti", 

[PATCH] D154934: [clang][dataflow] Use `IntegerValue` instead of `StructValue` in `ValueTest`.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Soon, it will no longer be possible to default-construct `StructValue`.
For details, see https://discourse.llvm.org/t/70086.

For completeness, also add a test that `areEquivalentValues()` on different
`IntegerValue`s returns false.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154934

Files:
  clang/unittests/Analysis/FlowSensitive/ValueTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 133b2fc - [clang][Interp][NFC] Use template types instead of auto

2023-07-11 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-11T11:25:00+02:00
New Revision: 133b2fc9cc27d03f3f5f922ec7f058c3b617a1ea

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

LOG: [clang][Interp][NFC] Use template types instead of auto

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index fa2f9d5b242de9..e61d8e6dc7daf6 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -44,8 +44,8 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = ();
-auto Value = std::move(*Ptr);
+T *Ptr = ();
+T Value = std::move(*Ptr);
 Ptr->~T();
 shrink(aligned_size());
 return Value;
@@ -57,7 +57,7 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = ();
+T *Ptr = ();
 Ptr->~T();
 shrink(aligned_size());
   }



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


[PATCH] D154856: [MemProf] Use new option/pass for profile feedback and matching

2023-07-11 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

The preparation patch (https://reviews.llvm.org/D154872) caused the AMD GPU 
OpenMP buildbot to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154856

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


[PATCH] D154952: [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These simplify the code in their own right, but they are also useful in that
they minimize the number of changes that will need to be made when then API of
`AggregateStorageLocation` and `StructValue` changes as part of the migration to
strict handling of value categories (see https://discourse.llvm.org/t/70086).

Depends On D154949 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154952

Files:
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue (AggregateStorageLocation ,
+  Environment ) {
+  auto  = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models an analysis that uses flow conditions.
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
@@ -390,23 +397,18 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), 
*S,
   getASTContext( {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", 
match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(

SpecialBoolRecordDecl
  .bind("call"),
  *S, getASTContext( {
-  auto *Object = E->getImplicitObjectArgument();
-  assert(Object != nullptr);
-
-  auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
-  assert(ObjectLoc != nullptr);
+  auto  =
+  *cast(getImplicitObjectLocation(*E, Env));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("is_set", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -551,21 +553,19 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
-  assert(ObjectLoc != nullptr);
+  auto  = *cast(
+  Env.getStorageLocation(*Object, SkipPast::Reference));
 
-  auto  = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("has_value", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -1227,9 +1227,7 @@
 match(callExpr(callee(functionDecl(hasName("makeTop".bind("top"),
   *S, getASTContext());
 if (const auto *E = selectFirst("top", Matches)) {
-  auto  = Env.createStorageLocation(*E);
-  Env.setValue(Loc, Env.makeTopBoolValue());
-  Env.setStorageLocation(*E, Loc);
+  Env.setValueStrict(*E, Env.makeTopBoolValue());
 }
   }
 


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue (AggregateStorageLocation ,
+  Environment ) {
+  auto  = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models 

[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu 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 rG7f3d2cd7ec25: [include-cleaner] Fix the `fixIncludes` API 
not respect main-file header. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Results.Missing.push_back("\"d.h\"");
+  Code = R"cpp(#include "a.h")cpp";
+  // FIXME: this isn't correct, the main-file header d.h should be added before
+  // a.h.
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "a.h"
+#include "d.h"
 )cpp");
 }
 
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle ) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle );
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   

[clang-tools-extra] 7f3d2cd - [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-07-11T15:02:26+02:00
New Revision: 7f3d2cd7ec254cda659c5e5a19a42105e370e04c

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

LOG: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 547e9dd7261ca3..77be4f1dad5212 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@ analyze(llvm::ArrayRef ASTRoots,
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle );
 
 /// Gets all the providers for a symbol by traversing each location.

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 616eeae43a87ee..e76929f6824ce7 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@ analyze(llvm::ArrayRef ASTRoots,
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle ) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));

diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp 
b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index e7ae0c68c88214..c6cd7995d2e829 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@ class Action : public clang::ASTFrontendAction {
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index b6521d56bcff44..64dd6bc1e84cae 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@ TEST_F(AnalyzeTest, NoCrashWhenUnresolved) {
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@ TEST(FixIncludes, Basic) {
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Results.Missing.push_back("\"d.h\"");
+  Code = 

[PATCH] D154861: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 538929.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments and add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/SemaCXX/cxx11-crashes.cpp


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int (x);
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,12 @@
 - Stop evaluating a constant expression if the condition expression which in
   switch statement contains errors.
   (`#63453 _`)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int 

[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther added a comment.

> I think `&&` is cleaner: `return Triple.getOS() == llvm::Triple::UnknownOS && 
> ...`;

Totally agree. I was just following precedent there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154884: [clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl

2023-07-11 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 538940.
mikecrowe marked an inline comment as done.
mikecrowe added a comment.

Remove unnecessary init-statement and test case in commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154884

Files:
  clang-tools-extra/clang-tidy/utils/Matchers.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
@@ -3,7 +3,7 @@
 // RUN: [ \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.PrintfLikeFunctions, \
-// RUN:   value: '::myprintf; mynamespace::myprintf2' \
+// RUN:   value: 'unqualified_printf;::myprintf; 
mynamespace::myprintf2' \
 // RUN:  }, \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.FprintfLikeFunctions, \
@@ -14,7 +14,7 @@
 // RUN:   -- -isystem %clang_tidy_headers
 
 #include 
-#include 
+#include 
 
 int myprintf(const char *, ...);
 int myfprintf(FILE *fp, const char *, ...);
@@ -85,3 +85,10 @@
   // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead 
of 'myprintf' [modernize-use-std-print]
   // CHECK-FIXES-NOT: std::println(stderr, "return value {}", i);
 }
+
+// Ensure that MatchesAnyListedNameMatcher::NameMatcher::match() can cope with 
a
+// NamedDecl that has no name when we're trying to match unqualified_printf.
+void no_name(const std::string )
+{
+  "A" + in;
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -112,7 +112,9 @@
   case MatchMode::MatchFullyQualified:
 return Regex.match("::" + ND.getQualifiedNameAsString());
   default:
-return Regex.match(ND.getName());
+if (const IdentifierInfo *II = ND.getIdentifier())
+  return Regex.match(II->getName());
+return false;
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
@@ -3,7 +3,7 @@
 // RUN: [ \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.PrintfLikeFunctions, \
-// RUN:   value: '::myprintf; mynamespace::myprintf2' \
+// RUN:   value: 'unqualified_printf;::myprintf; mynamespace::myprintf2' \
 // RUN:  }, \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.FprintfLikeFunctions, \
@@ -14,7 +14,7 @@
 // RUN:   -- -isystem %clang_tidy_headers
 
 #include 
-#include 
+#include 
 
 int myprintf(const char *, ...);
 int myfprintf(FILE *fp, const char *, ...);
@@ -85,3 +85,10 @@
   // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead of 'myprintf' [modernize-use-std-print]
   // CHECK-FIXES-NOT: std::println(stderr, "return value {}", i);
 }
+
+// Ensure that MatchesAnyListedNameMatcher::NameMatcher::match() can cope with a
+// NamedDecl that has no name when we're trying to match unqualified_printf.
+void no_name(const std::string )
+{
+  "A" + in;
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -112,7 +112,9 @@
   case MatchMode::MatchFullyQualified:
 return Regex.match("::" + ND.getQualifiedNameAsString());
   default:
-return Regex.match(ND.getName());
+if (const IdentifierInfo *II = ND.getIdentifier())
+  return Regex.match(II->getName());
+return false;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@sammccall @nridge gentle ping~


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

https://reviews.llvm.org/D153114

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


[PATCH] D154884: [clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl

2023-07-11 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154884

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


[clang] 74258f4 - [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal conditionally

2023-07-11 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-07-11T16:13:06+08:00
New Revision: 74258f4189e2b6bacabd40ee6f588fd9d1b37741

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

LOG: [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal 
conditionally

Close https://github.com/llvm/llvm-project/issues/63544.

Background: We landed std modules in libcxx recently but we haven't
landed the corresponding in-tree tests. According to @Mordante, there
are only 1% libcxx tests failing with std modules. And the major
blocking issue is the lambda expression in the require clauses.

The root cause of the issue is that previously we never consider any
lambda expression as the same. Per [temp.over.link]p5:
> Two lambda-expressions are never considered equivalent.

I thought this is an oversight at first but @rsmith explains that in the
wording, the program is as if there is only a single definition, and a
single lambda-expression. So we don't need worry about this in the spec.
The explanation makes sense. But it didn't reflect to the implementation
directly.

Here is a cycle in the implementation. If we want to merge two
definitions, we need to make sure its implementation are the same. But
according to the explanation above, we need to judge if two
lambda-expression are the same by looking at its parent definitions. So
here is the problem.

To solve the problem, I think we have to profile the lambda expressions
actually to get the accurate information. But we can't do this
universally. So in this patch I tried to modify the interface of
`Stmt::Profile` and only profile the lambda expression during the
process of merging the constraint expressions.

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

Added: 
clang/test/Modules/merge-requires-with-lambdas.cppm
clang/test/Modules/pr63544.cppm

Modified: 
clang/include/clang/AST/Stmt.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/StmtProfile.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9a77f876c08ae7..156dd0a436a900 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1297,8 +1297,13 @@ class alignas(void *) Stmt {
   /// parameters are identified by index/level rather than their
   /// declaration pointers) or the exact representation of the statement as
   /// written in the source.
+  /// \param ProfileLambdaExpr whether or not to profile lambda expressions.
+  /// When false, the lambda expressions are never considered to be equal to
+  /// other lambda expressions. When true, the lambda expressions with the same
+  /// implementation will be considered to be the same. ProfileLambdaExpr 
should
+  /// only be true when we try to merge two declarations within modules.
   void Profile(llvm::FoldingSetNodeID , const ASTContext ,
-   bool Canonical) const;
+   bool Canonical, bool ProfileLambdaExpr = false) const;
 
   /// Calculate a unique representation for a statement that is
   /// stable across compiler invocations.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2b84673cf6b8fc..7acacd7bf4f504 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6328,8 +6328,8 @@ bool ASTContext::isSameConstraintExpr(const Expr *XCE, 
const Expr *YCE) const {
 return true;
 
   llvm::FoldingSetNodeID XCEID, YCEID;
-  XCE->Profile(XCEID, *this, /*Canonical=*/true);
-  YCE->Profile(YCEID, *this, /*Canonical=*/true);
+  XCE->Profile(XCEID, *this, /*Canonical=*/true, /*ProfileLambdaExpr=*/true);
+  YCE->Profile(YCEID, *this, /*Canonical=*/true, /*ProfileLambdaExpr=*/true);
   return XCEID == YCEID;
 }
 
@@ -6694,13 +6694,8 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
 // ConceptDecl wouldn't be the same if their constraint expression 
diff ers.
 if (const auto *ConceptX = dyn_cast(X)) {
   const auto *ConceptY = cast(Y);
-  const Expr *XCE = ConceptX->getConstraintExpr();
-  const Expr *YCE = ConceptY->getConstraintExpr();
-  assert(XCE && YCE && "ConceptDecl without constraint expression?");
-  llvm::FoldingSetNodeID XID, YID;
-  XCE->Profile(XID, *this, /*Canonical=*/true);
-  YCE->Profile(YID, *this, /*Canonical=*/true);
-  if (XID != YID)
+  if (!isSameConstraintExpr(ConceptX->getConstraintExpr(),
+ConceptY->getConstraintExpr()))
 return false;
 }
 

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index a9c4e14e87eff3..307ad4925d36b7 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -29,10 +29,12 @@ namespace {
   protected:
 llvm::FoldingSetNodeID 
 bool Canonical;
+bool 

[PATCH] D153957: [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal conditionally

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74258f4189e2: [C++20] [Modules] Allow Stmt::Profile to treat 
lambdas as equal conditionally (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153957

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/test/Modules/merge-requires-with-lambdas.cppm
  clang/test/Modules/pr63544.cppm

Index: clang/test/Modules/pr63544.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63544.cppm
@@ -0,0 +1,88 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/m-a.pcm
+// RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/m-b.pcm
+// RUN: %clang_cc1 -std=c++23 %t/m.cppm -emit-module-interface -o %t/m.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++23 %t/pr63544.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- foo.h
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+namespace std {
+template 
+class optional {
+private:
+using value_type = _Tp;
+value_type __val_;
+bool __engaged_;
+public:
+constexpr bool has_value() const noexcept
+{
+return this->__engaged_;
+}
+
+constexpr const value_type& operator*() const& noexcept
+{
+return __val_;
+}
+
+optional(_Tp v) : __val_(v) {
+__engaged_ = true;
+}
+};
+
+template 
+concept __is_derived_from_optional = requires(const _Tp& __t) { [](const optional<__Up>&) {}(__t); };
+
+template 
+requires(!__is_derived_from_optional<_Up>)
+constexpr strong_ordering
+operator<=>(const optional<_Tp>& __x, const _Up& __v) {
+return __x.has_value() ? *__x <=> __v : strong_ordering::less;
+}
+} // namespace std
+
+//--- a.cppm
+module;
+#include "foo.h"
+export module m:a;
+export namespace std {
+using std::optional;
+using std::operator<=>;
+}
+
+//--- b.cppm
+module;
+#include "foo.h"
+export module m:b;
+export namespace std {
+using std::optional;
+using std::operator<=>;
+}
+
+//--- m.cppm
+export module m;
+export import :a;
+export import :b;
+
+//--- pr63544.cpp
+// expected-no-diagnostics
+import m;
+int pr63544() {
+std::optional a(43);
+int t{3};
+return a<=>t;
+}
Index: clang/test/Modules/merge-requires-with-lambdas.cppm
===
--- /dev/null
+++ clang/test/Modules/merge-requires-with-lambdas.cppm
@@ -0,0 +1,100 @@
+// Tests that we can merge the concept declarations with lambda well.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/A0.cppm -emit-module-interface -o %t/A0.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A1.cppm -emit-module-interface -o %t/A1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA1.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A2.cppm -emit-module-interface -o %t/A2.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA2.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A3.cppm -emit-module-interface -o %t/A3.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA3.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- A.h
+template 
+concept A = requires(const _Tp& __t) { [](const __Up&) {}(__t); };
+
+//--- A1.h
+template 
+concept A = requires(const _Tp& __t) { [](__Up) {}(__t); };
+
+//--- A2.h
+template 
+concept A = requires(const _Tp& __t) { [](const __Up& __u) {
+(int)__u;
+}(__t); };
+
+//--- A3.h
+template 
+concept A = requires(const _Tp& __t) { [t = '?'](const __Up&) {
+(int)t;
+}(__t); };
+
+//--- A.cppm
+module;
+#include "A.h"
+export module A;
+export using ::A;
+
+//--- A0.cppm
+module;
+#include "A.h"
+export module A0;
+export using ::A;
+
+//--- TestA.cpp
+// expected-no-diagnostics
+import A;
+import A0;
+
+template 
+void f(C) requires(A) {}
+
+//--- A1.cppm
+module;
+#include "A1.h"
+export module A1;
+export using ::A;
+
+//--- TestA1.cpp
+import A;
+import A1;
+
+template 
+void f(C) requires(A) {} // expected-error 1+{{reference to 'A' is ambiguous}}
+// 

[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError and use it throughout ASTImporter

2023-07-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D154709#4487776 , @balazske wrote:

> The goal is to have a message always in `ASTImportError`? Then probably the 
> constructor without message can be removed, at least to check if really the 
> message is added at all places. I found that it is missing in 
> `VisitObjCImplementationDecl`.

Agree, will do that

> I do not know what happens with messages passed to FromDiag or ToDiag and if 
> these are available somehow to LLDB.

Ideally yes, but I found they're not very helpful in LLDB's use-case because:

1. the diagnostic doesn't get issued at all call-sites
2. LLDB switches off any `odr` related warnings because AFAIU they occur a lot 
(outside the ASTImporter) and would flood the user with redundant information

> Otherwise it would be even better to remove all FromDiag and ToDiag messages 
> from ASTImporter and put these messages into ASTImportError and use later in 
> the way that is needed by the use case. This would require to pass a message 
> to HandleNameConflict but then we have always the detailed message. There are 
> places where diagnostic is generated but there is no error, we should check 
> if this is correct and if we can remove the diagnostic or make import error.

That sounds like a good way forward. The `-ast-merge` clang option does benefit 
from these diagnostics. So we would probably need to change it to dump the 
`ASTImportError` instead of relying on the diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

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


[PATCH] D154949: [clang][dataflow] Use `getFieldValue()` in TransferTest.cpp.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For context, see https://reviews.llvm.org/D154935.

Depends On D154935 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154949

Files:
  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
@@ -262,7 +262,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -310,7 +311,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -357,7 +359,8 @@
 cast(>getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -470,37 +473,37 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooReferentVal = cast(Env.getValue(*FooLoc));
+const auto  =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto  = *cast(Env.getValue(FooLoc));
 
-const auto *BarVal =
-cast(FooReferentVal->getChild(*BarDecl));
-const auto *BarReferentVal =
-cast(Env.getValue(BarVal->getReferentLoc()));
+const auto  =
+*cast(FooReferentVal.getChild(*BarDecl));
+const auto  =
+*cast(Env.getValue(BarVal.getReferentLoc()));
 
-const auto *FooRefVal =
-cast(BarReferentVal->getChild(*FooRefDecl));
+const auto  =
+*cast(getFieldValue(, *FooRefDecl, Env));
 const auto  =
-cast(FooRefVal->getReferentLoc());
+cast(FooRefVal.getReferentLoc());
 EXPECT_THAT(Env.getValue(FooReferentLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooReferentLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *FooPtrVal =
-cast(BarReferentVal->getChild(*FooPtrDecl));
+const auto  =
+*cast(getFieldValue(, *FooPtrDecl, Env));
 const auto  =
-cast(FooPtrVal->getPointeeLoc());
+cast(FooPtrVal.getPointeeLoc());
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooPtrPointeeLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(, *BarDecl, Env), IsNull());
 
-const auto *BazRefVal =
-cast(BarReferentVal->getChild(*BazRefDecl));
-const StorageLocation  = BazRefVal->getReferentLoc();
+const auto  =
+*cast(getFieldValue(, *BazRefDecl, Env));
+const StorageLocation  = BazRefVal.getReferentLoc();
 EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
 
-const auto *BazPtrVal =
-cast(BarReferentVal->getChild(*BazPtrDecl));
-const StorageLocation  = BazPtrVal->getPointeeLoc();
+const auto  =
+*cast(getFieldValue(, *BazPtrDecl, Env));
+const StorageLocation  = BazPtrVal.getPointeeLoc();
 EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
   });
 }
@@ -630,35 +633,36 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *FooPointeeVal =
-cast(Env.getValue(FooVal->getPointeeLoc()));
-
-const auto *BarVal =
-cast(FooPointeeVal->getChild(*BarDecl));
-const auto *BarPointeeVal =
-cast(Env.getValue(BarVal->getPointeeLoc()));
-
-const auto *FooRefVal =
-cast(BarPointeeVal->getChild(*FooRefDecl));
-const StorageLocation  = FooRefVal->getReferentLoc();
+const auto  =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto  = *cast(Env.getValue(FooLoc));
+const auto  =
+*cast(Env.getValue(FooVal.getPointeeLoc()));
+
+const auto  =
+*cast(getFieldValue(, *BarDecl, Env));
+const auto  =
+  

[PATCH] D154952: [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:400
   getASTContext( {
-  auto  = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));

This works because we know that constructor has already created a fresh value 
for `E`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154952

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


[PATCH] D153339: [clang] Support vectors in __builtin_isfpclass

2023-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This seems reasonable to me, but I do wonder if changing the return type from 
int to bool will cause surprises for anyone. I see why it's done, but this 
seems more like a C interface (to me) which would return an `int`; returning a 
`bool` gets promoted to `int` when you sneeze near it, so I wonder about 
performance implications. But at the same time, we wouldn't want a vector of 
ints returns in the vector case, I would suspect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153339

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


[PATCH] D152632: [Clang] Add warnings for CWG2521

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill accepted this revision as: Endill.
Endill added a comment.

DR testing side looks good, but you should wait for more approvals.
Thank you for addressing all the issues there!


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

https://reviews.llvm.org/D152632

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


[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

2023-07-11 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 but please land with a release note.




Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:66
   .y = 1, // override-note {{previous}}
-  .y = 1, // override-error {{overrides prior initialization}}
+  .y = 1, // override-error {{overrides prior initialization}} // reorder-note 
{{previous initialization for field 'y' is here}}
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides 
prior initialization}} override-note {{previous}}

shafik wrote:
> aaron.ballman wrote:
> > A few questions: 1) what is this new note attached to? The only `reorder-*` 
> > diagnostic I see in the test is for the initialization of `x`. 2) is the 
> > note actually on the correct previous use? I would have expected this to be 
> > on the assignment to `y` one line above.
> It is attached to :
> 
> ```
> .x = 1, // reorder-error {{declaration order}}
> ```
> 
> We were not issuing it before b/c it was broken, in this case it was just not 
> crashing but it was still broken.
> 
> We could argue the note should go on the first `.y` although I could see both 
> sides since the override is a warning and not an error I think using the 
> second is defensible. 
> 
> 
Oh! I had a brain fart and thought this was about *re*initialization of `y`. I 
see what's going on now and yeah, this makes sense. I'm not worried about which 
`y` the note attaches to.


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

https://reviews.llvm.org/D154675

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


[clang] 3ab7ef2 - Revert "[MemProf] Use new option/pass for profile feedback and matching"

2023-07-11 Thread JP Lehr via cfe-commits

Author: JP Lehr
Date: 2023-07-11T05:44:42-04:00
New Revision: 3ab7ef28eebf9019eb3d3c4efd7ebfd160106bb1

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

LOG: Revert "[MemProf] Use new option/pass for profile feedback and matching"

This reverts commit b4a82b62258c5f650a1cccf5b179933e6bae4867.

Broke AMDGPU OpenMP Offload buildbot

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/memprof.cpp
clang/test/Driver/fmemprof.cpp
llvm/include/llvm/Support/PGOOptions.h
llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Support/PGOOptions.cpp
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/memprof.ll
llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll
llvm/tools/opt/NewPMDriver.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index fadfff48582eea..b0f22411e1ad20 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -282,9 +282,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Name of the profile file to use as output for with -fmemory-profile.
   std::string MemoryProfileOutput;
 
-  /// Name of the profile file to use as input for -fmemory-profile-use.
-  std::string MemoryProfileUsePath;
-
   /// Name of the profile file to use as input for -fprofile-instr-use
   std::string ProfileInstrumentUsePath;
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c5230d11baeddf..a34eab4064997a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1772,10 +1772,6 @@ defm memory_profile : OptInCC1FFlag<"memory-profile", 
"Enable", "Disable", " hea
 def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
 Group, Flags<[CC1Option]>, MetaVarName<"">,
 HelpText<"Enable heap memory profiling and dump results into ">;
-def fmemory_profile_use_EQ : Joined<["-"], "fmemory-profile-use=">,
-Group, Flags<[CC1Option, CoreOption]>, MetaVarName<"">,
-HelpText<"Use memory profile for profile-guided memory optimization">,
-MarshallingInfoString>;
 
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 06af08023d1be9..458756509b3a3d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -762,37 +762,31 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 PGOOpt = PGOOptions(
 CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
: 
CodeGenOpts.InstrProfileOutput,
-"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
-PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
+"", "", nullptr, PGOOptions::IRInstr, PGOOptions::NoCSAction,
+CodeGenOpts.DebugInfoForProfiling);
   else if (CodeGenOpts.hasProfileIRUse()) {
 // -fprofile-use.
 auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
 : PGOOptions::NoCSAction;
-PGOOpt = PGOOptions(
-CodeGenOpts.ProfileInstrumentUsePath, "",
-CodeGenOpts.ProfileRemappingFile, CodeGenOpts.MemoryProfileUsePath, 
VFS,
-PGOOptions::IRUse, CSAction, CodeGenOpts.DebugInfoForProfiling);
+PGOOpt =
+PGOOptions(CodeGenOpts.ProfileInstrumentUsePath, "",
+   CodeGenOpts.ProfileRemappingFile, VFS, PGOOptions::IRUse,
+   CSAction, CodeGenOpts.DebugInfoForProfiling);
   } else if (!CodeGenOpts.SampleProfileFile.empty())
 // -fprofile-sample-use
 PGOOpt = PGOOptions(
 CodeGenOpts.SampleProfileFile, "", CodeGenOpts.ProfileRemappingFile,
-CodeGenOpts.MemoryProfileUsePath, VFS, PGOOptions::SampleUse,
-PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
-CodeGenOpts.PseudoProbeForProfiling);
-  else if (!CodeGenOpts.MemoryProfileUsePath.empty())
-// -fmemory-profile-use (without any of the above options)
-PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath, VFS,
-PGOOptions::NoAction, PGOOptions::NoCSAction,
-CodeGenOpts.DebugInfoForProfiling);

[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther updated this revision to Diff 539033.
cwalther added a comment.

Updated patch according to current discussion:

- remove check for vendor, any vendor is accepted
- replace cascaded `if` by `&&`
- rebase on main a3f9ce6 



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

https://reviews.llvm.org/D154357

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -345,6 +345,58 @@
 // CHECK-RV32IMAFC-SAME: 
"-L[[SYSROOT:[^"]+]]{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f{{[/\\]+}}lib"
 // CHECK-RV32IMAFC-SAME: 
"-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f"
 
+// RUN: %clang %s -### --target=powerpc-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPCEABI %s
+// CHECK-PPCEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPCEABI: "-nostdsysteminc"
+// CHECK-PPCEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPCEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPCEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPCEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPCEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPCEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPCEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPCEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc" "-o" "a.out"
+
+// RUN: %clang %s -### --target=powerpc64-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64EABI %s
+// CHECK-PPC64EABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPC64EABI: "-nostdsysteminc"
+// CHECK-PPC64EABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPC64EABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPC64EABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPC64EABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPC64EABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc64" "-o" 
"a.out"
+
+// RUN: %clang %s -### --target=powerpcle-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPCLEEABI %s
+// CHECK-PPCLEEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPCLEEABI: "-nostdsysteminc"
+// CHECK-PPCLEEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPCLEEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPCLEEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPCLEEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPCLEEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpcle" "-o" 
"a.out"
+
+// RUN: %clang %s -### --target=powerpc64le-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64LEEABI %s
+// CHECK-PPC64LEEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPC64LEEABI: "-nostdsysteminc"
+// CHECK-PPC64LEEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPC64LEEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPC64LEEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPC64LEEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPC64LEEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc64le" "-o" 
"a.out"
+
 // Check that compiler-rt library without the arch filename suffix will
 // be used if present.
 // RUN: rm -rf 

[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:303
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"

kadircet wrote:
> can you also have a test in which we insert "d.h" and it gets put into the 
> right place?
added a test with a FIXME -- unfortunately, this case doesn't work yet (I 
believe this is a bug in the `tooling::HeaderIncludes`, I plan to fix it 
afterwards.)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

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


[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 539045.
hokein added a comment.

add a testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Results.Missing.push_back("\"d.h\"");
+  Code = R"cpp(#include "a.h")cpp";
+  // FIXME: this isn't correct, the main-file header d.h should be added before
+  // a.h.
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "a.h"
+#include "d.h"
 )cpp");
 }
 
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle ) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults , llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults ,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle );
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, 

[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9838
+def err_omp_loop_reduction_clause : Error<
+  "reduction clause not allowed with '#pragma omp loop bind(teams)'">;
 def warn_break_binds_to_switch : Warning<

'reduction'



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6105
+bool Sema::mapLoopConstruct(
+llvm::SmallVector *ClausesWithoutBind,
+ArrayRef Clauses, OpenMPBindClauseKind BindKind,

Why ClausesWithoutBind passing by pointer? Use `llvm::SmallVectorImpl ` instead



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6107
+ArrayRef Clauses, OpenMPBindClauseKind BindKind,
+OpenMPDirectiveKind *Kind) {
+

Same, pass by reference



Comment at: clang/lib/Sema/SemaOpenMP.cpp:14088-14089
   setFunctionHasBranchProtectedScope();
-  return OMPDistributeDirective::Create(Context, StartLoc, EndLoc,
-NestedLoopCount, Clauses, AStmt, B);
+  return OMPDistributeDirective::Create(
+  Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }

Restore formatting


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

https://reviews.llvm.org/D144634

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr14xx.cpp:491
+  float operator ""_E(const char *);
+  // expected-warning@+1 {{user-defined literal suffixes not starting with '_' 
are reserved; no literal will invoke this operator}}
+  float operator ""E(const char *); // don't err on the lack of spaces even 
when the literal suffix identifier is invalid

Can you move this down, so that offset is negative (after @)?


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

https://reviews.llvm.org/D153156

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D154357#4487896 , @cwalther wrote:

> Thanks for the comments. Yes, `powerpc-*-eabi` should be valid (sorry if I 
> was unclear about that – my parenthetical was only about AArch64). There is a 
> PowerPC EABI: https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I 
> wouldn’t know if Clang/LLD obey it, but it works for us…
>
> I am fine with removing the vendor check if that is the consensus.

Sounds good. I think `&&` is cleaner: `return Triple.getOS() == 
llvm::Triple::UnknownOS && ...`;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[clang] 9ca395b - [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-07-11T09:14:27+02:00
New Revision: 9ca395b5ade105aee63db20534d49a1c58ac76c7

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

LOG: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from 
VarDecl's initializer.

Similar to the https://reviews.llvm.org/D86048 (it only sets the bit for C++
code), we propagate the contains-errors bit for C-code path.

Fixes https://github.com/llvm/llvm-project/issues/50236
Fixes https://github.com/llvm/llvm-project/issues/50243
Fixes https://github.com/llvm/llvm-project/issues/48636
Fixes https://github.com/llvm/llvm-project/issues/50320

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ComputeDependence.cpp
clang/test/AST/ast-dump-recovery.c
clang/test/SemaCXX/cxx11-crashes.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae88de6a4aa7e6..6a1e2fc3ea0e64 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -576,6 +576,12 @@ Bug Fixes in This Version
 - Fixed false positive error diagnostic when pack expansion appears in template
   parameters of a member expression.
   (`#48731 `_)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 632f38f711fb1b..09df5401d6693a 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext ) {
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext ) {
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the

diff  --git a/clang/test/AST/ast-dump-recovery.c 
b/clang/test/AST/ast-dump-recovery.c
index 969e0e7941244a..68d3f182dd9f64 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@ void test6_GH50244() {
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];

diff  --git a/clang/test/SemaCXX/cxx11-crashes.cpp 
b/clang/test/SemaCXX/cxx11-crashes.cpp
index a15fea336f8c5e..11bc42315421d6 100644
--- a/clang/test/SemaCXX/cxx11-crashes.cpp
+++ b/clang/test/SemaCXX/cxx11-crashes.cpp
@@ 

[PATCH] D154861: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu 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 rG9ca395b5ade1: [clang][AST] Propagate the contains-errors bit 
to DeclRefExpr from VarDecls… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D154861?vs=538929=538931#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/SemaCXX/cxx11-crashes.cpp


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int (x);
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -576,6 +576,12 @@
 - Fixed false positive error diagnostic when pack expansion appears in template
   parameters of a member expression.
   (`#48731 `_)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error 

[PATCH] D154324: [C++20] [Modules] [ODRHash] Use CanonicalType for base classes

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Changes 
Planned".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf82df0b285ac: [C++20] [Modules] Use CanonicalType for base 
classes (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154324

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/pr63595.cppm


Index: clang/test/Modules/pr63595.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o 
%t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o 
%t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify 
-fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto  : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }


Index: clang/test/Modules/pr63595.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o %t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o %t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify -fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto  : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f82df0b - [C++20] [Modules] Use CanonicalType for base classes

2023-07-11 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-07-11T15:59:03+08:00
New Revision: f82df0b285acd8a7115f0bfc55ce44474251c2d1

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

LOG: [C++20] [Modules] Use CanonicalType for base classes

This comes from https://reviews.llvm.org/D153003

By @rsmith, the test case is valid since:

> Per [temp.type]/1.4 (http://eel.is/c++draft/temp.type#1.4),
>
>> Two template-ids are the same if [...] their corresponding template
>> template-arguments refer to the same template.
> so B and B are the same type. The stricter "same sequence of
> tokens" rule doesn't apply here, because using-declarations are not
> definitions.

> we should either (preferably) be including only the syntactic form of
> the base specifier (because local syntax is what the ODR covers), or
> the canonical type (which should be the same for both
> using-declarations).

Here we adopt the second suggested solutions.

Reviewed By: cor3ntin, v.g.vassilev

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

Added: 
clang/test/Modules/pr63595.cppm

Modified: 
clang/lib/AST/ODRHash.cpp

Removed: 




diff  --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 507fb0b49f8ad3..40d68a310dd2a8 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) 
{
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto  : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }

diff  --git a/clang/test/Modules/pr63595.cppm b/clang/test/Modules/pr63595.cppm
new file mode 100644
index 00..f2caf629ac10b8
--- /dev/null
+++ b/clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o 
%t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o 
%t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify 
-fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;



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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:22-25
+  RN_T0 = 0xC,
+  RN_T1 = 0xD,
+  RN_RA = 0x1,
+  RN_SP = 0x3,

xen0n wrote:
> I think people usually just declare the register ABI names with decimal 
> numbers for readability?
> 
> This is minor but I personally find it slightly distracting to have to think 
> about what's `0xc` in decimal (that's the case even though I'm already very 
> familiar with these kinds of thing). Not sure if others also prefer decimals 
> though...
Ok,  use decimal numbers to declare the register ABI names.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:32
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Parens not needed in this case. (If you want to enhance readability for those 
> people having difficulties remembering precedence and associativeness of 
> operators, you should instead put the parens around `Rj << 5` and `Imm << 
> 10`...)
> 
> I'd suggest re-ordering the operands too, to imitate the expected bit layout 
> of the result.
What you said makes sense. Thanks for your suggestion and attentiveness. I have 
adjusted parens and operands order.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:39
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rd | Imm << 5);
+}

xen0n wrote:
> Similarly here.
Done.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:42-47
+// Encode instructions in 2RI16 format, e.g. jirl.
+inline static uint32_t
+encodeInstruction2RI16(uint32_t Opcode, uint32_t Rd, uint32_t Rj,
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Does this look *very* similar to `encodeInstruction2RI12`? ;-)
> 
> Actually, if you don't bounds-check the operands, you only need one helper 
> for each combination of slots involved. Check for example the `static 
> uint32_t insn` implementation in my D138135, or [[ 
> https://gitlab.com/qemu-project/qemu/-/blob/master/tcg/loongarch64/tcg-insn-defs.c.inc
>  | the auto-generated encoding helpers for the QEMU TCG LoongArch64 port ]], 
> for some alternative approaches.
It is indeed similar to `encodeInstruction2RI12`. Given its exclusive use in 
this context, I prefer the unified `2RIx` format.

Thanks for the suggestion. While we appreciate it, we are more inclined to use 
one `2RIx` format helper here.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:58
+  //   11 NOPs (44 bytes)
+  //   .tmpN
+  //

xen0n wrote:
> `.tmpN:` for it to not look like a directive?
Use the real `.Lxray_sled_endN`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:71
+  //   ori t1, t1, %abs_lo12(function_id);pass function id
+  //   jirlra, t0, 0 ;call Tracing hook
+  //   ld.dra, sp, 8 ;restore return address

xen0n wrote:
> All-lowercase i.e. `tracing` for consistency? Or am I missing something?
It should be a copy from `mips`. I think it can be written `tracing hook` or 
`TracingHook`. To maintain all-lowercase consistency here, I use `tracing hook`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:73
+  //   ld.dra, sp, 8 ;restore return address
+  //   addi.d  sp, sp, 16;delete stack frame
+  //

xen0n wrote:
> I think idiomatically it's not "create/delete stack frame" but rather 
> "(de-)allocate" or "setup/teardown"... anyway please fix the usage of 
> articles (put the "the"'s properly) and also add a space after the `;` 
> because it's usually aesthetically better.
> 
> This is all minor though, and it's not like people will misunderstand 
> anything otherwise, but rather it's mostly just me pushing for more natural 
> English usage.
Ok, a space after the `;`   is added.  About article `the`,  i also added it. 
But i am not sure whether the usage of `the` is proper. If  there are any 
further issues , I would greatly appreciate your feedback.

Thanks for your effort.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:80
+  //
+  // When |Enable|==false, we set back the first instruction in the sled to be
+  //   B #48

xen0n wrote:
> ("set back" happens to be an idiomatic phrase verb so I got confused here for 
> ~1 second, so I think it's probably easier to just avoid this coincidence.)
Done.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:83
+  // a1=1 means that we are tracing an exit event
+  ori $a1, $zero, 1
+  // Function ID is in t1 (the first parameter).

xen0n wrote:
> Use pseudo-instruction for idiomatic expression of 

[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

These insulate tests against changes to the `getChild()` functions of
`AggregateStorageLocation` and `StructValue` that will happen as part of the
migration to strict handling of value categories (see
https://discourse.llvm.org/t/70086 for details):

- `AggregateStorageLocation::getChild()` will soon return a `StorageLocation *` 
instead of a `StorageLocation &`. When this happens, `getFieldValue()` will be 
changed to return null if `AggregateStorageLocation::getChild()` returns null; 
test code will not need to change as it should already be checking whether the 
return value of `getFieldValue()` is null.

- `StructValue::getChild()` will soon return a `StorageLocation *` instead of a 
`Value *`. When this happens, `getFieldValue()` will be changed to look up the 
`Value *` in the `Environment`. Again, test code will not need to change.

The test helpers will continue to serve a useful purpose once the API changes
are complete, so the intent is to leave them in place.

This patch changes DataflowEnvironmentTest.cpp and RecordOpsTest.cpp to use the
test helpers. TransferTest.cpp will be changed in an upcoming patch to help keep
patch sizes manageable for review.

Depends On D154934 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154935

Files:
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -451,6 +451,28 @@
   return *cast(Env.getValue(*VD));
 }
 
+/// Returns the value of a `Field` on the record referenced by `Loc.`
+/// Returns null if `Loc` is null.
+inline Value *getFieldValue(const AggregateStorageLocation *Loc,
+const ValueDecl , const Environment ) {
+  if (Loc == nullptr)
+return nullptr;
+  return Env.getValue(Loc->getChild(Field));
+}
+
+/// Returns the value of a `Field` on a `Struct.
+/// Returns null if `Struct` is null.
+///
+/// Note: This function currently does not use the `Env` parameter, but it will
+/// soon be needed to look up the `Value` when `setChild()` changes to return a
+/// `StorageLocation *`.
+inline Value *getFieldValue(const StructValue *Struct, const ValueDecl ,
+const Environment ) {
+  if (Struct == nullptr)
+return nullptr;
+  return Struct->getChild(Field);
+}
+
 /// Creates and owns constraints which are boolean values.
 class ConstraintContext {
   unsigned NextAtom = 0;
Index: clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -63,12 +63,12 @@
 auto  = cast(S1.getChild(*InnerDecl));
 auto  = cast(S2.getChild(*InnerDecl));
 
-EXPECT_NE(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_NE(getFieldValue(, *OuterIntDecl, Env),
+  getFieldValue(, *OuterIntDecl, Env));
 EXPECT_NE(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_NE(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_NE(getFieldValue(, *InnerIntDecl, Env),
+  getFieldValue(, *InnerIntDecl, Env));
 
 auto *S1Val = cast(Env.getValue(S1));
 auto *S2Val = cast(Env.getValue(S2));
@@ -78,12 +78,12 @@
 
 copyRecord(S1, S2, Env);
 
-EXPECT_EQ(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_EQ(getFieldValue(, *OuterIntDecl, Env),
+  getFieldValue(, *OuterIntDecl, Env));
 EXPECT_EQ(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_EQ(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_EQ(getFieldValue(, *InnerIntDecl, Env),
+  getFieldValue(, *InnerIntDecl, Env));
 
 S1Val = cast(Env.getValue(S1));
 S2Val = cast(Env.getValue(S2));
Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
===
--- 

[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

I'm gonna close this, since the new approach is too different.


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

https://reviews.llvm.org/D144943

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


[PATCH] D149013: [clang][Interp] Check pointers when accessing base class

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149013

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


[PATCH] D154471: [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I gave it a try, here is a testcase that triggers the crash

  // clang -cc1 -emit-pch -o /tmp/t.pch /tmp/t.cpp
  #ifndef HEADER
  #define HEADER
  
  struct A {  int *p; };
  const A  = A{ new int(10) };
  
  #endif


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154471

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


[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ymandel, xazax.hun.
Herald added subscribers: ChuanqiXu, martong, mgrang.
Herald added a reviewer: NoQ.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes two places where we relied on map iteration order when processing
values, which leaked nondeterminism into the generated SAT formulas.
Adds a couple of tests that directly assert that the SAT system is
equivalent on each run.

It's desirable that the formulas are deterministic based on the input:

- our SAT solver is naive and perfermance is sensitive to even simple 
semantics-preserving transformations like A|B to B|A. (e.g. it's likely to 
choose a different variable to split on). Timeout failures are bad, but *flaky* 
ones are terrible to debug.
- similarly when debugging, it's important to have a consistent understanding 
of what e.g. "V23" means across runs.

---

Both changes in this patch were isolated from a nullability analysis of
real-world code which was extremely slow, spending ages in the SAT
solver at "random" points that varied on each run.
I've included a reduced version of the code as a regression test.

One of the changes shows up directly as flow-condition nondeterminism
with a no-op analysis, the other relied on bits of the nullability
analysis but I found a synthetic example to show the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154948

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp
@@ -0,0 +1,137 @@
+//===- unittests/Analysis/FlowSensitive/DeterminismTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/AST/Decl.h"
+#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
+#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
+#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang::dataflow {
+
+// Run a no-op analysis, and return a textual representation of the
+// flow-condition at function exit.
+std::string analyzeAndPrintExitCondition(llvm::StringRef Code) {
+  DataflowAnalysisContext DACtx(std::make_unique());
+  clang::TestAST AST(Code);
+  const auto *Target =
+  cast(test::findValueDecl(AST.context(), "target"));
+  Environment InitEnv(DACtx, *Target);
+  auto CFCtx = cantFail(ControlFlowContext::build(*Target));
+
+  NoopAnalysis Analysis(AST.context(), DataflowAnalysisOptions{});
+
+  auto Result = runDataflowAnalysis(CFCtx, Analysis, InitEnv);
+  EXPECT_FALSE(!Result) << Result.takeError();
+
+  Atom FinalFC = (*Result)[CFCtx.getCFG().getExit().getBlockID()]
+ ->Env.getFlowConditionToken();
+  std::string Textual;
+  llvm::raw_string_ostream OS(Textual);
+  DACtx.dumpFlowCondition(FinalFC, OS);
+  return Textual;
+}
+
+TEST(DeterminismTest, NestedSwitch) {
+  // Example extracted from real-world code that had wildly nondeterministic
+  // analysis times.
+  // Its flow condition depends on the order we join predecessor blocks.
+  const char *Code = R"cpp(
+struct Tree;
+struct Rep {
+  Tree *tree();
+  int length;
+};
+struct Tree{
+  int height();
+  Rep *edge(int);
+  int length;
+};
+struct RetVal {};
+int getInt();
+bool maybe();
+
+RetVal make(int size);
+inline RetVal target(int size, Tree& self) {
+  Tree* tree = 
+  const int height = self.height();
+  Tree* n1 = tree;
+  Tree* n2 = tree;
+  switch (height) {
+case 3:
+  tree = tree->edge(0)->tree();
+  if (maybe()) return {};
+  n2 = tree;
+case 2:
+  tree = tree->edge(0)->tree();
+  n1 = tree;
+  if 

[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Thank you, Sam!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154948

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

No concerns from the perspective of PowerPC here. Of course, my focus is 
primarily on the server side of things but I am not aware of any other group 
that could be adversely affected.


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

https://reviews.llvm.org/D154357

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added inline comments.
This revision now requires changes to proceed.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:20
+  .type __xray_FunctionEntry,@function
+__xray_FunctionEntry:
+  .cfi_startproc

The symbol needs to be hidden and consider using some macros. See 
xray_trampoline_AArch64.S



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-07-11 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

@MaskRay @w2yehia @shchenz could you let me know if there are further comments? 
I will land this patch if there are none. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/ast-print-method-decl.cpp:15
+  // CHECK-NEXT: };
+};

strimo378 wrote:
> aaron.ballman wrote:
> > I'd also like to see test cases along the lines of:
> > ```
> > struct B {
> >   template 
> >   B(Ty);
> >   B(int X) : B((float)X) {}
> > };
> > 
> > struct C {
> >   C(auto);
> >   C(int) : C("") {}
> > };
> > ```
> I fully agree to you that these test cases should also work but that goes 
> beyond the scope of a "simple" delegating ctor output fix.
> 
> In the current implementation all implicitly specialized templates are output 
> and therefore the generated code is not correct C++ anymore, see 
> https://godbolt.org/z/34xaoYW5n . I think it is not a good idea to check for 
> incorrect C++ code in a test case...
> 
> I am currently focusing to get non-templated C++ code output correctly. For 
> methods e.g. there are many problems with the correct position of attributes. 
> I will address that in one of my next merge request and I want to put all 
> method related tests into ast-print-method-decl.cpp . Therefore, I would like 
> to keep the name.
> I fully agree to you that these test cases should also work but that goes 
> beyond the scope of a "simple" delegating ctor output fix.

Ah, so this is exposing an already existing issue. In that case, let's add the 
tests and leave a FIXME comment to improve the behavior in the future (bonus 
points for filing an issue) so that it's clear we've noticed there's a problem 
rather than looking like an oversight in test coverage. This also ensures that 
those forms of delegation don't cause assertions or crashes despite being wrong.

> I am currently focusing to get non-templated C++ code output correctly. For 
> methods e.g. there are many problems with the correct position of attributes. 
> I will address that in one of my next merge request and I want to put all 
> method related tests into ast-print-method-decl.cpp . Therefore, I would like 
> to keep the name.

Ah, if there's more functionality to be added to the test in the near future, 
the current name is fine by me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

We have `TargetOptions::DisableIntegratedAS` (your llc.cpp change). Do you know 
why it is not feasible for the places you want to check?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D154602: [clang][clangd] Don't crash/assert on -gsplit-dwarf=single without output

2023-07-11 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 539223.
DmitryPolukhin added a comment.

Added -target arm-linux-gnueabi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154602

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -367,6 +367,19 @@
   EXPECT_TRUE(CallbackHasCalled);
 }
 
+TEST(CompilerInvocation, SplitSwarfSingleCrash) {
+  static constexpr const char *Args[] = {"clang",
+ "-target",
+ "arm-linux-gnueabi",
+ "-gdwarf-4",
+ "-gsplit-dwarf=single",
+ "-c",
+ "foo.cpp"};
+  CreateInvocationOptions CIOpts;
+  std::unique_ptr CI = createInvocation(Args, CIOpts);
+  EXPECT_TRUE(CI); // no-crash
+}
+
 TEST(GetDriverMode, PrefersLastDriverMode) {
   static constexpr const char *Args[] = {"clang-cl", "--driver-mode=foo",
  "--driver-mode=bar", "foo.cpp"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1269,7 +1269,7 @@
 F += ".dwo";
   };
   if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
-if (StringRef(A->getValue()) == "single")
+if (StringRef(A->getValue()) == "single" && Output.isFilename())
   return Args.MakeArgString(Output.getFilename());
 
   SmallString<128> T;


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -367,6 +367,19 @@
   EXPECT_TRUE(CallbackHasCalled);
 }
 
+TEST(CompilerInvocation, SplitSwarfSingleCrash) {
+  static constexpr const char *Args[] = {"clang",
+ "-target",
+ "arm-linux-gnueabi",
+ "-gdwarf-4",
+ "-gsplit-dwarf=single",
+ "-c",
+ "foo.cpp"};
+  CreateInvocationOptions CIOpts;
+  std::unique_ptr CI = createInvocation(Args, CIOpts);
+  EXPECT_TRUE(CI); // no-crash
+}
+
 TEST(GetDriverMode, PrefersLastDriverMode) {
   static constexpr const char *Args[] = {"clang-cl", "--driver-mode=foo",
  "--driver-mode=bar", "foo.cpp"};
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1269,7 +1269,7 @@
 F += ".dwo";
   };
   if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
-if (StringRef(A->getValue()) == "single")
+if (StringRef(A->getValue()) == "single" && Output.isFilename())
   return Args.MakeArgString(Output.getFilename());
 
   SmallString<128> T;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >