[PATCH] D152793: [RISCV] Add MC layer support for Zicfiss.

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:1972
 
+// Control Flow Integerity
+include "RISCVInstrInfoZicfiss.td"

Put this with the other RISCVInstrInfoZi* files under "Integer"



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td:92
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 1 
in
+def C_SSPUSHX1 : RVC_SSInst<0b1, "c.sspush", "x1">;
+

Can we merge the X1 and X5 instructions? Looks like the register is encoded?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152793

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


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 546323.
evelez7 added a comment.

Add test for overloaded operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/operator_overload.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"title": "Bar"
+  },
+  "pathComponents": [
+"Bar"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/operator_overload.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/operator_overload.cpp
@@ -0,0 +1,210 @@
+// RUN: rm -rf %t

[PATCH] D156851: [RISCV] Merge rv32 and rv64 Zvb* intrinsic tests. NFC

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: asb, wangpc, kito-cheng, reames.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, eopXD, MaskRay.
Herald added a project: clang.

There was some duplication between these tests and
we can merge them by checking __riscv_xlen for the parts
that aren't duplicated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156851

Files:
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/zbc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/zbkx.c

Index: clang/test/CodeGen/RISCV/rvb-intrinsics/zbkx.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/zbkx.c
@@ -0,0 +1,53 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv32 -target-feature +zbkx -emit-llvm %s -o - \
+// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
+// RUN: | FileCheck %s  -check-prefix=RV32ZBKX
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zbkx -emit-llvm %s -o - \
+// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
+// RUN: | FileCheck %s  -check-prefix=RV64ZBKX
+
+#include 
+
+#if __riscv_xlen == 32
+// RV32ZBKX-LABEL: @xperm8_32(
+// RV32ZBKX-NEXT:  entry:
+// RV32ZBKX-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.xperm8.i32(i32 [[RS1:%.*]], i32 [[RS2:%.*]])
+// RV32ZBKX-NEXT:ret i32 [[TMP0]]
+//
+uint32_t xperm8_32(uint32_t rs1, uint32_t rs2)
+{
+  return __builtin_riscv_xperm8_32(rs1, rs2);
+}
+
+// RV32ZBKX-LABEL: @xperm4_32(
+// RV32ZBKX-NEXT:  entry:
+// RV32ZBKX-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.xperm4.i32(i32 [[RS1:%.*]], i32 [[RS2:%.*]])
+// RV32ZBKX-NEXT:ret i32 [[TMP0]]
+//
+uint32_t xperm4_32(uint32_t rs1, uint32_t rs2)
+{
+  return __builtin_riscv_xperm4_32(rs1, rs2);
+}
+#endif
+
+#if __riscv_xlen == 64
+// RV64ZBKX-LABEL: @xperm8_64(
+// RV64ZBKX-NEXT:  entry:
+// RV64ZBKX-NEXT:[[TMP0:%.*]] = call i64 @llvm.riscv.xperm8.i64(i64 [[RS1:%.*]], i64 [[RS2:%.*]])
+// RV64ZBKX-NEXT:ret i64 [[TMP0]]
+//
+uint64_t xperm8_64(uint64_t rs1, uint64_t rs2)
+{
+  return __builtin_riscv_xperm8_64(rs1, rs2);
+}
+
+// RV64ZBKX-LABEL: @xperm4_64(
+// RV64ZBKX-NEXT:  entry:
+// RV64ZBKX-NEXT:[[TMP0:%.*]] = call i64 @llvm.riscv.xperm4.i64(i64 [[RS1:%.*]], i64 [[RS2:%.*]])
+// RV64ZBKX-NEXT:ret i64 [[TMP0]]
+//
+uint64_t xperm4_64(uint64_t rs1, uint64_t rs2)
+{
+  return __builtin_riscv_xperm4_64(rs1, rs2);
+}
+#endif
Index: clang/test/CodeGen/RISCV/rvb-intrinsics/zbkc.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/zbkc.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/zbkc.c
@@ -1,10 +1,14 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv32 -target-feature +zbkc -emit-llvm %s -o - \
+// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
+// RUN: | FileCheck %s  -check-prefix=RV32ZBKC
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zbkc -emit-llvm %s -o - \
 // RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZBKC
 
 #include 
 
+#if __riscv_xlen == 64
 // RV64ZBKC-LABEL: @clmul_64(
 // RV64ZBKC-NEXT:  entry:
 // RV64ZBKC-NEXT:[[TMP0:%.*]] = call i64 @llvm.riscv.clmul.i64(i64 [[A:%.*]], i64 [[B:%.*]])
@@ -22,7 +26,13 @@
 uint64_t clmulh_64(uint64_t a, uint64_t b) {
   return __builtin_riscv_clmulh_64(a, b);
 }
+#endif
 
+// RV32ZBKC-LABEL: @clmul_32(
+// RV32ZBKC-NEXT:  entry:
+// RV32ZBKC-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.clmul.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+// RV32ZBKC-NEXT:ret i32 [[TMP0]]
+//
 // RV64ZBKC-LABEL: @clmul_32(
 // RV64ZBKC-NEXT:  entry:
 // RV64ZBKC-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.clmul.i32(i32 [[A:%.*]], i32 [[B:%.*]])
@@ -31,3 +41,14 @@
 uint32_t clmul_32(uint32_t a, uint32_t 

[clang] 244fd4d - [RISCV] Run mem2reg on more scalar C builtin tests to remove allocas and simplify checks. NFC

2023-08-01 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-08-01T22:10:54-07:00
New Revision: 244fd4dfc56a0d59655c65adac6a7258114b8af2

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

LOG: [RISCV] Run mem2reg on more scalar C builtin tests to remove allocas and 
simplify checks. NFC

Added: 


Modified: 
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c

Removed: 




diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
index 6e7ecf0300fba5..ffd869ce6d9b0a 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
@@ -1,14 +1,12 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple riscv32 -target-feature +zbb -emit-llvm %s -o - \
+// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV32ZBB
 
 // RV32ZBB-LABEL: @orc_b_32(
 // RV32ZBB-NEXT:  entry:
-// RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
-// RV32ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 [[TMP0]])
-// RV32ZBB-NEXT:ret i32 [[TMP1]]
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 
[[A:%.*]])
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
 //
 unsigned int orc_b_32(unsigned int a) {
   return __builtin_riscv_orc_b_32(a);
@@ -16,11 +14,8 @@ unsigned int orc_b_32(unsigned int a) {
 
 // RV32ZBB-LABEL: @clz_32(
 // RV32ZBB-NEXT:  entry:
-// RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
-// RV32ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 
false)
-// RV32ZBB-NEXT:ret i32 [[TMP1]]
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[A:%.*]], i1 
false)
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
 //
 unsigned int clz_32(unsigned int a) {
   return __builtin_riscv_clz_32(a);
@@ -28,11 +23,8 @@ unsigned int clz_32(unsigned int a) {
 
 // RV32ZBB-LABEL: @ctz_32(
 // RV32ZBB-NEXT:  entry:
-// RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
-// RV32ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
-// RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 
false)
-// RV32ZBB-NEXT:ret i32 [[TMP1]]
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[A:%.*]], i1 
false)
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
 //
 unsigned int ctz_32(unsigned int a) {
   return __builtin_riscv_ctz_32(a);

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
index 2309adfff84408..37b2b4fcc35546 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
@@ -1,14 +1,12 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zbb -emit-llvm %s -o - \
+// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZBB
 
 // RV64ZBB-LABEL: @orc_b_32(
 // RV64ZBB-NEXT:  entry:
-// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
-// RV64ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
-// RV64ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
-// RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 [[TMP0]])
-// RV64ZBB-NEXT:ret i32 [[TMP1]]
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 
[[A:%.*]])
+// RV64ZBB-NEXT:ret i32 [[TMP0]]
 //
 unsigned int orc_b_32(unsigned int a) {
   return __builtin_riscv_orc_b_32(a);
@@ -16,11 +14,8 @@ unsigned int orc_b_32(unsigned int a) {
 
 // RV64ZBB-LABEL: @orc_b_64(
 // RV64ZBB-NEXT:  entry:
-// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
-// RV64ZBB-NEXT:store i64 [[A:%.*]], ptr [[A_ADDR]], align 8
-// RV64ZBB-NEXT:[[TMP0:%.*]] = load i64, ptr [[A_ADDR]], align 8
-// RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.riscv.orc.b.i64(i64 [[TMP0]])
-// RV64ZBB-NEXT:ret i64 [[TMP1]]
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i64 @llvm.riscv.orc.b.i64(i64 
[[A:%.*]])
+// RV64ZBB-NEXT:ret i64 [[TMP0]]
 //
 unsigned long orc_b_64(unsigned long a) {
   return __builtin_riscv_orc_b_64(a);
@@ -28,11 +23,8 @@ unsigned long orc_b_64(unsigned long a) {
 
 // RV64ZBB-LABEL: @clz_32(
 // RV64ZBB-NEXT:  entry:
-// RV64ZBB-NEXT:

[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 added inline comments.



Comment at: clang/include/clang/ExtractAPI/API.h:770
+template <>
+struct has_function_signature : public std::true_type {};
+

dang wrote:
> Does `CXXInstanceMethodRecord` need one of these as well?
`CXXInstanceMethodRecord` inherits from `CXXMethodRecord` which holds the 
signature for all methods.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153557

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


[PATCH] D153557: [clang][ExtractAPI] Add support for C++ classes

2023-08-01 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 546317.
evelez7 marked 4 inline comments as done.
evelez7 added a comment.

Address review feedback, add tests, and small refactors.

- Add tests for destructors, constructors, and conversion methods.
- Remove redundant check-nots in existing tests.
- Properly record destructor names.
- Add explicit qualifier to conversions.
- Remove unused code from getFragmentsForSpecialCXXMethod.
- Use appendSpace isntead of literals in keyword fragments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153557

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class.cpp
  clang/test/ExtractAPI/constructor_destructor.cpp
  clang/test/ExtractAPI/conversions.cpp
  clang/test/ExtractAPI/function_noexcepts.cpp
  clang/test/ExtractAPI/methods.cpp
  clang/test/ExtractAPI/multiple_inheritance.cpp
  clang/test/ExtractAPI/simple_inheritance.cpp

Index: clang/test/ExtractAPI/simple_inheritance.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/simple_inheritance.cpp
@@ -0,0 +1,162 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang++ -extract-api -target arm64-apple-macosx -x c++-header \
+// RUN: %t/input.h -o %t/output.json -Xclang -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+class Foo {};
+
+class Bar : public Foo {};
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "inheritsFrom",
+  "source": "c:@S@Bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "class"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@S@Bar"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "c++.class"
+  },
+  "location": {
+"position": {
+  "character": 7,
+  "line": 3
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Bar"
+  }

[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 546315.
craig.topper added a comment.

Add riscv_bitmanip.h to cover all of Zbb and Zbkb


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155647

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_bitmanip.h
  clang/lib/Headers/riscv_crypto.h
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c

Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
@@ -6,7 +6,7 @@
 // RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSH
 
-#include 
+#include 
 
 // RV32ZKSH-LABEL: @sm3p0(
 // RV32ZKSH-NEXT:  entry:
@@ -19,7 +19,7 @@
 // RV64ZKSH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sm3p0(uint32_t rs1) {
-  return __builtin_riscv_sm3p0(rs1);
+  return __riscv_sm3p0(rs1);
 }
 
 
@@ -34,5 +34,5 @@
 // RV64ZKSH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sm3p1(uint32_t rs1) {
-  return __builtin_riscv_sm3p1(rs1);
+  return __riscv_sm3p1(rs1);
 }
Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
@@ -6,7 +6,7 @@
 // RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSED
 
-#include 
+#include 
 
 // RV32ZKSED-LABEL: @sm4ks(
 // RV32ZKSED-NEXT:  entry:
@@ -19,7 +19,7 @@
 // RV64ZKSED-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sm4ks(uint32_t rs1, uint32_t rs2) {
-  return __builtin_riscv_sm4ks(rs1, rs2, 0);
+  return __riscv_sm4ks(rs1, rs2, 0);
 }
 
 // RV32ZKSED-LABEL: @sm4ed(
@@ -33,5 +33,5 @@
 // RV64ZKSED-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sm4ed(uint32_t rs1, uint32_t rs2) {
-  return __builtin_riscv_sm4ed(rs1, rs2, 0);
+  return __riscv_sm4ed(rs1, rs2, 0);
 }
Index: clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
@@ -3,7 +3,7 @@
 // RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKNH
 
-#include 
+#include 
 
 // RV64ZKNH-LABEL: @sha512sig0(
 // RV64ZKNH-NEXT:  entry:
@@ -11,7 +11,7 @@
 // RV64ZKNH-NEXT:ret i64 [[TMP0]]
 //
 uint64_t sha512sig0(uint64_t rs1) {
-  return __builtin_riscv_sha512sig0(rs1);
+  return __riscv_sha512sig0(rs1);
 }
 
 
@@ -21,7 +21,7 @@
 // RV64ZKNH-NEXT:ret i64 [[TMP0]]
 //
 uint64_t sha512sig1(uint64_t rs1) {
-  return __builtin_riscv_sha512sig1(rs1);
+  return __riscv_sha512sig1(rs1);
 }
 
 
@@ -31,7 +31,7 @@
 // RV64ZKNH-NEXT:ret i64 [[TMP0]]
 //
 uint64_t sha512sum0(uint64_t rs1) {
-  return __builtin_riscv_sha512sum0(rs1);
+  return __riscv_sha512sum0(rs1);
 }
 
 
@@ -41,7 +41,7 @@
 // RV64ZKNH-NEXT:ret i64 [[TMP0]]
 //
 uint64_t sha512sum1(uint64_t rs1) {
-  return __builtin_riscv_sha512sum1(rs1);
+  return __riscv_sha512sum1(rs1);
 }
 
 
@@ -51,7 +51,7 @@
 // RV64ZKNH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sha256sig0(uint32_t rs1) {
-  return __builtin_riscv_sha256sig0(rs1);
+  return __riscv_sha256sig0(rs1);
 }
 
 // RV64ZKNH-LABEL: @sha256sig1(
@@ -60,7 +60,7 @@
 // RV64ZKNH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sha256sig1(uint32_t rs1) {
-  return __builtin_riscv_sha256sig1(rs1);
+  return __riscv_sha256sig1(rs1);
 }
 
 
@@ -70,7 +70,7 @@
 // RV64ZKNH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sha256sum0(uint32_t rs1) {
-  return __builtin_riscv_sha256sum0(rs1);
+  return __riscv_sha256sum0(rs1);
 }
 
 // RV64ZKNH-LABEL: @sha256sum1(
@@ -79,5 +79,5 @@
 // RV64ZKNH-NEXT:ret i32 [[TMP0]]
 //
 uint32_t sha256sum1(uint32_t rs1) {
-  return __builtin_riscv_sha256sum1(rs1);
+  return __riscv_sha256sum1(rs1);
 }
Index: 

[PATCH] D156771: [clang][hexagon] Handle library path arguments earlier

2023-08-01 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 546314.
bcain added a comment.

Changed test to use `-Werror -###` instead of `-fdriver-only -v -Werror`.

Fixed indentation / `clang-format`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156771

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -120,8 +120,12 @@
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
 
-// RUN: %clang -fdriver-only -Werror -v -L/tmp \
-// RUN:--target=hexagon-unknown-linux-musl %s 2>&1 \
+// RUN: %clang -Werror -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
 // RUN:| FileCheck -check-prefix=CHECK010 %s
 // CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010-NOT:  "-lstandalone"
+// CHECK010-NOT:  crt0_standalone.o
+// CHECK010:   crt1.o
 // CHECK010:   "-L/tmp"
+// CHECK010-NOT:  "-lstandalone"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,6 +383,11 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
+const ToolChain::path_list  = HTC.getFilePaths();
+for (const auto  : LibPaths)
+  CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+Args.ClaimAllArgs(options::OPT_L);
+return;
   }
 
   
//


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -120,8 +120,12 @@
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" "[[INSTALLED_DIR]]/../target/hexagon/include"
 
-// RUN: %clang -fdriver-only -Werror -v -L/tmp \
-// RUN:--target=hexagon-unknown-linux-musl %s 2>&1 \
+// RUN: %clang -Werror -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
 // RUN:| FileCheck -check-prefix=CHECK010 %s
 // CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010-NOT:  "-lstandalone"
+// CHECK010-NOT:  crt0_standalone.o
+// CHECK010:   crt1.o
 // CHECK010:   "-L/tmp"
+// CHECK010-NOT:  "-lstandalone"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,6 +383,11 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
+const ToolChain::path_list  = HTC.getFilePaths();
+for (const auto  : LibPaths)
+  CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+Args.ClaimAllArgs(options::OPT_L);
+return;
   }
 
   //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-01 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 546309.
jcsxky added a comment.

update patch for pass unittests and test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
  clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
  clang/test/Analysis/Inputs/ctu-friend-template.h
  clang/test/Analysis/ctu-friend-template.cpp


Index: clang/test/Analysis/ctu-friend-template.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-friend-template.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-friend-template-other.cpp.ast 
%S/Inputs/ctu-friend-template-other.cpp
+// RUN: cp %S/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt 
%t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -Werror=ctu \
+// RUN:   -verify %s
+
+// CHECK: CTU loaded AST file
+
+#include "Inputs/ctu-friend-template.h"
+
+void bar();
+
+int main(){
+   bar(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.h
@@ -0,0 +1,20 @@
+namespace __1{
+
+template
+class A;
+
+template
+class A{
+public:
+   template
+   friend class A;
+
+   A(T x):x(x){}
+   
+   void foo(){}
+   
+private:
+   T x;
+};
+
+}
Index: 
clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
@@ -0,0 +1 @@
+9:c:@F@bar# ctu-friend-template-other.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
@@ -0,0 +1,6 @@
+#include "ctu-friend-template.h"
+
+void bar(){
+   __1::A a1(0);
+   a1.foo();
+}
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -44,6 +44,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeVisitor.h"
 #include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/FileManager.h"
@@ -5812,6 +5813,11 @@
   if (FoundTemplate) {
 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
   continue;
+auto Parents = FoundDecl->getASTContext().getParents(*FoundDecl);
+if (!Parents.empty() && nullptr != Parents.begin()->get() 
&&
+FoundTemplate->getName() == D->getName() &&
+!IsStructuralMatch(D, FoundTemplate, false))
+  continue;
 
 if (IsStructuralMatch(D, FoundTemplate)) {
   ClassTemplateDecl *TemplateWithDef =


Index: clang/test/Analysis/ctu-friend-template.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-friend-template.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-friend-template-other.cpp.ast %S/Inputs/ctu-friend-template-other.cpp
+// RUN: cp %S/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -Werror=ctu \
+// RUN:   -verify %s
+
+// CHECK: CTU loaded AST file
+
+#include "Inputs/ctu-friend-template.h"
+
+void bar();
+
+int main(){
+	bar(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.h
@@ -0,0 +1,20 @@
+namespace __1{
+
+template
+class A;
+
+template
+class A{
+public:
+	template
+	friend class A;
+
+	A(T x):x(x){}
+	
+	void foo(){}
+	
+private:
+	T x;
+};
+
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt

[PATCH] D96744: clang-format IncludeBlocks: Regroup determination of "main" for framework-style includes fix

2023-08-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc abandoned this revision.
poelmanc added a comment.
Herald added a project: All.

We eventually updated our coding standards and our fairly massive code base to 
change only the very top "main" include from `#include ` to 
`#include "Foo.h"`.

For all include statements after that, we still use framework-style includes 
(`#include `).

It worked great and now we're happily using clang-format to order and group all 
our include statements, with no need for any changes to clang-format. Thanks to 
all for maintaining such an amazing tool!


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96744

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


[PATCH] D156201: [ASTImporter] Fix corrupted RecordLayout introduced by circular referenced fields

2023-08-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91b7952afc82: [ASTImporter] Fix corrupted RecordLayout 
caused by circular referenced fields (authored by dingfei 
fd...@feysh.com).

Changed prior to commit:
  https://reviews.llvm.org/D156201?vs=546127=546304#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156201

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
@@ -2333,7 +2334,7 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   ImportVirtualOverriddenMethodOnALoopTest) {
+   ImportVirtualOverriddenMethodOnALoop) {
   // B::f() calls => f1() ==> C ==> C::f()
   // \
   //  \ A::f()
@@ -8057,7 +8058,7 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   ImportFieldsFirstForCorrectRecordLayoutTest) {
+   ImportFieldsFirstForCorrectRecordLayout) {
   // UnaryOperator(&) triggers RecordLayout computation, which relies on
   // correctly imported fields.
   auto Code =
@@ -8077,6 +8078,45 @@
   Import(FromF, Lang_CXX11);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportCirularRefFieldsWithoutCorruptedRecordLayoutCache) {
+  // Import sequence: A => A.b => B => B.f() => ... => UnaryOperator(&) => ...
+  //
+  // UnaryOperator(&) should not introduce invalid RecordLayout since 'A' is
+  // still not completely imported.
+  auto Code =
+  R"(
+  class B;
+  class A {
+B* b;
+int c;
+  };
+  class B {
+A *f() { return &((B *)0)->a; }
+A a;
+  };
+  )";
+
+  auto *FromR = FirstDeclMatcher().match(
+  getTuDecl(Code, Lang_CXX11), cxxRecordDecl(hasName("A")));
+  FromR = FromR->getDefinition();
+  auto  = FromR->getASTContext();
+  auto *ToR = Import(FromR, Lang_CXX11);
+  auto  = ToR->getASTContext();
+
+  uint64_t SecondFieldOffset = FromAST.getTypeSize(FromAST.VoidPtrTy);
+
+  EXPECT_TRUE(FromR->isCompleteDefinition());
+  const auto  = FromAST.getASTRecordLayout(FromR);
+  EXPECT_TRUE(FromLayout.getFieldOffset(0) == 0);
+  EXPECT_TRUE(FromLayout.getFieldOffset(1) == SecondFieldOffset);
+
+  EXPECT_TRUE(ToR->isCompleteDefinition());
+  const auto  = ToAST.getASTRecordLayout(ToR);
+  EXPECT_TRUE(ToLayout.getFieldOffset(0) == 0);
+  EXPECT_TRUE(ToLayout.getFieldOffset(1) == SecondFieldOffset);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportRecordWithLayoutRequestingExpr) {
   TranslationUnitDecl *FromTU = getTuDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -7414,10 +7414,17 @@
   if (Err)
 return std::move(Err);
 
-  return UnaryOperator::Create(
-  Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType,
-  E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(),
-  E->getFPOptionsOverride());
+  auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
+E->hasStoredFPFeatures());
+  UO->setType(ToType);
+  UO->setSubExpr(ToSubExpr);
+  UO->setOpcode(E->getOpcode());
+  UO->setOperatorLoc(ToOperatorLoc);
+  UO->setCanOverflow(E->canOverflow());
+  if (E->hasStoredFPFeatures())
+UO->setStoredFPFeatures(E->getStoredFPFeatures());
+
+  return UO;
 }
 
 ExpectedStmt
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -2341,7 +2341,7 @@
   }
 
 protected:
-  /// Set FPFeatures in trailing storage, used only by Serialization
+  /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
   void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
 
 public:
@@ -2359,6 +2359,7 @@
   }
 
   friend TrailingObjects;
+  friend class ASTNodeImporter;
   friend class ASTReader;
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -133,6 +133,10 @@
 ^
 - Fixed an import failure of recursive friend class template.
   `Issue 64169 `_
+- Remove unnecessary RecordLayout computation when 

[PATCH] D155661: [clang][ASTImporter] Fix friend class template import within dependent context

2023-08-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5f2157f8fcae: [clang][ASTImporter] Fix friend class template 
import within dependent context (authored by dingfei fd...@feysh.com).

Changed prior to commit:
  https://reviews.llvm.org/D155661?vs=545913=546303#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155661

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3968,8 +3968,58 @@
   EXPECT_EQ(ToDef->getPreviousDecl(), ToProto);
 }
 
-
-struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {};
+struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {
+  void testRecursiveFriendClassTemplate(Decl *FromTu) {
+auto *FromD = FirstDeclMatcher().match(
+FromTu, classTemplateDecl());
+
+auto Pattern = classTemplateDecl(
+has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
+ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
+
+auto *FromFriend =
+FirstDeclMatcher().match(FromD, friendDecl());
+auto *FromRecordOfFriend =
+cast(FromFriend->getFriendDecl())
+->getTemplatedDecl();
+EXPECT_NE(FromRecordOfFriend, FromD->getTemplatedDecl());
+EXPECT_TRUE(FromRecordOfFriend->getPreviousDecl() == nullptr);
+
+auto *FromDC = FromRecordOfFriend->getDeclContext();
+auto *FromLexicalDC = FromRecordOfFriend->getLexicalDeclContext();
+ASSERT_EQ(FromDC, cast(FromTu));
+ASSERT_EQ(FromLexicalDC, cast(FromD->getTemplatedDecl()));
+
+ASSERT_FALSE(FromDC->containsDecl(FromRecordOfFriend));
+ASSERT_FALSE(FromLexicalDC->containsDecl(FromRecordOfFriend));
+ASSERT_FALSE(cast(FromRecordOfFriend)
+ ->getLookupParent()
+ ->lookup(FromRecordOfFriend->getDeclName())
+ .empty());
+
+auto *ToD = Import(FromD, Lang_CXX03);
+EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+
+auto *ToFriend = FirstDeclMatcher().match(ToD, friendDecl());
+auto *ToRecordOfFriend =
+cast(ToFriend->getFriendDecl())->getTemplatedDecl();
+
+EXPECT_NE(ToRecordOfFriend, ToD->getTemplatedDecl());
+EXPECT_TRUE(ToRecordOfFriend->getPreviousDecl() == nullptr);
+
+auto *ToDC = ToRecordOfFriend->getDeclContext();
+auto *ToLexicalDC = ToRecordOfFriend->getLexicalDeclContext();
+ASSERT_EQ(ToDC, cast(ToD->getTranslationUnitDecl()));
+ASSERT_EQ(ToLexicalDC, cast(ToD->getTemplatedDecl()));
+
+ASSERT_FALSE(ToDC->containsDecl(ToRecordOfFriend));
+ASSERT_FALSE(ToLexicalDC->containsDecl(ToRecordOfFriend));
+ASSERT_FALSE(cast(ToRecordOfFriend)
+ ->getLookupParent()
+ ->lookup(ToRecordOfFriend->getDeclName())
+ .empty());
+  }
+};
 
 TEST_P(ImportFriendClasses, ImportOfFriendRecordDoesNotMergeDefinition) {
   Decl *FromTU = getTuDecl(
@@ -4074,20 +4124,19 @@
   )",
   Lang_CXX03, "input.cc");
 
-  auto *FromD =
-  FirstDeclMatcher().match(FromTu, classTemplateDecl());
-  auto *ToD = Import(FromD, Lang_CXX03);
-
-  auto Pattern = classTemplateDecl(
-  has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
-  ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
-  EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+  testRecursiveFriendClassTemplate(FromTu);
+}
 
-  auto *Class =
-  FirstDeclMatcher().match(ToD, classTemplateDecl());
-  auto *Friend = FirstDeclMatcher().match(ToD, friendDecl());
-  EXPECT_NE(Friend->getFriendDecl(), Class);
-  EXPECT_EQ(Friend->getFriendDecl()->getPreviousDecl(), Class);
+TEST_P(ImportFriendClasses,
+   ImportOfRecursiveFriendClassTemplateWithNonTypeParm) {
+  Decl *FromTu = getTuDecl(
+  R"(
+  template class declToImport {
+template friend class declToImport;
+  };
+  )",
+  Lang_CXX03, "input.cc");
+  testRecursiveFriendClassTemplate(FromTu);
 }
 
 TEST_P(ImportFriendClasses, ProperPrevDeclForClassTemplateDecls) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2857,9 +2857,13 @@
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
 IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend;
 
+  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+: DC->isDependentContext();
+  bool DependentFriend = IsFriendTemplate && IsDependentContext;
+
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod() && 

[clang] 91b7952 - [ASTImporter] Fix corrupted RecordLayout caused by circular referenced fields

2023-08-01 Thread via cfe-commits

Author: dingfei
Date: 2023-08-02T11:21:10+08:00
New Revision: 91b7952afc82f90e7b810701d9d5c776a8e21688

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

LOG: [ASTImporter] Fix corrupted RecordLayout caused by circular referenced 
fields

UnaryOperator(&)'s creation might need layout of some records
whose fields importation are still on fly, the layout is incorrectly
computed and cached. Clients relying on this will not work properly
or crash direclty (e.g StaticAnalyzer's MemRegion.cpp (calculateOffset)).

Use UnaryOperator::CreateEmpty() instead of UnaryOperator::Create()
to avoid this computation.

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

Reviewed By: aaron.ballman, balazske, shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Expr.h
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a536a9fe2363cf..381346f9605b4a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -133,6 +133,10 @@ Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
   `Issue 64169 `_
+- Remove unnecessary RecordLayout computation when importing UnaryOperator. The
+  computed RecordLayout is incorrect if fields are not completely imported and
+  should not be cached.
+  `Issue 64170 `_
 
 Miscellaneous Bug Fixes
 ^^^

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index f9795b6386c46f..6737721e1ed1b2 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2341,7 +2341,7 @@ class UnaryOperator final
   }
 
 protected:
-  /// Set FPFeatures in trailing storage, used only by Serialization
+  /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
   void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; 
}
 
 public:
@@ -2359,6 +2359,7 @@ class UnaryOperator final
   }
 
   friend TrailingObjects;
+  friend class ASTNodeImporter;
   friend class ASTReader;
   friend class ASTStmtReader;
   friend class ASTStmtWriter;

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1ad7067f8ca9c1..f122c09629e1c2 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -7414,10 +7414,17 @@ ExpectedStmt 
ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {
   if (Err)
 return std::move(Err);
 
-  return UnaryOperator::Create(
-  Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType,
-  E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(),
-  E->getFPOptionsOverride());
+  auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
+E->hasStoredFPFeatures());
+  UO->setType(ToType);
+  UO->setSubExpr(ToSubExpr);
+  UO->setOpcode(E->getOpcode());
+  UO->setOperatorLoc(ToOperatorLoc);
+  UO->setCanOverflow(E->canOverflow());
+  if (E->hasStoredFPFeatures())
+UO->setStoredFPFeatures(E->getStoredFPFeatures());
+
+  return UO;
 }
 
 ExpectedStmt

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 544550f05fd747..4c53d4b7eee9d8 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -10,6 +10,7 @@
 //
 
//===--===//
 
+#include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
@@ -2333,7 +2334,7 @@ TEST_P(ImportFunctions,
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   ImportVirtualOverriddenMethodOnALoopTest) {
+   ImportVirtualOverriddenMethodOnALoop) {
   // B::f() calls => f1() ==> C ==> C::f()
   // \
   //  \ A::f()
@@ -8057,7 +8058,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportDeductionGuideDifferentOrder) {
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   ImportFieldsFirstForCorrectRecordLayoutTest) {
+   ImportFieldsFirstForCorrectRecordLayout) {
   // UnaryOperator(&) triggers RecordLayout computation, which relies on
   // correctly imported fields.
   auto Code =
@@ -8077,6 +8078,45 @@ TEST_P(ASTImporterOptionSpecificTestBase,
   Import(FromF, Lang_CXX11);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportCirularRefFieldsWithoutCorruptedRecordLayoutCache) {
+  // Import sequence: A => A.b => B => B.f() => ... => UnaryOperator(&) 

[clang] 5f2157f - [clang][ASTImporter] Fix friend class template import within dependent context

2023-08-01 Thread via cfe-commits

Author: dingfei
Date: 2023-08-02T11:21:09+08:00
New Revision: 5f2157f8fcaede27ccf4ab215fcb1a4725a36b2a

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

LOG: [clang][ASTImporter] Fix friend class template import within dependent 
context

For friend class template within dependent context:

1. Should not do structure matching checking. This fixes importing failure of
   template with non-type parm;
2. Should not be added into redecls chain.

See Sema::CheckClassTemplate().

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

Reviewed By: aaron.ballman, balazske, shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a6b70042cc50f9..a536a9fe2363cf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -131,6 +131,8 @@ Bug Fixes to C++ Support
 
 Bug Fixes to AST Handling
 ^
+- Fixed an import failure of recursive friend class template.
+  `Issue 64169 `_
 
 Miscellaneous Bug Fixes
 ^^^

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index eb8e28ccd3e622..1ad7067f8ca9c1 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2857,9 +2857,13 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl 
*D) {
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
 IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend;
 
+  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+: DC->isDependentContext();
+  bool DependentFriend = IsFriendTemplate && IsDependentContext;
+
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod() && !D->isLambda()) {
+  if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
 SmallVector ConflictingDecls;
 auto FoundDecls =
 Importer.findDeclsInToCtx(DC, SearchName);
@@ -5796,10 +5800,15 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   if (ToD)
 return ToD;
 
+  bool IsFriendTemplate = D->getFriendObjectKind() != Decl::FOK_None;
+  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+: DC->isDependentContext();
+  bool DependentFriend = IsFriendTemplate && IsDependentContext;
+
   ClassTemplateDecl *FoundByLookup = nullptr;
 
   // We may already have a template of the same name; try to find and match it.
-  if (!DC->isFunctionOrMethod()) {
+  if (!DependentFriend && !DC->isFunctionOrMethod()) {
 SmallVector ConflictingDecls;
 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
 for (auto *FoundDecl : FoundDecls) {

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index c6ae2693930409..544550f05fd747 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -3968,8 +3968,58 @@ TEST_P(ImportClasses, 
ImportNestedPrototypeThenDefinition) {
   EXPECT_EQ(ToDef->getPreviousDecl(), ToProto);
 }
 
-
-struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {};
+struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {
+  void testRecursiveFriendClassTemplate(Decl *FromTu) {
+auto *FromD = FirstDeclMatcher().match(
+FromTu, classTemplateDecl());
+
+auto Pattern = classTemplateDecl(
+has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
+ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
+
+auto *FromFriend =
+FirstDeclMatcher().match(FromD, friendDecl());
+auto *FromRecordOfFriend =
+cast(FromFriend->getFriendDecl())
+->getTemplatedDecl();
+EXPECT_NE(FromRecordOfFriend, FromD->getTemplatedDecl());
+EXPECT_TRUE(FromRecordOfFriend->getPreviousDecl() == nullptr);
+
+auto *FromDC = FromRecordOfFriend->getDeclContext();
+auto *FromLexicalDC = FromRecordOfFriend->getLexicalDeclContext();
+ASSERT_EQ(FromDC, cast(FromTu));
+ASSERT_EQ(FromLexicalDC, cast(FromD->getTemplatedDecl()));
+
+ASSERT_FALSE(FromDC->containsDecl(FromRecordOfFriend));
+ASSERT_FALSE(FromLexicalDC->containsDecl(FromRecordOfFriend));
+ASSERT_FALSE(cast(FromRecordOfFriend)
+ ->getLookupParent()
+ ->lookup(FromRecordOfFriend->getDeclName())
+ .empty());
+
+auto *ToD = Import(FromD, Lang_CXX03);
+

[PATCH] D156749: [modules] Fix error about the same module being defined in different .pcm files when using VFS overlays.

2023-08-01 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D156749#4551596 , @jansvoboda11 
wrote:

> What are the performance implications of making VFS overlays part of the 
> context hash?

I don't have specific measurements but for Xcode projects different targets 
have different VFS overlays. So adding VFS overlays to the context hash would 
prevent module sharing between targets. To use llvm+clang as an example it 
means different libraries will have different versions of the same module. For 
example, clangLex will have its version of llvmSupport and clangSerialization 
will have its version too. Actual impact depends on a project but for clang 
with 29 subdirectories in "clang/lib" an approximate estimate would be 10 times 
more modules to build. Note that clang build doesn't use VFS, so it won't be an 
actual impact on clang build but on projects with the size and structure 
similar to clang.

In D156749#4551596 , @jansvoboda11 
wrote:

>> And it is build system's responsibility to provide `-ivfsoverlay` options 
>> that don't cause observable differences.
>
> I wasn't aware of that. Do we document this anywhere? It surprises me that 
> we'd impose such restriction on the build system. This seems fairly easy to 
> accidentally violate and end up in the same situation - Clang instances with 
> different VFS overlays, identical context hashes and different canonical 
> module map paths for the same module.

There are no documents describing responsibilities  of different components, as 
far as I know. I haven't researched the issue extensively but I think only 
Xcode build system uses VFS overlays. And if you have only one client, it is a 
questionable use of time to formalize the interface. And the absence of formal 
contract allows to evolve different sides faster.

Yes, if a build system provides bad data to a compiler, it can cause errors. 
And there are no ways to force build systems not to do that. I don't think it 
is the compiler's responsibility to verify build system behavior. For example, 
if for incremental build not all impacted files are recompiled (given the 
dependencies are correct) - the compiler shouldn't track it themselves and 
recompile the required files.

In D156749#4551596 , @jansvoboda11 
wrote:

> Alternatively, we could keep VFS overlays out of the context hash but create 
> `` from the on-disk real path of the defining module map and make the 
> whole PCM VFS-agnostic. Then it'd be correct to import that PCM regardless of 
> the specific VFS overlay setup, as long as all VFS queries of the importer 
> resolve the same way they resolved within the instance that built the PCM. 
> Maybe we can force the importer to recompile the PCM if that's not the case, 
> similar to what we do for diagnostic options.

I'm not sure I understand your proposal. Before this change we were calculating 
hash from the on-disk real path of the defining module map. And due to 
different VFS/no-VFS options defining module map is at different locations 
on-disk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156749

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


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-01 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 546301.
jcsxky added a comment.

update patch for pass unittests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
  clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
  clang/test/Analysis/Inputs/ctu-friend-template.h
  clang/test/Analysis/ctu-friend-template.cpp


Index: clang/test/Analysis/ctu-friend-template.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-friend-template.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-friend-template-other.cpp.ast 
%S/Inputs/ctu-friend-template-other.cpp
+// RUN: cp %S/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt 
%t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -Werror=ctu \
+// RUN:   -verify %s
+
+// CHECK: CTU loaded AST file
+
+#include "Inputs/ctu-friend-template.h"
+
+void bar();
+
+int main(){
+   bar(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.h
@@ -0,0 +1,20 @@
+namespace __1{
+
+template
+class A;
+
+template
+class A{
+public:
+   template
+   friend class A;
+
+   A(T x):x(x){}
+   
+   void foo(){}
+   
+private:
+   T x;
+};
+
+}
Index: 
clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt
@@ -0,0 +1 @@
+9:c:@F@bar# ctu-friend-template-other.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template-other.cpp
@@ -0,0 +1,6 @@
+#include "ctu-friend-template.h"
+
+void bar(){
+   __1::A a1(0);
+   a1.foo();
+}
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -44,6 +44,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeVisitor.h"
 #include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/FileManager.h"
@@ -5812,7 +5813,6 @@
   if (FoundTemplate) {
 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
   continue;
-
 if (IsStructuralMatch(D, FoundTemplate)) {
   ClassTemplateDecl *TemplateWithDef =
   getTemplateDefinition(FoundTemplate);
@@ -5824,6 +5824,11 @@
   // see ASTTests test ImportExistingFriendClassTemplateDef.
   continue;
 }
+auto Parents = FoundDecl->getASTContext().getParents(*FoundDecl);
+if (!Parents.empty() && nullptr != Parents.begin()->get() 
&&
+FoundTemplate->getName() == D->getName()) {
+  continue;
+}
 ConflictingDecls.push_back(FoundDecl);
   }
 }


Index: clang/test/Analysis/ctu-friend-template.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-friend-template.cpp
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-friend-template-other.cpp.ast %S/Inputs/ctu-friend-template-other.cpp
+// RUN: cp %S/Inputs/ctu-friend-template.cpp.externalDefMap-dump.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -Werror=ctu \
+// RUN:   -verify %s
+
+// CHECK: CTU loaded AST file
+
+#include "Inputs/ctu-friend-template.h"
+
+void bar();
+
+int main(){
+	bar(); // expected-no-diagnostics
+}
Index: clang/test/Analysis/Inputs/ctu-friend-template.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-friend-template.h
@@ -0,0 +1,20 @@
+namespace __1{
+
+template
+class A;
+
+template
+class A{
+public:
+	template
+	friend class A;
+
+	A(T x):x(x){}
+	

[PATCH] D156201: [ASTImporter] Fix corrupted RecordLayout introduced by circular referenced fields

2023-08-01 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D156201#4551464 , @aaron.ballman 
wrote:

> LGTM!
>
> In D156201#4551332 , @danix800 
> wrote:
>
>> In D156201#4551270 , @steakhal 
>> wrote:
>>
>>> Have you considered back porting this to clang-17?
>>
>> How to backport? I'm not familiar with this. Is it plain `cherry-pick` to 
>> specific branch?
>
> We have some documented instructions here: 
> https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches 
> -- I don't oppose adding this to the release branch (it seems simple and 
> straightforward enough), but if it's not fixing a regression or other 
> critical issue, it might make sense to leave it out of 17.x so there's less 
> moving parts during the release.

I'll leave it out of 17.x.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156201

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


[PATCH] D155661: [clang][ASTImporter] Fix friend class template import within dependent context

2023-08-01 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D155661#4550340 , @balazske wrote:

> The fix looks OK, but the test could be improved and cleaned up (for example 
> `FromClass` is the same as `FromD` in the test, and DeclContext is not 
> checked, can be done like in the test 
> `UndeclaredFriendClassShouldNotBeVisible` but the AST is different).

Testcase will be cleaned up in the final commit.

> Probably there are other similar cases, and there is a related problem shown 
> in D156693  (the fix in that patch is not 
> correct, the solution here is not good for that case, it is possible that the 
> same code as here needs to be changed again or a better fix is found). I am 
> accepting this code but probably will create a new patch to improve and add 
> tests for similar cases (if not done before by somebody else).

Confirmed, but I'll not touch this issue in this commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155661

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


[PATCH] D156686: [AST] Simplify Type::isSizelessBuiltinType(). NFC.

2023-08-01 Thread Jim Lin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c1066797c5b: [AST] Simplify Type::isSizelessBuiltinType(). 
NFC. (authored by Jim).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156686

Files:
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2353,14 +2353,11 @@
 }
 
 bool Type::isSizelessBuiltinType() const {
+  if (isSVESizelessBuiltinType() || isRVVSizelessBuiltinType())
+return true;
+
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {
-  // SVE Types
-#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/AArch64SVEACLETypes.def"
-#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/RISCVVTypes.def"
-  return true;
   // WebAssembly reference types
 #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/WebAssemblyReferenceTypes.def"


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2353,14 +2353,11 @@
 }
 
 bool Type::isSizelessBuiltinType() const {
+  if (isSVESizelessBuiltinType() || isRVVSizelessBuiltinType())
+return true;
+
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {
-  // SVE Types
-#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/AArch64SVEACLETypes.def"
-#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/RISCVVTypes.def"
-  return true;
   // WebAssembly reference types
 #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1c10667 - [AST] Simplify Type::isSizelessBuiltinType(). NFC.

2023-08-01 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2023-08-02T10:46:42+08:00
New Revision: 1c1066797c5bb56616dc485b596fd40d5f03ece2

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

LOG: [AST] Simplify Type::isSizelessBuiltinType(). NFC.

Reuse isSVESizelessBuiltinType() and isRVVSizelessBuiltinType().

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index cd1bcc4f17cdc6..8af6e296a20efb 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2353,14 +2353,11 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
 }
 
 bool Type::isSizelessBuiltinType() const {
+  if (isSVESizelessBuiltinType() || isRVVSizelessBuiltinType())
+return true;
+
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {
-  // SVE Types
-#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/AArch64SVEACLETypes.def"
-#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
-#include "clang/Basic/RISCVVTypes.def"
-  return true;
   // WebAssembly reference types
 #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/WebAssemblyReferenceTypes.def"



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


[PATCH] D156771: [clang][hexagon] Handle library path arguments earlier

2023-08-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

(After D156363 , newer tests can use `-### 
-Werror` instead of `-fdriver-only -v -Werror` :) )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156771

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


[PATCH] D156806: [Modules] Add test for merging of template member parent

2023-08-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156806

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


[PATCH] D156718: [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is enabled

2023-08-01 Thread Mariusz Borsa via Phabricator via cfe-commits
wrotki accepted this revision.
wrotki added a comment.

Yes, it looks good. I downloaded the patch and ran the test - had some doubts 
about 'otool -L %t |grep -q "dynamic.dylib"' - but verified with other ASAN 
tests binaries  and convinced myself that it's the right thing to do.


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

https://reviews.llvm.org/D156718

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


[PATCH] D152793: [RISCV] Add MC layer support for Zicfiss.

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:233
 
+def uimm10 : Operand, ImmLeaf(Imm);}]> {
+  let ParserMatchClass = UImmAsmOperand<10>;

Is this used?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td:35
+class RV_SSPop _rd, bits<5> _rs1, string opcodestr, string argstr> :
+  RVInstI<0b100, OPC_SYSTEM, (outs GPR:$rd), (ins GPR:$rs1), opcodestr, 
argstr> {
+  let rd = _rd;

Why are there ins and outs here that aren't encoded?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td:56
+let Predicates = [HasStdExtZicfiss] in {
+def SSLoadX1: RV_SSPop<0b1, 0b0, "ssload", "x1">;
+def SSLoadX5: RV_SSPop<0b00101, 0b0, "ssload", "x5">;

Need to be able to parse with `ra` instead of x1 and `t0` instead of x5. 

I think you might need a new Operand type so the parse can parse it as a 
register.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152793

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


[PATCH] D105671: [Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.

2023-08-01 Thread Jon Roelofs via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGed83797f3cbf: [Intrinsics][ObjC] Mark objc_retain and 
friends as thisreturn. (authored by jroelofs).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105671

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll

Index: llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
===
--- llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
+++ llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
@@ -9,7 +9,7 @@
 define ptr @test_objc_autorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_autorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr %arg0)
+; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.autorelease(ptr %arg0)
@@ -39,7 +39,7 @@
 define ptr @test_objc_autoreleaseReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_autoreleaseReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.autoreleaseReturnValue(ptr %arg0)
@@ -119,7 +119,7 @@
 define ptr @test_objc_retain(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retain
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retain(ptr %arg0)
@@ -129,7 +129,7 @@
 define ptr @test_objc_retainAutorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retainAutorelease(ptr %arg0)
@@ -139,7 +139,7 @@
 define ptr @test_objc_retainAutoreleaseReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutoreleaseReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = tail call ptr @llvm.objc.retainAutoreleaseReturnValue(ptr %arg0)
@@ -149,7 +149,7 @@
 define ptr @test_objc_retainAutoreleasedReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %arg0)
@@ -213,7 +213,7 @@
 define ptr @test_objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %arg0)
@@ -260,7 +260,7 @@
 define ptr @test_objc_retain_autorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retain_autorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retain.autorelease(ptr %arg0)
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -162,6 +162,16 @@
 CallInst::TailCallKind TCK = CI->getTailCallKind();
 NewCI->setTailCallKind(std::max(TCK, OverridingTCK));
 
+// Transfer the 'returned' attribute from the intrinsic to the call site.
+// By applying this only to intrinsic call sites, we avoid applying it to
+// non-ARC explicit calls to things like objc_retain which have not been
+// auto-upgraded to use the intrinsics.
+unsigned Index;
+if (F.getAttributes().hasAttrSomewhere(Attribute::Returned, ) &&
+Index)
+  NewCI->addParamAttr(Index - AttributeList::FirstArgIndex,
+  Attribute::Returned);
+
 if (!CI->use_empty())
   CI->replaceAllUsesWith(NewCI);
 CI->eraseFromParent();
Index: 

[clang] ed83797 - [Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.

2023-08-01 Thread Jon Roelofs via cfe-commits

Author: Jon Roelofs
Date: 2023-08-01T18:02:00-07:00
New Revision: ed83797f3cbfc8fb2a1af63542f97d7ec1d5505a

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

LOG: [Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain

rdar://79869679

Differential revision: https://reviews.llvm.org/D105671

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenObjC/arc.m
clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index e2f26782583727..43f5ae8d68c664 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3404,9 +3404,9 @@ static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction 
,
   const VarDecl *self = method->getSelfDecl();
   if (!self->getType().isConstQualified()) return nullptr;
 
-  // Look for a retain call.
-  llvm::CallInst *retainCall =
-dyn_cast(result->stripPointerCasts());
+  // Look for a retain call. Note: stripPointerCasts looks through returned arg
+  // functions, which would cause us to miss the retain.
+  llvm::CallInst *retainCall = dyn_cast(result);
   if (!retainCall || retainCall->getCalledOperand() !=
  CGF.CGM.getObjCEntrypoints().objc_retain)
 return nullptr;

diff  --git a/clang/test/CodeGenObjC/arc.m b/clang/test/CodeGenObjC/arc.m
index 997bbc3f6b1ee3..c220d4f69337cb 100644
--- a/clang/test/CodeGenObjC/arc.m
+++ b/clang/test/CodeGenObjC/arc.m
@@ -7,30 +7,30 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 
-Wno-objc-root-class -Wno-incompatible-pointer-types 
-Wno-arc-unsafe-retained-assign -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s
 
 // ARC-ALIEN: declare extern_weak void @llvm.objc.storeStrong(ptr, ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retain(ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autoreleaseReturnValue(ptr)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retain(ptr returned)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autoreleaseReturnValue(ptr 
returned)
 // ARC-ALIEN: declare ptr @objc_msgSend(ptr, ptr, ...) [[NLB:#[0-9]+]]
 // ARC-ALIEN: declare extern_weak void @llvm.objc.release(ptr)
-// ARC-ALIEN: declare extern_weak ptr 
@llvm.objc.retainAutoreleasedReturnValue(ptr)
+// ARC-ALIEN: declare extern_weak ptr 
@llvm.objc.retainAutoreleasedReturnValue(ptr returned)
 // ARC-ALIEN: declare extern_weak ptr @llvm.objc.initWeak(ptr, ptr)
 // ARC-ALIEN: declare extern_weak ptr @llvm.objc.storeWeak(ptr, ptr)
 // ARC-ALIEN: declare extern_weak ptr @llvm.objc.loadWeakRetained(ptr)
 // ARC-ALIEN: declare extern_weak void @llvm.objc.destroyWeak(ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autorelease(ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutorelease(ptr)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autorelease(ptr returned)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutorelease(ptr 
returned)
 
 // ARC-NATIVE: declare void @llvm.objc.storeStrong(ptr, ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.retain(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
+// ARC-NATIVE: declare ptr @llvm.objc.retain(ptr returned)
+// ARC-NATIVE: declare ptr @llvm.objc.autoreleaseReturnValue(ptr returned)
 // ARC-NATIVE: declare ptr @objc_msgSend(ptr, ptr, ...) [[NLB:#[0-9]+]]
 // ARC-NATIVE: declare void @llvm.objc.release(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
+// ARC-NATIVE: declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr 
returned)
 // ARC-NATIVE: declare ptr @llvm.objc.initWeak(ptr, ptr)
 // ARC-NATIVE: declare ptr @llvm.objc.storeWeak(ptr, ptr)
 // ARC-NATIVE: declare ptr @llvm.objc.loadWeakRetained(ptr)
 // ARC-NATIVE: declare void @llvm.objc.destroyWeak(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.autorelease(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.retainAutorelease(ptr)
+// ARC-NATIVE: declare ptr @llvm.objc.autorelease(ptr returned)
+// ARC-NATIVE: declare ptr @llvm.objc.retainAutorelease(ptr returned)
 
 // CHECK-LABEL: define{{.*}} void @test0
 void test0(id x) {

diff  --git a/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m 
b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
index 9a5ecbc03d8ae6..a60c9b0feb801f 100644
--- a/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
+++ b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -28,6 +28,11 @@ void test1(id x) 

[PATCH] D152793: [RISCV] Add MC layer support for Zicfiss.

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Please update llvm/docs/RISCVUsage.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152793

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


[PATCH] D153059: [-Wunsafe-buffer-usage] Group parameter fix-its

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

OOo down to ±300, I love this!! I'll take a closer look tomorrow.




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1891-1892
+  for (unsigned i = 0; i < NumParms; i++) {
+if (!ParmsMask[i])
+  continue;
+

Speaking of [[ https://reviews.llvm.org/D156762#inline-1517322 |my comment on 
the other patch]].

Can we simply ask `Strategy` about the strategy for `FD->getParamDecl(i)` 
instead of passing a mask?

Eventually we'll have to do that anyway, given how different parameters can be 
assigned different strategies.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1935
 // print parameter name if provided:
-if (IdentifierInfo * II = Parm->getIdentifier())
-  SS << " " << II->getName().str();
-  } else if (auto ParmTypeText =
- getRangeText(Parm->getSourceRange(), SM, LangOpts)) {
+if (auto II = Parm->getIdentifier())
+  SS << ' ' << II->getName().str();

Arguably not a great use of `auto`, because the return type isn't literally 
`Identifier *`.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2430
+  // The union group over the ones in "Groups" that contain parameters of `D`:
+  llvm::SetVector
+  GrpsUnionForParms; // these variables need to be fixed in one step

ziqingluo-90 wrote:
> NoQ wrote:
> > Why `SetVector`? Do we care about order? Maybe just `SmallSet`?
> We'd like to keep the order of elements in this container deterministic.  
> Otherwise, the diagnostic message that lists those elements could be 
> non-deterministic.
Ooo right gotcha!



Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:2171
+if (VarGroupForVD.size() <= 1)
+  return "";
+

ziqingluo-90 wrote:
> NoQ wrote:
> > Does the empty string actually ever make sense for the caller? Maybe just 
> > assert that this never happens, and force the caller to check that?
> The branch deals with the case where the group has only one member, which is 
> the `VD`.  In that case, we do not list group mates of `VD` as there is none. 
>   
> This case is actually possible and conforms to the contract of this method.
> 
> The case where the group is empty is not suppose to happen.
Gotcha, nice!


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

https://reviews.llvm.org/D153059

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


[PATCH] D156221: [RISCV] Support overloaded version ntlh intrinsic function

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I think another option could be to do this in SemaChecking.cpp where we 
implement __builtin_riscv_ntl_load and __builtin_riscv_ntl_store. We already do 
custom type checking there. We could detect the missing argument and give it a 
default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156221

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


[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2219
+  // cannot be fixed...
+  eraseVarsForUnfixableGroupMates(FixItsForVariable, VarGrpMgr);
+  // Now `FixItsForVariable` gets further reduced: a variable is in

NoQ wrote:
> Architecturally speaking, I think I just realized something confusing about 
> our code.
> 
> We already have variable groups well-defined at the Strategy phase, i.e. 
> before we call `getFixIts()`, but then `getFixIts()` continues to reason 
> about all variables collectively and indiscriminately. It continues to use 
> entities such as the `FixItsForVariable` map which contain fixits for 
> variables from *all* groups, not just the ones that are currently relevant. 
> Then it re-introduces per-group data structures such as `ParmsNeedFixMask` on 
> an ad-hoc basis, and it tries to compute them this way using the global, 
> indiscriminate data structures.
> 
> I'm starting to suspect that the code would start making a lot more sense if 
> we invoke `getFixIts()` separately for each variable group. So that each such 
> invocation produced a single collective fixit for the group, or failed doing 
> so.
> 
> This way we might be able to avoid sending steganographic messages through 
> `FixItsForVariable`, but instead say directly "these are the variables that 
> we're currently focusing on". It is the responsibility of the `Strategy` 
> class to answer "should this variable be fixed?"; we shouldn't direct that 
> question to any other data structures.
> 
> And if a group fails at any point, just early-return `None` and proceed 
> directly to the next getFixIts() invocation for the next group. We don't need 
> to separately record which individual variables have failed. In particular, 
> `eraseVarsForUnfixableGroupMates()` would become a simple early return.
> 
> It probably also makes sense to store groups themselves inside the `Strategy` 
> class. After all, fixing variables together is a form of strategy.
(I don't think this needs to be addressed in the current patch, but this could 
help us untangle the code in general.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

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


[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2219
+  // cannot be fixed...
+  eraseVarsForUnfixableGroupMates(FixItsForVariable, VarGrpMgr);
+  // Now `FixItsForVariable` gets further reduced: a variable is in

Architecturally speaking, I think I just realized something confusing about our 
code.

We already have variable groups well-defined at the Strategy phase, i.e. before 
we call `getFixIts()`, but then `getFixIts()` continues to reason about all 
variables collectively and indiscriminately. It continues to use entities such 
as the `FixItsForVariable` map which contain fixits for variables from *all* 
groups, not just the ones that are currently relevant. Then it re-introduces 
per-group data structures such as `ParmsNeedFixMask` on an ad-hoc basis, and it 
tries to compute them this way using the global, indiscriminate data structures.

I'm starting to suspect that the code would start making a lot more sense if we 
invoke `getFixIts()` separately for each variable group. So that each such 
invocation produced a single collective fixit for the group, or failed doing so.

This way we might be able to avoid sending steganographic messages through 
`FixItsForVariable`, but instead say directly "these are the variables that 
we're currently focusing on". It is the responsibility of the `Strategy` class 
to answer "should this variable be fixed?"; we shouldn't direct that question 
to any other data structures.

And if a group fails at any point, just early-return `None` and proceed 
directly to the next getFixIts() invocation for the next group. We don't need 
to separately record which individual variables have failed. In particular, 
`eraseVarsForUnfixableGroupMates()` would become a simple early return.

It probably also makes sense to store groups themselves inside the `Strategy` 
class. After all, fixing variables together is a form of strategy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-01 Thread Artem Labazov via Phabricator via cfe-commits
artem updated this revision to Diff 546269.
artem added a comment.

typo fix


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

https://reviews.llvm.org/D156821

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c
  clang/test/CodeGen/abs-overflow.c
  clang/test/CodeGen/builtin-abs.c
  clang/test/CodeGenCXX/builtins.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.h
  compiler-rt/test/ubsan/TestCases/Misc/abs.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
@@ -0,0 +1,26 @@
+// REQUIRES: arch=x86_64
+//
+// RUN: %clangxx -fsanitize=builtin -fno-sanitize-recover=signed-integer-overflow -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+// RUN: %clangxx -fsanitize=signed-integer-overflow -fno-sanitize-recover=builtin -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+//
+// RUN: %clangxx -fsanitize=builtin -fsanitize=signed-integer-overflow -fno-sanitize-recover=builtin -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+// RUN: %clangxx -fsanitize=builtin -fsanitize=signed-integer-overflow -fno-sanitize-recover=signed-integer-overflow -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+
+#include 
+
+int main() {
+  // ABORT: abs.cpp:[[@LINE+2]]:17: runtime error: passing minimal signed integer to abs(), which overflows
+  // RECOVER: abs.cpp:[[@LINE+1]]:17: runtime error: passing minimal signed integer to abs(), which overflows
+  __builtin_abs(INT_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+1]]:18: runtime error: passing minimal signed integer to abs(), which overflows
+  __builtin_labs(LONG_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+1]]:19: runtime error: passing minimal signed integer to abs(), which overflows
+  __builtin_llabs(LLONG_MIN);
+  return 0;
+}
Index: compiler-rt/lib/ubsan/ubsan_handlers.h
===
--- compiler-rt/lib/ubsan/ubsan_handlers.h
+++ compiler-rt/lib/ubsan/ubsan_handlers.h
@@ -158,6 +158,7 @@
 enum BuiltinCheckKind : unsigned char {
   BCK_CTZPassedZero,
   BCK_CLZPassedZero,
+  BCK_AbsPassedBadVal,
 };
 
 struct InvalidBuiltinData {
Index: compiler-rt/lib/ubsan/ubsan_handlers.cpp
===
--- compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -626,9 +626,13 @@
 
   ScopedReport R(Opts, Loc, ET);
 
-  Diag(Loc, DL_Error, ET,
-   "passing zero to %0, which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+  if (Data->Kind == BCK_AbsPassedBadVal) {
+Diag(Loc, DL_Error, ET,
+ "passing minimal signed integer to abs(), which overflows");
+  } else {
+Diag(Loc, DL_Error, ET, "passing zero to %0, which is not a valid argument")
+<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+  }
 }
 
 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
Index: clang/test/CodeGenCXX/builtins.cpp
===
--- clang/test/CodeGenCXX/builtins.cpp
+++ clang/test/CodeGenCXX/builtins.cpp
@@ -53,7 +53,8 @@
 extern "C" int __builtin_abs(int); // #3
 
 int x = __builtin_abs(-2);
-// CHECK:  store i32 2, ptr @x, align 4
+// CHECK:  [[X:%.*]] = call i32 @llvm.abs.i32(i32 -2, i1 true)
+// CHECK:  store i32 [[X]], ptr @x, align 4
 
 long y = __builtin_abs(-2l);
 // CHECK:  [[Y:%.+]] = call noundef i64 @_Z13__builtin_absl(i64 noundef -2)
Index: clang/test/CodeGen/builtin-abs.c
===
--- clang/test/CodeGen/builtin-abs.c
+++ clang/test/CodeGen/builtin-abs.c
@@ -2,27 +2,21 @@
 
 int absi(int x) {
 // CHECK-LABEL: @absi(
-// CHECK:   [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i32 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[X]]
+// CHECK:   [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
 //
   return __builtin_abs(x);
 }
 
 long absl(long x) {
 // CHECK-LABEL: @absl(
-// CHECK:   [[NEG:%.*]] = sub nsw i64 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i64 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i64 [[NEG]], i64 [[X]]
+// CHECK:   [[ABS:%.*]] = call i64 @llvm.abs.i64(i64 [[X:%.*]], i1 true)
 //
   return __builtin_labs(x);
 }
 
 long long absll(long long x) {
 // CHECK-LABEL: @absll(
-// CHECK:   [[NEG:%.*]] = sub nsw i64 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i64 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i64 [[NEG]], i64 [[X]]
+// CHECK:   [[ABS:%.*]] = call i64 @llvm.abs.i64(i64 [[X:%.*]], i1 true)
 //
   return __builtin_llabs(x);
 }

[PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-08-01 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

Hi @dblaikie

Thank you for the detailed response!

> So you get some bunch of annotations from the BTFTagAttributedType, then you 
> build the underlying type (which might already be built/needed/fine because 
> it's used without attributes in other places/needs to exist independently) - 
> and then at the end you copy any of these types that are needed and put the 
> annotations on them?

Yes.

> Does the BTFTagAttributedType always have to apply to the immediate type 
> that's going to be modified/mutated to have the attributes applied to it 
> directly? Is the set of types that may have these attributes/annotations 
> added small/closed? (struct types, void, anything else? could you add tags to 
> int __tag *, for instance and get a DW_TAG_base_type for "int" with 
> annotations on it?

We decided against applying it to const/volatile/restrict, but it can be 
applied to struct types, void, "base" types ("int"), pointers and typedefs.

> If it's really generic/can apply to any type - but always the /immediate/ 
> type (I guess with the special handling you've got to skip applying it to the 
> DW_TAG_const_type, etc)...
>
> What if you skipped getOrCreateType - and called into the CreateType dispatch 
> below that? Since you never want a cached instance of a type, right? You want 
> to create a new copy of the type you could then apply annotations to.
>
> Except, I guess, in the instance you showed, where the type is being 
> completed - can't go and create another one, because we're part-way through 
> building this one... hmm, maybe you can, though? What happens if we start 
> making a totally distinct copy of that same type? I guess there's some map 
> that contains such partially completed types, and that map would get 
> confused/break if we tried to build two types for the same type without 
> adding in some extra key goo that contained the annotations... - maybe that 
> wouldn't be too invasive, though?

I made a prototype of such change, available here 
.
 The interesting function is `CGDebugInfo::CreateType(const 
BTFTagAttributedType *Ty, ...)`.
Pseudo code for old version (this revision):

  def CGDebugInfo::CreateType(const BTFTagAttributedType *Ty, ...):
WrappedTy, Annotations = collect annotations are base type from Ty
WrappedDI = getOrCreateType(WrappedTy, ...)
Placeholder = create temporary placeholder node with
  references to WrappedDI and Annotations
AnnotationPlaceholders.push_back(Placeholder)
return Placeholder

  def CGDebugInfo::finalize():
...
for Placeholder in AnnotationPlaceholders:
  T = Placeholder.WrappedDI.Clone()
  T.replaceAnnotations(Placeholder.Annotations)
  replace Placeholder with T

Pseudo code for new version (link to my github from above):

  def CGDebugInfo::CreateType(const BTFTagAttributedType *Ty, ...):
WrappedTy, Annotations = collect annotations are base type from Ty
Placeholder = empty temporary node
TypeCache[Ty] = Placeholder
WrappedDI = CreateType(UnwrapTypeForDebugInfo(WrappedTy), ...)
T = WrappedDI.Clone()
T.replaceAnnotations(Annotations)
replace Placeholder with T
return T

Comparing the "old" and "new" versions "old" appears to be less hacky to me: it 
does not break `getOrCreateType()` abstraction and it does not process members 
two times for circular types.

Note that this 

 diff is important for the new version, without it `CreateType` won't actually 
create a new object in the circular type case. I checked call-graph for 
`CreateType(RecordType *)` and it looks like it is only invoked from 
`getOrCreateType()`, so `getTypeOrNull()` within it is not actually needed. It 
was added in commit 3b1cc9b85846 back in 2013. Test cases for that commit are 
passing.

> given this code:
>
>   #define __tag1 __attribute__((btf_type_tag("tag1")))
>   
>   struct st {
> struct st *self;
>   };
>   struct st __tag1 x;
>
> What's the expected DWARF here? x's type is a the attributed/annotated st 
> type, but then does the self pointer inside there point to the attributed 
> type or the unattributed type?

The `self` should have type w/o tag, the `x` should have type with tag.

> Maybe what you've got is the best of some bad options, but I'm not 
> sure/trying to think it through. (@aprantl wouldn't mind your perspective - 
> if it's too much to consume easily, let me know and I can make a best-effort 
> at summarizing, maybe even better over a video chat if you've got a few 
> minutes)

I appreciate the effort, if you and @aprantl decide that the call is necessary 
I can attend if you need me.


Repository:
  rG LLVM 

[PATCH] D155814: Fix the linting problems which causes `clang/utils/ci/run-buildbot check-format` to return 1.

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Looks like rG910450a28ba9c 
 has 
independently addressed both issues. But at least we had a chance to deal with 
the injustice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155814

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


[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I really like this!




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2178
+  // `FixItsForVariable` will map each variable to a set of fix-its directly
+  // associated to the variable itself.  Fix-its of distict variables in
+  // `FixItsForVariable` are disjoint.





Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2243
+  // 1. overlap with macros or/and templates; or
+  // 2. conflicting each other.
+  // Otherwise, the fix-its will be dropped.





Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2293
   // Instead, it should be visited along with the outer method.
+  // FIXME: do we want to do the same thing for `BlockDecl`s?
   if (const auto *fd = dyn_cast(D)) {

Hmm, do we suffer from a crash similar to D150386 in presence of blocks instead 
of lambdas?

I vaguely remember that there were subtle differences, but I also think our 
approach should probably be the same, so this fixme is probably correct.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2526-2533
+  if (isa(D))
+// The only case where `D` is not a `FunctionDecl` is when `D` is a
+// `BlockDecl`.  Let's NOT try to fix variables in blocks for now. Becuase
+// those variables could be declared implicitly (captured variables) or in
+// enclosing scopes.
+FixItsForVariableGroup =
+getFixIts(FixablesForAllVars, NaiveStrategy, D->getASTContext(),

A bit more idiomatic this way.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2527-2530
+// The only case where `D` is not a `FunctionDecl` is when `D` is a
+// `BlockDecl`.  Let's NOT try to fix variables in blocks for now. Becuase
+// those variables could be declared implicitly (captured variables) or in
+// enclosing scopes.

Ultimately we should accept `ObjCMethodDecl` here, and we should also accept 
`BlockDecl`s that live in global scope (where they can't be checked together 
with the surrounding function because there's no surrounding function).

Of course parameter fixits are going to be quite different in these cases, but 
it shouldn't stop us from trying. Even today, even though we don't know how to 
fix ObjC method parameters, we can already encounter cases where fixing local 
variables is sufficient.

In other words, I think `const FunctionDecl *` is the right parameter type for 
eg. `createFunctionOverloadsForParms()` ([[ 
https://reviews.llvm.org/D153059?id=539720#inline-1506914 | like I suggested 
before ]]), but probably not for the entire `getFixits()`,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-01 Thread Artem Labazov via Phabricator via cfe-commits
artem updated this revision to Diff 546261.
artem added a comment.

Fixed comments and failing test. Added a new compiler-rt test for ubsan


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

https://reviews.llvm.org/D156821

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c
  clang/test/CodeGen/abs-overflow.c
  clang/test/CodeGen/builtin-abs.c
  clang/test/CodeGenCXX/builtins.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/lib/ubsan/ubsan_handlers.h
  compiler-rt/test/ubsan/TestCases/Misc/abs.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
@@ -0,0 +1,26 @@
+// REQUIRES: arch=x86_64
+//
+// RUN: %clangxx -fsanitize=builtin -fno-sanitize-recover=signed-integer-overflow -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+// RUN: %clangxx -fsanitize=signed-integer-overflow -fno-sanitize-recover=builtin -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+//
+// RUN: %clangxx -fsanitize=builtin -fsanitize=signed-integer-overflow -fno-sanitize-recover=builtin -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+// RUN: %clangxx -fsanitize=builtin -fsanitize=signed-integer-overflow -fno-sanitize-recover=signed-integer-overflow -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+
+#include 
+
+int main() {
+  // ABORT: abs.cpp:[[@LINE+2]]:17: runtime error: passing a minimal signed integer to abs(), which results in overflow
+  // RECOVER: abs.cpp:[[@LINE+1]]:17: runtime error: passing a minimal signed integer to abs(), which results in overflow
+  __builtin_abs(INT_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+1]]:18: runtime error: passing a minimal signed integer to abs(), which results in overflow
+  __builtin_labs(LONG_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+1]]:19: runtime error: passing a minimal signed integer to abs(), which results in overflow
+  __builtin_llabs(LLONG_MIN);
+  return 0;
+}
Index: compiler-rt/lib/ubsan/ubsan_handlers.h
===
--- compiler-rt/lib/ubsan/ubsan_handlers.h
+++ compiler-rt/lib/ubsan/ubsan_handlers.h
@@ -158,6 +158,7 @@
 enum BuiltinCheckKind : unsigned char {
   BCK_CTZPassedZero,
   BCK_CLZPassedZero,
+  BCK_AbsPassedBadVal,
 };
 
 struct InvalidBuiltinData {
Index: compiler-rt/lib/ubsan/ubsan_handlers.cpp
===
--- compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -626,9 +626,13 @@
 
   ScopedReport R(Opts, Loc, ET);
 
-  Diag(Loc, DL_Error, ET,
-   "passing zero to %0, which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+  if (Data->Kind == BCK_AbsPassedBadVal) {
+Diag(Loc, DL_Error, ET,
+ "passing minimal signed integer to abs(), which results in overflow");
+  } else {
+Diag(Loc, DL_Error, ET, "passing zero to %0, which is not a valid argument")
+<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+  }
 }
 
 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
Index: clang/test/CodeGenCXX/builtins.cpp
===
--- clang/test/CodeGenCXX/builtins.cpp
+++ clang/test/CodeGenCXX/builtins.cpp
@@ -53,7 +53,8 @@
 extern "C" int __builtin_abs(int); // #3
 
 int x = __builtin_abs(-2);
-// CHECK:  store i32 2, ptr @x, align 4
+// CHECK:  [[X:%.*]] = call i32 @llvm.abs.i32(i32 -2, i1 true)
+// CHECK:  store i32 [[X]], ptr @x, align 4
 
 long y = __builtin_abs(-2l);
 // CHECK:  [[Y:%.+]] = call noundef i64 @_Z13__builtin_absl(i64 noundef -2)
Index: clang/test/CodeGen/builtin-abs.c
===
--- clang/test/CodeGen/builtin-abs.c
+++ clang/test/CodeGen/builtin-abs.c
@@ -2,27 +2,21 @@
 
 int absi(int x) {
 // CHECK-LABEL: @absi(
-// CHECK:   [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i32 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[X]]
+// CHECK:   [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
 //
   return __builtin_abs(x);
 }
 
 long absl(long x) {
 // CHECK-LABEL: @absl(
-// CHECK:   [[NEG:%.*]] = sub nsw i64 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i64 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i64 [[NEG]], i64 [[X]]
+// CHECK:   [[ABS:%.*]] = call i64 @llvm.abs.i64(i64 [[X:%.*]], i1 true)
 //
   return __builtin_labs(x);
 }
 
 long long absll(long long x) {
 // CHECK-LABEL: @absll(
-// CHECK:   [[NEG:%.*]] = sub nsw i64 0, [[X:%.*]]
-// CHECK:   [[CMP:%.*]] = icmp slt i64 [[X]], 0
-// CHECK:   [[SEL:%.*]] = select i1 [[CMP]], i64 [[NEG]], i64 

[PATCH] D155814: Fix the linting problems which causes `clang/utils/ci/run-buildbot check-format` to return 1.

2023-08-01 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added a comment.

Hi @AMP999

I have committed this patch on behalf of you.
Unfortunately, I cannot amend an old commit for you as it will cause rewriting 
a bunch of the history. 
I made a correction message along with the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155814

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-01 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao marked an inline comment as done.
SlaterLatiao added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3289-3290
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl())
+Instantiation->setInvalidDecl();
+} else {

dblaikie wrote:
> Is this codepath tested?
Some checks in `Visit` need to be implemented for this branch. I elaborated in 
the comment and will implement in a future differential.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3292-3295
+  // FIXME: Eventually, a NULL return will mean that one of the
+  // instantiations was a semantic disaster, and we'll want to mark
+  // the declaration invalid. For now, we expect to skip some members
+  // that we can't yet handle.

SlaterLatiao wrote:
> dblaikie wrote:
> > Worth having a test case showing that/what's broken here?
> It's copied from the handling of non-pack members and possibly a duplicate 
> that should be avoided. I'm not sure which case could trigger this branch. 
> Will look into it.
We Traced back and could not find a test case associated with this block.  I 
added a cross reference of this to the FIXME below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D155814: Fix the linting problems which causes `clang/utils/ci/run-buildbot check-format` to return 1.

2023-08-01 Thread Ziqing Luo 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 rG82b94a9f7be9: Fix the linting problems in 
UnsafeBufferUsage.cpp (authored by AMP999, committed by ziqingluo-90).

Changed prior to commit:
  https://reviews.llvm.org/D155814?vs=542972=546260#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155814

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp


Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2267,7 +2267,6 @@
 #endif
 
   assert(D && D->getBody());
-
   // We do not want to visit a Lambda expression defined inside a method 
independently.
   // Instead, it should be visited along with the outer method.
   if (const auto *fd = dyn_cast(D)) {


Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2267,7 +2267,6 @@
 #endif
 
   assert(D && D->getBody());
-
   // We do not want to visit a Lambda expression defined inside a method independently.
   // Instead, it should be visited along with the outer method.
   if (const auto *fd = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82b94a9 - Fix the linting problems in UnsafeBufferUsage.cpp

2023-08-01 Thread via cfe-commits

Author: Amirreza Ashouri
Date: 2023-08-01T16:17:40-07:00
New Revision: 82b94a9f7be9474acd0a950ce521c439057066be

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

LOG: Fix the linting problems in UnsafeBufferUsage.cpp

Fix the linting problems which causes `clang/utils/ci/run-buildbot 
check-format` to return 1.

Also make a correction for the email address of the author of
0fd4175907b40fe63131482c162d7e0f76000521:

  The correct email address is "ar.ashouri...@gmail.com", not 
"ar.ashouri...@google.com".

Reviewed by: ziqingluo-90 (Ziqing Luo)

Differential revision: https://reviews.llvm.org/D155814

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 5782ad7e6e443e..6f9f5f5e7ee7f2 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2267,7 +2267,6 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
 #endif
 
   assert(D && D->getBody());
-
   // We do not want to visit a Lambda expression defined inside a method 
independently.
   // Instead, it should be visited along with the outer method.
   if (const auto *fd = dyn_cast(D)) {



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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-01 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 546257.
SlaterLatiao added a comment.

- Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,9 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for data member packs.
+  // https://discourse.llvm.org/t/adding-support-for-data-member-packs/71333
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5954,7 +5957,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,81 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+if (Decl *NewMember = Instantiator.Visit(Member)) {
+  FieldDecl *PackedField = cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl()) {
+// When `NewMember` has type of `PackExpansionType`, it escapes
+// validation checks in `Visit`. Handling of such cases
+

[PATCH] D156743: clang/OpenCL: Add inline implementations of sqrt in builtin header

2023-08-01 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Headers/opencl-c-base.h:832
+
+inline float __ovld __cnfn sqrt(float __x) {
+  return __builtin_elementwise_sqrt(__x);

Is this a generic implementation enough? Would some targets not need to do 
something different for this built-in?

Ideally this header is to be kept light so I am a bit worried about adding 
definitions of the functions here. Otherwise we will end up in the same 
situation as we one day were with opencl-c.h. So could these be left there 
instead? It might be good to check with @svenvh if TableGen header has already 
a way to do this function forwarding or can be extended to do such a thing. 
Then it would be implementable in the both header mechanisms. I don't know if 
Sven has some other ideas or opinions...


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

https://reviews.llvm.org/D156743

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


[PATCH] D156474: [-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the code

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1143
+   // order is deterministic:
+   CompareNode>
+  byVar;

t-rasmud wrote:
> NoQ wrote:
> > ziqingluo-90 wrote:
> > > To make the order of variables in every group deterministic.
> > Would it make sense to immediately clean up the regexps in tests then?
> @NoQ I had an offline discussion with @ziqingluo-90 about this and we agreed 
> (IIRC) that I would clean up the tests since I added those regexps. I plan to 
> create a patch as soon as this lands. Does that make sense?
Yes sure SGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156474

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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

> We also are tied to OpenCL semantic of future versions.

This is what I would like to avoid aliasing to OpenCL and then starting to 
change it in a way that is not conforming or documented. Maybe there is a need 
for something like an address space for the group of related languages or 
something like that and also a way to derive and specialise from the class 
instead of forking and copying/pasting.

There were a number of proposals for similar things in the past including 
improvement to the target specific address spaces 
https://reviews.llvm.org/D62574.

If what we currently have is not good enough for all purposes perhaps it would 
make sense to start an RFC describing the problems and the requirements and 
then working out the solution that works for all the use cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-08-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I glanced at the patch. The code seems reasonable.




Comment at: clang/test/lit.cfg.py:383
 
-# The llvm-nm tool supports an environment variable "OBJECT_MODE" on AIX OS, 
which
+# Some tool support an environment variable "OBJECT_MODE" on AIX OS, which
 # controls the kind of objects they will support. If there is no "OBJECT_MODE"





Comment at: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp:488
+  Thin ? object::Archive::K_GNU : object::Archive::K_COFF,
+  /*Deterministic*/ true, Thin, nullptr, COFF::isArm64EC(LibMachine))) 
{
 handleAllErrors(std::move(E), [&](const ErrorInfoBase ) {





Comment at: llvm/test/tools/llvm-ranlib/non-AIX-not-supported-X-option.test:1
+## REQUIRES: !system-aix
+## Test the -X option is not supported on non-AIX os.

`UNSUPPORTED: system-aix`

I think the convention is to name `aix-X-option.test` and 
`non-AIX-not-supported-X-option.test` with a shared prefix to make identify 
such tests easier.

Perhaps the file can be renamed to `AIX-X-option-non-AIX.test` or similar.



Comment at: llvm/test/tools/llvm-ranlib/non-AIX-not-supported-X-option.test:4
+
+# RUN: not llvm-ranlib -X32 2>&1 | FileCheck --implicit-check-not="error:"  
--check-prefixes=INVALID-X-OPTION %s
+

With one prefix, we prefer `--check-prefix=`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142660

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


[PATCH] D156474: [-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the code

2023-08-01 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1143
+   // order is deterministic:
+   CompareNode>
+  byVar;

NoQ wrote:
> ziqingluo-90 wrote:
> > To make the order of variables in every group deterministic.
> Would it make sense to immediately clean up the regexps in tests then?
@NoQ I had an offline discussion with @ziqingluo-90 about this and we agreed 
(IIRC) that I would clean up the tests since I added those regexps. I plan to 
create a patch as soon as this lands. Does that make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156474

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


[PATCH] D156474: [-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the code

2023-08-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1143
+   // order is deterministic:
+   CompareNode>
+  byVar;

ziqingluo-90 wrote:
> To make the order of variables in every group deterministic.
Would it make sense to immediately clean up the regexps in tests then?



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2318-2319
   if (ImplPair) {
-std::pair Impl = ImplPair.value();
+std::pair Impl = 
std::move(*ImplPair);
 PtrAssignmentGraph[Impl.first].insert(Impl.second);
   }

These objects don't really define any move semantics, so `std::move` is 
probably redundant.

Maybe structured binding instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156474

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


[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-08-01 Thread Danila Kutenin via Phabricator via cfe-commits
danlark added a comment.

In D155809#4551721 , @cor3ntin wrote:

> I think the test we want is a set of classes and virtuaal fuc
>
> In D155809#4551686 , @philnik wrote:
>
>> @aaron.ballman I think what @danlark means is that when building clang 
>> against a libc++ which has debug assertions enabled, the clang tests he 
>> mentioned result in an assertion firing within libc++. i.e. the libc++ debug 
>> mode catches the non-strict weak ordering that it gets from the clang code. 
>> That's why he can't just add a test that fires the assertion. Currently, 
>> there are no bots that build clang against a libc++ with debug assertions 
>> enabled.
>
> What we are asking for is a standalone minimal test that doesn't depend on 
> libc++ at all, living in `clang/test/`

That's impossible. No test will fail because no implementation of 
std::stable_sort calls `comp(a, a)`. Only libcxx calls it in debug mode. But by 
C++ standard rules, `comp(a, a)` is allowed to be called.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155809

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


[PATCH] D76096: [clang] allow const structs/unions/arrays to be constant expressions for C

2023-08-01 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:74-76
+- ``structs``, ``unions``, and ``arrays`` that are const may now be used as
+  constant expressions.  This change is more consistent with the behavior of
+  GCC.

Note to self:
If this lands in time to be backported to release/17.x (as I've tagged 
https://github.com/llvm/llvm-project/issues/44502 to that milestone), I'll need 
to rebase this patch and post to a branch as the result of:

https://discourse.llvm.org/t/llvm-17-x-release-notes-update/72292


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76096

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


[PATCH] D156474: [-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the code

2023-08-01 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2179
+  if (FixItsForVariable.count(GrpMate))
+FinalFixItsForVariable[Var].insert(FinalFixItsForVariable[Var].end(),
+   FixItsForVariable[GrpMate].begin(),

ziqingluo-90 wrote:
> Instead of calling `fixVariable` to generate fix-its for group mates, 
> directly copying those fix-its from the `FixItsForVariable` container.
> 
> At this point,  `FixItsForVariable` is complete. That is, it maps every 
> variable to its own fix-its (excluding fix-its of group mates).
Do you mean "including fix-its of group mates"? If not, I might have 
misunderstood the changes and will take a look again.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2394
+  for (const VarDecl *V : VarGroup) {
+VarGrpMap[V] = GrpIdx;
   }

ziqingluo-90 wrote:
> Mapping variables to group indexes instead of groups themselves to avoid 
> copies.
I think this is a really clever optimization and believe it would save a bunch 
of time and space in code having significant variable grouping. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156474

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


[PATCH] D156718: [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is enabled

2023-08-01 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl accepted this revision.
rsundahl added a comment.
This revision is now accepted and ready to land.

This looks good to me. Thanks for the additional clean-up @thetruestblue.


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

https://reviews.llvm.org/D156718

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


[PATCH] D105671: [Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.

2023-08-01 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs updated this revision to Diff 546219.
jroelofs added a comment.

Rebase. Avoid the dependency on D156735 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105671

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll

Index: llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
===
--- llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
+++ llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
@@ -9,7 +9,7 @@
 define ptr @test_objc_autorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_autorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr %arg0)
+; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.autorelease(ptr %arg0)
@@ -39,7 +39,7 @@
 define ptr @test_objc_autoreleaseReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_autoreleaseReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.autoreleaseReturnValue(ptr %arg0)
@@ -119,7 +119,7 @@
 define ptr @test_objc_retain(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retain
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retain(ptr %arg0)
@@ -129,7 +129,7 @@
 define ptr @test_objc_retainAutorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retainAutorelease(ptr %arg0)
@@ -139,7 +139,7 @@
 define ptr @test_objc_retainAutoreleaseReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutoreleaseReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = tail call ptr @llvm.objc.retainAutoreleaseReturnValue(ptr %arg0)
@@ -149,7 +149,7 @@
 define ptr @test_objc_retainAutoreleasedReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %arg0)
@@ -213,7 +213,7 @@
 define ptr @test_objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0) {
 ; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %arg0)
@@ -260,7 +260,7 @@
 define ptr @test_objc_retain_autorelease(ptr %arg0) {
 ; CHECK-LABEL: test_objc_retain_autorelease
 ; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr returned %arg0)
 ; CHECK-NEXT: ret ptr %0
 entry:
   %0 = call ptr @llvm.objc.retain.autorelease(ptr %arg0)
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -162,6 +162,16 @@
 CallInst::TailCallKind TCK = CI->getTailCallKind();
 NewCI->setTailCallKind(std::max(TCK, OverridingTCK));
 
+// Transfer the 'returned' attribute from the intrinsic to the call site.
+// By applying this only to intrinsic call sites, we avoid applying it to
+// non-ARC explicit calls to things like objc_retain which have not been
+// auto-upgraded to use the intrinsics.
+unsigned Index;
+if (F.getAttributes().hasAttrSomewhere(Attribute::Returned, ) &&
+Index)
+  NewCI->addParamAttr(Index - AttributeList::FirstArgIndex,
+  Attribute::Returned);
+
 if (!CI->use_empty())
   CI->replaceAllUsesWith(NewCI);
 CI->eraseFromParent();
Index: llvm/include/llvm/IR/Intrinsics.td

[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-08-01 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added a comment.

Ping?


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

https://reviews.llvm.org/D155870

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


[PATCH] D156539: [Clang][CodeGen] `__builtin_alloca`s should care about address spaces too

2023-08-01 Thread Alex Voicu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
AlexVlx marked an inline comment as done.
Closed by commit rG51a014cb2d9c: [Clang][CodeGen] `__builtin_alloca`s should 
care about address spaces (authored by AlexVlx).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156539

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dynamic-alloca-with-address-space.c


Index: clang/test/CodeGen/dynamic-alloca-with-address-space.c
===
--- /dev/null
+++ clang/test/CodeGen/dynamic-alloca-with-address-space.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -DOCL12 -x cl -std=cl1.2 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL12
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x cl -std=cl2.0 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL20
+
+#if defined(OCL12)
+#define CAST (char *)(unsigned long)
+#else
+#define CAST (char *)
+#endif
+
+void allocas(unsigned long n) {
+char *a = CAST __builtin_alloca(n);
+char *uninitialized_a = CAST __builtin_alloca_uninitialized(n);
+char *aligned_a = CAST __builtin_alloca_with_align(n, 8);
+char *aligned_uninitialized_a = CAST 
__builtin_alloca_with_align_uninitialized(n, 8);
+}
+
+// CHECK: @allocas(
+// CHECK: store i64 %n, ptr %n.addr.ascast, align 8
+// CHECK: %0 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %1 = alloca i8, i64 %0, align 8, addrspace(5)
+// CHECK: %2 = addrspacecast ptr addrspace(5) %1 to ptr
+// CHECK: store ptr %2, ptr %a.ascast, align 8
+// CHECK: %3 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %4 = alloca i8, i64 %3, align 8, addrspace(5)
+// CHECK: %5 = addrspacecast ptr addrspace(5) %4 to ptr
+// CHECK: store ptr %5, ptr %uninitialized_a.ascast, align 8
+// CHECK: %6 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %7 = alloca i8, i64 %6, align 1, addrspace(5)
+// CHECK: %8 = addrspacecast ptr addrspace(5) %7 to ptr
+// CHECK: store ptr %8, ptr %aligned_a.ascast, align 8
+// CHECK: %9 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %10 = alloca i8, i64 %9, align 1, addrspace(5)
+// CHECK: %11 = addrspacecast ptr addrspace(5) %10 to ptr
+// CHECK: store ptr %11, ptr %aligned_uninitialized_a.ascast, align 8
+// CHECK: ret void
+// CHECK-CL12-NOT: addrspacecast
+// CHECK-CL20-NOT: addrspacecast
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3517,6 +3517,12 @@
 return RValue::get(Result);
   }
 
+  // An alloca will always return a pointer to the alloca (stack) address
+  // space. This address space need not be the same as the AST / Language
+  // default (e.g. in C / C++ auto vars are in the generic address space). At
+  // the AST level this is handled within CreateTempAlloca et al., but for the
+  // builtin / dynamic alloca we have to handle it here. We use an explicit 
cast
+  // instead of passing an AS to CreateAlloca so as to not inhibit 
optimisation.
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca_uninitialized:
@@ -3532,6 +3538,13 @@
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+LangAS AAS = getASTAllocaAddressSpace();
+LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
+if (AAS != EAS) {
+  llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
+  return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
+   EAS, Ty));
+}
 return RValue::get(AI);
   }
 
@@ -3547,6 +3560,13 @@
 AI->setAlignment(AlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
   initializeAlloca(*this, AI, Size, AlignmentInBytes);
+LangAS AAS = getASTAllocaAddressSpace();
+LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
+if (AAS != EAS) {
+  llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
+  return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
+   EAS, Ty));
+}
 return RValue::get(AI);
   }
 


Index: clang/test/CodeGen/dynamic-alloca-with-address-space.c
===
--- /dev/null
+++ clang/test/CodeGen/dynamic-alloca-with-address-space.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN:   | FileCheck %s 

[clang] 51a014c - [Clang][CodeGen] `__builtin_alloca`s should care about address spaces

2023-08-01 Thread Alex Voicu via cfe-commits

Author: Alex Voicu
Date: 2023-08-01T21:55:36+01:00
New Revision: 51a014cb2d9c6f8303f9b11ffc035d69cbeb9e21

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

LOG: [Clang][CodeGen] `__builtin_alloca`s should care about address spaces

`alloca` instructions always return pointers to the `alloca` address space. 
This composes poorly with most HLLs which are address space agnostic and thus 
have all pointers point to generic/default. Static `alloca`s were already 
handled on the AST level, however dynamic `alloca`s were not, which would lead 
to subtly incorrect IR. This patch addresses that by inserting an address space 
cast iff the `alloca` address space is different from the default / expected.

Reviewed By: rjmccall, arsenm

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

Added: 
clang/test/CodeGen/dynamic-alloca-with-address-space.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1f1323e2f92045..803895f64214d9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3517,6 +3517,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 return RValue::get(Result);
   }
 
+  // An alloca will always return a pointer to the alloca (stack) address
+  // space. This address space need not be the same as the AST / Language
+  // default (e.g. in C / C++ auto vars are in the generic address space). At
+  // the AST level this is handled within CreateTempAlloca et al., but for the
+  // builtin / dynamic alloca we have to handle it here. We use an explicit 
cast
+  // instead of passing an AS to CreateAlloca so as to not inhibit 
optimisation.
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca_uninitialized:
@@ -3532,6 +3538,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+LangAS AAS = getASTAllocaAddressSpace();
+LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
+if (AAS != EAS) {
+  llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
+  return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
+   EAS, Ty));
+}
 return RValue::get(AI);
   }
 
@@ -3547,6 +3560,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 AI->setAlignment(AlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
   initializeAlloca(*this, AI, Size, AlignmentInBytes);
+LangAS AAS = getASTAllocaAddressSpace();
+LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
+if (AAS != EAS) {
+  llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
+  return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
+   EAS, Ty));
+}
 return RValue::get(AI);
   }
 

diff  --git a/clang/test/CodeGen/dynamic-alloca-with-address-space.c 
b/clang/test/CodeGen/dynamic-alloca-with-address-space.c
new file mode 100644
index 00..0ef9039e68968e
--- /dev/null
+++ b/clang/test/CodeGen/dynamic-alloca-with-address-space.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -DOCL12 -x cl -std=cl1.2 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL12
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -x cl -std=cl2.0 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CL20
+
+#if defined(OCL12)
+#define CAST (char *)(unsigned long)
+#else
+#define CAST (char *)
+#endif
+
+void allocas(unsigned long n) {
+char *a = CAST __builtin_alloca(n);
+char *uninitialized_a = CAST __builtin_alloca_uninitialized(n);
+char *aligned_a = CAST __builtin_alloca_with_align(n, 8);
+char *aligned_uninitialized_a = CAST 
__builtin_alloca_with_align_uninitialized(n, 8);
+}
+
+// CHECK: @allocas(
+// CHECK: store i64 %n, ptr %n.addr.ascast, align 8
+// CHECK: %0 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %1 = alloca i8, i64 %0, align 8, addrspace(5)
+// CHECK: %2 = addrspacecast ptr addrspace(5) %1 to ptr
+// CHECK: store ptr %2, ptr %a.ascast, align 8
+// CHECK: %3 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %4 = alloca i8, i64 %3, align 8, addrspace(5)
+// CHECK: %5 = addrspacecast ptr addrspace(5) %4 to ptr
+// CHECK: 

[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-08-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I think the test we want is a set of classes and virtuaal fuc

In D155809#4551686 , @philnik wrote:

> @aaron.ballman I think what @danlark means is that when building clang 
> against a libc++ which has debug assertions enabled, the clang tests he 
> mentioned result in an assertion firing within libc++. i.e. the libc++ debug 
> mode catches the non-strict weak ordering that it gets from the clang code. 
> That's why he can't just add a test that fires the assertion. Currently, 
> there are no bots that build clang against a libc++ with debug assertions 
> enabled.

What we are asking for is a standalone minimal test that doesn't depend on 
libc++ at all, living in `clang/test/`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155809

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


[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer

2023-08-01 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG400da115c58a: [clang-format] Fix braced initializer with 
templated base class (authored by galenelias, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156705

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13458,6 +13458,8 @@
   verifyFormat(
   "class A {\n"
   "  A() : a{} {}\n"
+  "  A() : Base{} {}\n"
+  "  A() : Base>{} {}\n"
   "  A(int b) : b(b) {}\n"
   "  A(int a, int b) : a(a), bs{{bs...}} { f(); }\n"
   "  int a, b;\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -581,7 +581,8 @@
   ProbablyBracedList =
   ProbablyBracedList ||
   (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok &&
-   LBraceStack.back().PrevTok->is(tok::identifier));
+   LBraceStack.back().PrevTok->isOneOf(tok::identifier,
+   tok::greater));
 
   ProbablyBracedList =
   ProbablyBracedList ||


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13458,6 +13458,8 @@
   verifyFormat(
   "class A {\n"
   "  A() : a{} {}\n"
+  "  A() : Base{} {}\n"
+  "  A() : Base>{} {}\n"
   "  A(int b) : b(b) {}\n"
   "  A(int a, int b) : a(a), bs{{bs...}} { f(); }\n"
   "  int a, b;\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -581,7 +581,8 @@
   ProbablyBracedList =
   ProbablyBracedList ||
   (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok &&
-   LBraceStack.back().PrevTok->is(tok::identifier));
+   LBraceStack.back().PrevTok->isOneOf(tok::identifier,
+   tok::greater));
 
   ProbablyBracedList =
   ProbablyBracedList ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 400da11 - [clang-format] Fix braced initializer with templated base class

2023-08-01 Thread Owen Pan via cfe-commits

Author: Galen Elias
Date: 2023-08-01T13:53:22-07:00
New Revision: 400da115c58ae19445cfdc871a3f559f160fc5c6

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

LOG: [clang-format] Fix braced initializer with templated base class

Fixes #64134.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index febe43e1ba65f4..5c6e7e2e1194e9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -581,7 +581,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   ProbablyBracedList =
   ProbablyBracedList ||
   (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok &&
-   LBraceStack.back().PrevTok->is(tok::identifier));
+   LBraceStack.back().PrevTok->isOneOf(tok::identifier,
+   tok::greater));
 
   ProbablyBracedList =
   ProbablyBracedList ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e512a861dc4e35..ed0c5e64f44743 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13458,6 +13458,8 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat(
   "class A {\n"
   "  A() : a{} {}\n"
+  "  A() : Base{} {}\n"
+  "  A() : Base>{} {}\n"
   "  A(int b) : b(b) {}\n"
   "  A(int a, int b) : a(a), bs{{bs...}} { f(); }\n"
   "  int a, b;\n"



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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-08-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:290
+  "encoding prefix '%0' on an unevaluated string literal has no effect"
+  "%select{| and is incompatible with c++2c}1">,
+  InGroup>;

hubert.reinterpretcast wrote:
> aaron.ballman wrote:
> > hubert.reinterpretcast wrote:
> > > I am not seeing any tests covering C mode.
> > > 
> > > @aaron.ballman, can you confirm that you are okay with the warning when 
> > > processing C code (and, moreover, the newly-added errors for numeric 
> > > escape sequences)?
> > > 
> > Good call on C test coverage, thank you for bringing that up!
> > 
> > I think the behavior in C is reasonable, even if it's not mandated by the 
> > standard. We're going from issuing an error in C to issuing a warning and 
> > the warning text helpfully omits the C++2c part of the diagnostic, so it 
> > seems like we're more relaxed in C than we previously were.
> > 
> > Do you have concerns about the behavior in C? (Or are you saying you'd 
> > prefer this to be an error in C as it was before?)
> My question was with respect to the change from the Clang 16 status quo for 
> numeric escapes introduced by the prior change and carried forward with this 
> one: https://godbolt.org/z/aneGr1Yfb
> 
> ```
> _Static_assert(1, "\x30"); // error in Clang 17
> ```
> 
Yes, this is intended, numeric escape sequences in unevaluated string literals 
are not allowed in any language modes - the motivation for C is the same as 
C++. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156596

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3270-3339
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =

In order to help improve the readability of this function, I suggest breaking 
the branches into two separate functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D153276: [clang][Interp] Reject reinterpret_cast expressions

2023-08-01 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:1761
+  S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+  << static_cast(Kind) << S.Current->getRange(OpPC);
+  return false;

Would you mind changing this cast from `uint8_t` to `unsigned`? We have an 
internal bot using a pickier mode of MSVC and it complains about ambiguous 
overloads, as the `operator<<` doesn't have anything smaller than `int` and 
`unsigned`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153276

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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-08-01 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:290
+  "encoding prefix '%0' on an unevaluated string literal has no effect"
+  "%select{| and is incompatible with c++2c}1">,
+  InGroup>;

aaron.ballman wrote:
> hubert.reinterpretcast wrote:
> > I am not seeing any tests covering C mode.
> > 
> > @aaron.ballman, can you confirm that you are okay with the warning when 
> > processing C code (and, moreover, the newly-added errors for numeric escape 
> > sequences)?
> > 
> Good call on C test coverage, thank you for bringing that up!
> 
> I think the behavior in C is reasonable, even if it's not mandated by the 
> standard. We're going from issuing an error in C to issuing a warning and the 
> warning text helpfully omits the C++2c part of the diagnostic, so it seems 
> like we're more relaxed in C than we previously were.
> 
> Do you have concerns about the behavior in C? (Or are you saying you'd prefer 
> this to be an error in C as it was before?)
My question was with respect to the change from the Clang 16 status quo for 
numeric escapes introduced by the prior change and carried forward with this 
one: https://godbolt.org/z/aneGr1Yfb

```
_Static_assert(1, "\x30"); // error in Clang 17
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156596

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


[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-08-01 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

@aaron.ballman I think what @danlark means is that when building clang against 
a libc++ which has debug assertions enabled, the clang tests he mentioned 
result in an assertion firing within libc++. i.e. the libc++ debug mode catches 
the non-strict weak ordering that it gets from the clang code. That's why he 
can't just add a test that fires the assertion. Currently, there are no bots 
that build clang against a libc++ with debug assertions enabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155809

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


[PATCH] D156643: [clang-format][NFC] Remove superfluous code in UnwrappedLineParser

2023-08-01 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGadece4e452e8: [clang-format][NFC] Remove superfluous code in 
UnwrappedLineParser (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156643

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1188,8 +1188,8 @@
 static bool tokenCanStartNewLine(const FormatToken ) {
   // Semicolon can be a null-statement, l_square can be a start of a macro or
   // a C++11 attribute, but this doesn't seem to be common.
+  assert(Tok.isNot(TT_AttributeSquare));
   return Tok.isNot(tok::semi) && Tok.isNot(tok::l_brace) &&
- Tok.isNot(TT_AttributeSquare) &&
  // Tokens that can only be used as binary operators and a part of
  // overloaded operator names.
  Tok.isNot(tok::period) && Tok.isNot(tok::periodstar) &&
@@ -3646,12 +3646,7 @@
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();
-if (FormatTok->is(TT_AttributeSquare)) {
-  parseSquare();
-  // Consume the closing TT_AttributeSquare.
-  if (FormatTok->Next && FormatTok->is(TT_AttributeSquare))
-nextToken();
-}
+assert(FormatTok->isNot(TT_AttributeSquare));
 if (FormatTok->is(tok::identifier)) {
   nextToken();
   // If there are two identifiers in a row, this is likely an elaborate


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1188,8 +1188,8 @@
 static bool tokenCanStartNewLine(const FormatToken ) {
   // Semicolon can be a null-statement, l_square can be a start of a macro or
   // a C++11 attribute, but this doesn't seem to be common.
+  assert(Tok.isNot(TT_AttributeSquare));
   return Tok.isNot(tok::semi) && Tok.isNot(tok::l_brace) &&
- Tok.isNot(TT_AttributeSquare) &&
  // Tokens that can only be used as binary operators and a part of
  // overloaded operator names.
  Tok.isNot(tok::period) && Tok.isNot(tok::periodstar) &&
@@ -3646,12 +3646,7 @@
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();
-if (FormatTok->is(TT_AttributeSquare)) {
-  parseSquare();
-  // Consume the closing TT_AttributeSquare.
-  if (FormatTok->Next && FormatTok->is(TT_AttributeSquare))
-nextToken();
-}
+assert(FormatTok->isNot(TT_AttributeSquare));
 if (FormatTok->is(tok::identifier)) {
   nextToken();
   // If there are two identifiers in a row, this is likely an elaborate
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] adece4e - [clang-format][NFC] Remove superfluous code in UnwrappedLineParser

2023-08-01 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-01T13:31:24-07:00
New Revision: adece4e452e88f47e1b2b7971286906ae5246fb8

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

LOG: [clang-format][NFC] Remove superfluous code in UnwrappedLineParser

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 32619bc56f7a3f..febe43e1ba65f4 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1188,8 +1188,8 @@ void UnwrappedLineParser::parsePPUnknown() {
 static bool tokenCanStartNewLine(const FormatToken ) {
   // Semicolon can be a null-statement, l_square can be a start of a macro or
   // a C++11 attribute, but this doesn't seem to be common.
+  assert(Tok.isNot(TT_AttributeSquare));
   return Tok.isNot(tok::semi) && Tok.isNot(tok::l_brace) &&
- Tok.isNot(TT_AttributeSquare) &&
  // Tokens that can only be used as binary operators and a part of
  // overloaded operator names.
  Tok.isNot(tok::period) && Tok.isNot(tok::periodstar) &&
@@ -3646,12 +3646,7 @@ bool UnwrappedLineParser::parseEnum() {
 // We can have macros or attributes in between 'enum' and the enum name.
 if (FormatTok->is(tok::l_paren))
   parseParens();
-if (FormatTok->is(TT_AttributeSquare)) {
-  parseSquare();
-  // Consume the closing TT_AttributeSquare.
-  if (FormatTok->Next && FormatTok->is(TT_AttributeSquare))
-nextToken();
-}
+assert(FormatTok->isNot(TT_AttributeSquare));
 if (FormatTok->is(tok::identifier)) {
   nextToken();
   // If there are two identifiers in a row, this is likely an elaborate



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


[PATCH] D156788: [clang][dataflow] Rename `AggregateStorageLocation` to `RecordStorageLocation` and `StructValue` to `RecordValue`.

2023-08-01 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ecdbe3855a8: [clang][dataflow] Rename 
`AggregateStorageLocation` to `RecordStorageLocation`… (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D156788?vs=546021=546201#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156788

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/RecordOps.h
  clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/RecordOps.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  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
@@ -415,7 +415,7 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S,
   getASTContext( {
-  cast(Env.getValue(*E))
+  cast(Env.getValue(*E))
   ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(
@@ -423,9 +423,9 @@
  .bind("call"),
  *S, getASTContext( {
   auto  =
-  *cast(getImplicitObjectLocation(*E, Env));
+  *cast(getImplicitObjectLocation(*E, Env));
 
-  refreshStructValue(ObjectLoc, Env)
+  refreshRecordValue(ObjectLoc, Env)
   .setProperty("is_set", Env.getBoolLiteralValue(true));
 }
   }
@@ -572,7 +572,7 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  cast(Env.getValue(*E))
+  cast(Env.getValue(*E))
   ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
@@ -580,7 +580,7 @@
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  refreshStructValue(*Object, Env)
+  refreshRecordValue(*Object, Env)
   .setProperty("has_value", Env.getBoolLiteralValue(true));
 }
   }
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -164,10 +164,10 @@
 auto *FooValue = dyn_cast_or_null(Env.getValue(*FooDecl));
 ASSERT_THAT(FooValue, NotNull());
 
-EXPECT_TRUE(isa(FooValue->getPointeeLoc()));
+EXPECT_TRUE(isa(FooValue->getPointeeLoc()));
 auto *FooPointeeValue = Env.getValue(FooValue->getPointeeLoc());
 ASSERT_THAT(FooPointeeValue, NotNull());
-EXPECT_TRUE(isa(FooPointeeValue));
+EXPECT_TRUE(isa(FooPointeeValue));
   });
 }
 
@@ -215,9 +215,9 @@
 ASSERT_THAT(UnmodeledDecl, NotNull());
 
 const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+cast(Env.getStorageLocation(*FooDecl));
 const auto *UnmodeledLoc = FooLoc->getChild(*UnmodeledDecl);
-ASSERT_TRUE(isa(UnmodeledLoc));
+ASSERT_TRUE(isa(UnmodeledLoc));
 EXPECT_THAT(Env.getValue(*UnmodeledLoc), IsNull());
 
 const ValueDecl *ZabDecl = findValueDecl(ASTCtx, "Zab");
@@ -262,7 +262,7 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+cast(Env.getStorageLocation(*FooDecl));
 EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }
@@ -305,7 +305,7 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
+cast(Env.getStorageLocation(*FooDecl));
 EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }

[clang] 9ecdbe3 - [clang][dataflow] Rename `AggregateStorageLocation` to `RecordStorageLocation` and `StructValue` to `RecordValue`.

2023-08-01 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-08-01T20:29:40Z
New Revision: 9ecdbe3855a8048989a507ff8d470aee4d407589

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

LOG: [clang][dataflow] Rename `AggregateStorageLocation` to 
`RecordStorageLocation` and `StructValue` to `RecordValue`.

- Both of these constructs are used to represent structs, classes, and unions;
  Clang uses the collective term "record" for these.

- The term "aggregate" in `AggregateStorageLocation` implies that, at some
  point, the intention may have been to use it also for arrays, but it don't
  think it's possible to use it for arrays. Records and arrays are very
  different and therefore need to be modeled differently. Records have a fixed
  set of named fields, which can have different type; arrays have a variable
  number of elements, but they all have the same type.

- Futhermore, "aggregate" has a very specific meaning in C++
  (https://en.cppreference.com/w/cpp/language/aggregate_initialization).
  Aggregates of class type may not have any user-declared or inherited
  constructors, no private or protected non-static data members, no virtual
  member functions, and so on, but we use `AggregateStorageLocations` to model 
all objects of class type.

In addition, for consistency, we also rename the following:

- `getAggregateLoc()` (in `RecordValue`, formerly known as `StructValue`) to
  simply `getLoc()`.

- `refreshStructValue()` to `refreshRecordValue()`

We keep the old names around as deprecated synonyms to enable clients to be 
migrated to the new names.

Reviewed By: ymandel, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Analysis/FlowSensitive/RecordOps.h
clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/lib/Analysis/FlowSensitive/RecordOps.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 7ac2ff3102adcd..f812c01d42040b 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -76,7 +76,7 @@ class Environment {
 virtual ComparisonResult compare(QualType Type, const Value ,
  const Environment , const Value 
,
  const Environment ) {
-  // FIXME: Consider adding QualType to StructValue and removing the Type
+  // FIXME: Consider adding QualType to RecordValue and removing the Type
   // argument here.
   return ComparisonResult::Unknown;
 }
@@ -290,7 +290,7 @@ class Environment {
   /// Returns the storage location assigned to the `this` pointee in the
   /// environment or null if the `this` pointee has no assigned storage 
location
   /// in the environment.
-  AggregateStorageLocation *getThisPointeeStorageLocation() const;
+  RecordStorageLocation *getThisPointeeStorageLocation() const;
 
   /// Returns the location of the result object for a record-type prvalue.
   ///
@@ -315,7 +315,7 @@ class Environment {
   ///
   /// Requirements:
   ///  `E` must be a prvalue of record type.
-  AggregateStorageLocation (const Expr );
+  RecordStorageLocation (const Expr );
 
   /// Returns the return value of the current function. This can be null if:
   /// - The function has a void return type
@@ -375,8 +375,8 @@ class Environment {
   /// non-pointer/non-reference type.
   ///
   /// If `Type` is a class, struct, or union type, calls `setValue()` to
-  /// associate the `StructValue` with its storage location
-  /// (`StructValue::getAggregateLoc()`).
+  /// associate the `RecordValue` with its storage location
+  /// (`RecordValue::getLoc()`).
   ///
   /// If `Type` is one of the following types, this function will always return
   /// a non-null 

[PATCH] D156718: [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is enabled

2023-08-01 Thread Brittany Blue Gaston via Phabricator via cfe-commits
thetruestblue updated this revision to Diff 546199.

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

https://reviews.llvm.org/D156718

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  compiler-rt/test/asan_abi/CMakeLists.txt
  compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
  compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
  compiler-rt/test/asan_abi/lit.site.cfg.py.in


Index: compiler-rt/test/asan_abi/lit.site.cfg.py.in
===
--- compiler-rt/test/asan_abi/lit.site.cfg.py.in
+++ compiler-rt/test/asan_abi/lit.site.cfg.py.in
@@ -8,7 +8,6 @@
 config.arm_thumb = "@COMPILER_RT_ARM_THUMB@"
 config.apple_platform = "@ASAN_ABI_TEST_APPLE_PLATFORM@"
 config.apple_platform_min_deployment_target_flag = 
"@ASAN_ABI_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
-config.asan_abi_dynamic = @ASAN_ABI_TEST_DYNAMIC@
 config.target_arch = "@ASAN_ABI_TEST_TARGET_ARCH@"
 
 # Load common config for all compiler-rt lit tests.
Index: compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
===
--- compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
+++ compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_asan_abi  -O2 -c -fsanitize-stable-abi -fsanitize=address -O0 
%s -o %t.o
 // RUN: %clangxx -c %p/../../../lib/asan_abi/asan_abi.cpp -o asan_abi.o
-// RUN: %clangxx -o %t %t.o %libasan_abi asan_abi.o && %run %t 2>&1
+// RUN: %clangxx -o %t %t.o -fsanitize-stable-abi -fsanitize=address 
asan_abi.o && %run %t 2>&1
 
 int main() { return 0; }
Index: compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
===
--- compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
+++ compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_asan_abi -O0 -c -fsanitize-stable-abi -fsanitize=address %s -o 
%t.o
 // RUN: %clangxx -c %p/../../../../lib/asan_abi/asan_abi.cpp -o asan_abi.o
-// RUN: %clangxx -dead_strip -o %t %t.o %libasan_abi asan_abi.o && %run %t 2>&1
+// RUN: %clangxx -dead_strip -o %t %t.o -fsanitize-stable-abi 
-fsanitize=address asan_abi.o && %run %t 2>&1
 // RUN: %clangxx -x c++-header -o - -E 
%p/../../../../lib/asan/asan_interface.inc \
 // RUN: | sed "s/INTERFACE_FUNCTION/\nINTERFACE_FUNCTION/g" > 
%t.asan_interface.inc
 // RUN: llvm-nm -g %libasan_abi   \
@@ -22,6 +22,9 @@
 // RUN: sort %t.exports | uniq > %t.exports-sorted
 // RUN: diff %t.imports-sorted %t.exports-sorted
 
+// Ensure that there is no dynamic dylib linked.
+// RUN: otool -L %t | (! grep -q "dynamic.dylib")
+
 // UNSUPPORTED: ios
 
 int main() { return 0; }
Index: compiler-rt/test/asan_abi/CMakeLists.txt
===
--- compiler-rt/test/asan_abi/CMakeLists.txt
+++ compiler-rt/test/asan_abi/CMakeLists.txt
@@ -13,7 +13,6 @@
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND ASAN_ABI_TEST_DEPS asan_abi)
 endif()
-set(ASAN_ABI_DYNAMIC_TEST_DEPS ${ASAN_ABI_TEST_DEPS})
 
 set(ASAN_ABI_TEST_ARCH ${ASAN_ABI_SUPPORTED_ARCH})
 if(APPLE)
@@ -27,7 +26,6 @@
   string(TOLOWER "-${arch}-${OS_NAME}" ASAN_ABI_TEST_CONFIG_SUFFIX)
   get_bits_for_arch(${arch} ASAN_ABI_TEST_BITS)
   get_test_cc_for_arch(${arch} ASAN_ABI_TEST_TARGET_CC 
ASAN_ABI_TEST_TARGET_CFLAGS)
-  set(ASAN_ABI_TEST_DYNAMIC True)
 
   string(TOUPPER ${arch} ARCH_UPPER_CASE)
   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1484,9 +1484,13 @@
 
   if (Sanitize.linkRuntimes()) {
 if (Sanitize.needsAsanRt()) {
-  assert(Sanitize.needsSharedRt() &&
- "Static sanitizer runtimes not supported");
-  AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+  if (Sanitize.needsStableAbi()) {
+AddLinkSanitizerLibArgs(Args, CmdArgs, "asan_abi", /*shared=*/false);
+  } else {
+assert(Sanitize.needsSharedRt() &&
+   "Static sanitizer runtimes not supported");
+AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+  }
 }
 if (Sanitize.needsLsanRt())
   AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
Index: clang/include/clang/Driver/SanitizerArgs.h
===
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -76,6 +76,7 @@
 bool DiagnoseErrors = true);
 
   bool needsSharedRt() const { return SharedRuntime; }
+  bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
   bool needsAsanRt() const { return 

[clang] 63c648f - [Driver][test] Add --rocm-path or -nogpuinc/-nogpulib to some AMDGPU tests

2023-08-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-01T13:16:01-07:00
New Revision: 63c648f46dff8d21ade2b77515579b29421b5b69

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

LOG: [Driver][test] Add --rocm-path or -nogpuinc/-nogpulib to some AMDGPU tests

An upcoming change D156363 will change -### to exit with code 1
if hasErrorOccurred. Some AMDGPU tests would exit with code 1.

Added: 


Modified: 
clang/test/Driver/cl-denorms-are-zero.cl
clang/test/Driver/fast-math.c
clang/test/Driver/frame-pointer-elim.cl
clang/test/Driver/hip-code-object-version.hip
clang/test/Driver/opencl.cl
clang/test/Driver/split-debug.c

Removed: 




diff  --git a/clang/test/Driver/cl-denorms-are-zero.cl 
b/clang/test/Driver/cl-denorms-are-zero.cl
index 6ca90edc1730d6..85c268436bea3e 100644
--- a/clang/test/Driver/cl-denorms-are-zero.cl
+++ b/clang/test/Driver/cl-denorms-are-zero.cl
@@ -1,14 +1,14 @@
 // Slow FMAF and slow f32 denormals
 // RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=pitcairn %s 2>&1 
| FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
-// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa -c 
-mcpu=pitcairn %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa 
-nogpulib -c -mcpu=pitcairn %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // Fast FMAF, but slow f32 denormals
 // RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=tahiti %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
-// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa -c 
-mcpu=tahiti %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa 
-nogpulib -c -mcpu=tahiti %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // Fast F32 denormals, but slow FMAF
 // RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=fiji %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
-// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa -c 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -cl-denorms-are-zero -o - --target=amdgcn--amdhsa 
-nogpulib -c -mcpu=fiji %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH 
%s
 
 // Fast F32 denormals and fast FMAF
 // RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=gfx900 %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-DENORM %s

diff  --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c
index f72c977282e1ac..34b9899e9fc185 100644
--- a/clang/test/Driver/fast-math.c
+++ b/clang/test/Driver/fast-math.c
@@ -130,7 +130,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 // RUN: %clang -### -target x86_64-linux-musl -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
-// RUN: %clang -### --target=amdgcn-amd-amdhsa -c %s 2>&1 \
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -nogpuinc -nogpulib -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 // RUN: %clang -### -target amdgcn-amd-amdpal -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s

diff  --git a/clang/test/Driver/frame-pointer-elim.cl 
b/clang/test/Driver/frame-pointer-elim.cl
index 76f6607a1f1758..d3cdd1518c37d4 100644
--- a/clang/test/Driver/frame-pointer-elim.cl
+++ b/clang/test/Driver/frame-pointer-elim.cl
@@ -1,8 +1,8 @@
-// RUN: %clang --target=amdgcn-amd-amdhsa -### -S -O3 %s 2>&1 | FileCheck 
-check-prefix=CHECKNONE %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -### -S -O3 -fno-omit-frame-pointer 
%s 2>&1 | FileCheck -check-prefix=CHECKALL %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -### -S %s 2>&1 | FileCheck 
-check-prefix=CHECKALL %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -### -S -O0 %s 2>&1 | FileCheck 
-check-prefix=CHECKALL %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -### -S -cl-opt-disable %s 2>&1 | 
FileCheck -check-prefix=CHECKALL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -### -nogpuinc -nogpulib -S -O3 %s 
2>&1 | FileCheck -check-prefix=CHECKNONE %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -### -nogpuinc -nogpulib -S -O3 
-fno-omit-frame-pointer %s 2>&1 | FileCheck -check-prefix=CHECKALL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -### -nogpuinc -nogpulib -S %s 2>&1 
| FileCheck -check-prefix=CHECKALL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -### -nogpuinc -nogpulib -S -O0 %s 
2>&1 | FileCheck -check-prefix=CHECKALL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -### -nogpuinc -nogpulib -S 
-cl-opt-disable %s 2>&1 | FileCheck -check-prefix=CHECKALL %s
 
 // CHECKNONE: -mframe-pointer=none
 // CHECKALL: -mframe-pointer=all

diff  --git 

[PATCH] D155145: [X86] Add AVX-VNNI-INT16 instructions.

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D155145#4551526 , @anna wrote:

> In D155145#4544068 , @pengfei wrote:
>
>> In D155145#4543326 , @anna wrote:
>>
>>> We see a crash bisected to this patch about using an illegal instruction. 
>>> Here's the CPUInfo for the machine:
>>>
>>>   CPU info:
>>>   current cpu id: 22
>>>   total 32(physical cores 16) (assigned logical cores 32) (assigned 
>>> physical cores 16) (assigned_sockets:2 of 2) (8 cores per cpu, 2 threads 
>>> per core) family 6 model 45 stepping 7 microcode 0x71a, cmov, cx8, fxsr, 
>>> mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, vzeroupper, avx, aes, 
>>> clmul, ht, tsc, tscinvbit, tscinv, clflush
>>>   AvgLoads: 0.30, 0.10, 0.18
>>>   CPU Model and flags from /proc/cpuinfo:
>>>   model name  : Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
>>>   flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge 
>>> mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall 
>>> nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl 
>>> xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl 
>>> vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt 
>>> tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp 
>>> tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts 
>>> md_clear flush_l1d
>>>   Online cpus: 0-31
>>>   Offline cpus:
>>>   BIOS frequency limitation: 
>>>   Frequency switch latency (ns): 2
>>>   Available cpu frequencies: 
>>>   Current governor: schedutil
>>>   Core performance/turbo boost: 
>>>
>>> I don't see `avxvnniint16` in the flags list nor avx2. So, this (relatively 
>>> new) instruction shouldn't be generated for this machine. Any ideas on why 
>>> this might be happening?
>>
>> As far as I can see from the patch, the only way to generate avxvnniint16 
>> instructions is to call its specific intrinsics explicitly. And we will 
>> check compiling options in FE before allowing to call the intrinsics. We do 
>> have an optimization to generate vnni instructions without intrinsics, but 
>> we haven't extend it to avxvnniint16 so far.
>> So I don't know what's wrong in your case, could you provide a reproducer 
>> for your problem?
>
> I've investigated what is going on. With this patch, we are now passing in 
> `+avxvnniint16` into machine attributes. With that attribute, we now generate 
> an instruction which is illegal on sandybridge machine:
>
>0x3013f2af:jmpq   0x3013f09b
>  0x3013f2b4:  mov%rax,%rdi
>  0x3013f2b7:  and$0xfff0,%rdi
>   => 0x3013f2bb:  vpbroadcastd %xmm0,%ymm2
>  0x3013f2c0:  vpbroadcastd %xmm1,%ymm3
>
> The instruction `vpbroadcastd %xmm0,%ymm2` requires `AVX2` CPU flag: 
> https://www.felixcloutier.com/x86/vpbroadcast. However, the machine has only 
> AVX flag.
>
> This is the complete mattr generated:
>
>   !3 = 
> !{!"-mattr=-prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-xsaves,-avx512fp16,-sm4,+sse4.1,-avx512ifma,+xsave,-avx512pf,+sse4.2,-tsxldtrk,-ptwrite,-widekl,-sm3,-invpcid,+64bit,-xsavec,-avx512vpopcntdq,+cmov,-avx512vp2intersect,-avx512cd,-movbe,-avxvnniint8,-avx512er,-amx-int8,-kl,-sha512,-avxvnni,-rtm,-adx,-avx2,-hreset,-movdiri,-serialize,-vpclmulqdq,-avx512vl,-uintr,-clflushopt,-raoint,-cmpccxadd,-bmi,-amx-tile,+sse,-gfni,+avxvnniint16,-amx-fp16,+xsaveopt,-rdrnd,-avx512f,-amx-bf16,-avx512bf16,-avx512vnni,+cx8,-avx512bw,+sse3,-pku,-fsgsbase,-clzero,-mwaitx,-lwp,-lzcnt,-sha,-movdir64b,-wbnoinvd,-enqcmd,-prefetchwt1,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,-bmi2,-fma,+popcnt,-avxifma,-f16c,-avx512bitalg,-rdpru,-clwb,+mmx,+sse2,-rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,-avx512dq,-sse4a"}
>
> I've confirmed if we changed to `-avxvnniint16` we do not generate 
> `vpbroadcastd`.
>
> W.r.t. how we get the machine attributes generated through our front-end:
>
>   if (!sys::getHostCPUFeatures(Features))
> return std::move(mattr);
> 
>   // Fill mattr with default values.
>   mattr.reserve(Features.getNumItems());
>   for (auto  : Features) {
> std::string attr(I.first());
> mattr.emplace_back(std::string(I.second ? "+" : "-") + attr);
>   }
>
> So, the problem is in getHostCPUFeatures, possibly this line from the patch : 
> `Features["avxvnniint16"] = HasLeaf7Subleaf1 && ((EDX >> 10) & 1) && 
> HasAVXSave;`.

Does this patch help

  diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
  index 1141df09307c..11a6879fb76a 100644
  --- a/llvm/lib/TargetParser/Host.cpp
  +++ b/llvm/lib/TargetParser/Host.cpp
  @@ -1769,7 +1769,7 @@ bool sys::getHostCPUFeatures(StringMap ) 
{
 Features["amx-tile"]   = HasLeaf7 && ((EDX >> 24) & 1) && HasAMXSave;
 Features["amx-int8"]   = 

[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-08-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

(I snipped off earlier context because it was starting to get hard to read.)

In D155809#4550727 , @danlark wrote:

> Okay, but I still don't understand how I can satisfy the following conditions 
> at the same time
>
> - Enable libc++ debug mode without failing existing tests like 
> llvm/llvm-project/clang/test/CodeGen:available-externally-hidden.cpp.test and 
> llvm/llvm-project/clang/test/CodeGenCXX:cxx2a-three-way-comparison.cpp.test 
> (yes, these are the tests that reach the assertion I am talking about). They 
> already exist. You can reproduce by building and running llvm-lit with libc++ 
> at head in debug mode.

I'm ignorant of how things are tested within libc++ which may be contributing 
to the confusion here. 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
 does not include any header files, so I don't understand what libc++ has to do 
with the test. What I'm asking for is to add a clang-specific test that fires 
the assertion today (copied and reduced from whatever test code you've got in 
libc++ that demonstrates the issue) and no longer fires the assertion with your 
patch so that we can land the Clang changes. That should then allow you to 
enable the existing debug tests in libc++ without hitting the assertion from 
Clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155809

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


[PATCH] D156749: [modules] Fix error about the same module being defined in different .pcm files when using VFS overlays.

2023-08-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a subscriber: benlangmuir.
jansvoboda11 added a comment.

CC @benlangmuir, since we've talked about this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156749

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


[PATCH] D156790: [clang][dataflow] Remove deprecated `Strict` accessors.

2023-08-01 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c1a519ee423: [clang][dataflow] Remove deprecated `Strict` 
accessors. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156790

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
@@ -276,11 +276,6 @@
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   void setStorageLocation(const Expr , StorageLocation );
 
-  /// Deprecated synonym for `setStorageLocation()`.
-  void setStorageLocationStrict(const Expr , StorageLocation ) {
-setStorageLocation(E, Loc);
-  }
-
   /// Returns the storage location assigned to the glvalue `E` in the
   /// environment, or null if `E` isn't assigned a storage location in the
   /// environment.
@@ -292,11 +287,6 @@
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   StorageLocation *getStorageLocation(const Expr ) const;
 
-  /// Deprecated synonym for `getStorageLocation()`.
-  StorageLocation *getStorageLocationStrict(const Expr ) const {
-return getStorageLocation(E);
-  }
-
   /// Returns the storage location assigned to the `this` pointee in the
   /// environment or null if the `this` pointee has no assigned storage 
location
   /// in the environment.
@@ -454,9 +444,6 @@
   ///  `StructValue` has a durable storage location.
   void setValue(const Expr , Value );
 
-  /// Deprecated synonym for `setValue()`.
-  void setValueStrict(const Expr , Value ) { setValue(E, Val); }
-
   /// Returns the value assigned to `Loc` in the environment or null if `Loc`
   /// isn't assigned a value in the environment.
   Value *getValue(const StorageLocation ) const;


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -276,11 +276,6 @@
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   void setStorageLocation(const Expr , StorageLocation );
 
-  /// Deprecated synonym for `setStorageLocation()`.
-  void setStorageLocationStrict(const Expr , StorageLocation ) {
-setStorageLocation(E, Loc);
-  }
-
   /// Returns the storage location assigned to the glvalue `E` in the
   /// environment, or null if `E` isn't assigned a storage location in the
   /// environment.
@@ -292,11 +287,6 @@
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   StorageLocation *getStorageLocation(const Expr ) const;
 
-  /// Deprecated synonym for `getStorageLocation()`.
-  StorageLocation *getStorageLocationStrict(const Expr ) const {
-return getStorageLocation(E);
-  }
-
   /// Returns the storage location assigned to the `this` pointee in the
   /// environment or null if the `this` pointee has no assigned storage location
   /// in the environment.
@@ -454,9 +444,6 @@
   ///  `StructValue` has a durable storage location.
   void setValue(const Expr , Value );
 
-  /// Deprecated synonym for `setValue()`.
-  void setValueStrict(const Expr , Value ) { setValue(E, Val); }
-
   /// Returns the value assigned to `Loc` in the environment or null if `Loc`
   /// isn't assigned a value in the environment.
   Value *getValue(const StorageLocation ) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156749: [modules] Fix error about the same module being defined in different .pcm files when using VFS overlays.

2023-08-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

> And it is build system's responsibility to provide `-ivfsoverlay` options 
> that don't cause observable differences.

I wasn't aware of that. Do we document this anywhere? It surprises me that we'd 
impose such restriction on the build system. This seems fairly easy to 
accidentally violate and end up in the same situation - Clang instances with 
different VFS overlays, identical context hashes and different canonical module 
map paths for the same module.

What are the performance implications of making VFS overlays part of the 
context hash?

Alternatively, we could keep VFS overlays out of the context hash but create 
`` from the on-disk real path of the defining module map and make the 
whole PCM VFS-agnostic. Then it'd be correct to import that PCM regardless of 
the specific VFS overlay setup, as long as all VFS queries of the importer 
resolve the same way they resolved within the instance that built the PCM. 
Maybe we can force the importer to recompile the PCM if that's not the case, 
similar to what we do for diagnostic options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156749

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


[clang] 8c1a519 - [clang][dataflow] Remove deprecated `Strict` accessors.

2023-08-01 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-08-01T20:07:00Z
New Revision: 8c1a519ee423f4097092095a44ba850bf0dd498d

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

LOG: [clang][dataflow] Remove deprecated `Strict` accessors.

Reviewed By: ymandel, xazax.hun

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

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 0e5cfad263c797..7ac2ff3102adcd 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -276,11 +276,6 @@ class Environment {
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   void setStorageLocation(const Expr , StorageLocation );
 
-  /// Deprecated synonym for `setStorageLocation()`.
-  void setStorageLocationStrict(const Expr , StorageLocation ) {
-setStorageLocation(E, Loc);
-  }
-
   /// Returns the storage location assigned to the glvalue `E` in the
   /// environment, or null if `E` isn't assigned a storage location in the
   /// environment.
@@ -292,11 +287,6 @@ class Environment {
   ///  `E` must be a glvalue or a `BuiltinType::BuiltinFn`
   StorageLocation *getStorageLocation(const Expr ) const;
 
-  /// Deprecated synonym for `getStorageLocation()`.
-  StorageLocation *getStorageLocationStrict(const Expr ) const {
-return getStorageLocation(E);
-  }
-
   /// Returns the storage location assigned to the `this` pointee in the
   /// environment or null if the `this` pointee has no assigned storage 
location
   /// in the environment.
@@ -454,9 +444,6 @@ class Environment {
   ///  `StructValue` has a durable storage location.
   void setValue(const Expr , Value );
 
-  /// Deprecated synonym for `setValue()`.
-  void setValueStrict(const Expr , Value ) { setValue(E, Val); }
-
   /// Returns the value assigned to `Loc` in the environment or null if `Loc`
   /// isn't assigned a value in the environment.
   Value *getValue(const StorageLocation ) const;



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


[clang] 8a9c51c - [Driver][test] Remove hipBundled before %clang

2023-08-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-01T12:55:00-07:00
New Revision: 8a9c51cdbb6d68a5526e4636090ee52ee3cf38f7

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

LOG: [Driver][test] Remove hipBundled before %clang

Otherwise, if `%clang` fails, rm -rf hipBundled will not run and the
linkering hipBundled will cause the next test invocation to fail.

Added: 


Modified: 
clang/test/Driver/hip-link-bundle-archive.hip

Removed: 




diff  --git a/clang/test/Driver/hip-link-bundle-archive.hip 
b/clang/test/Driver/hip-link-bundle-archive.hip
index 945b45afa20dbc..6dc33b0d671763 100644
--- a/clang/test/Driver/hip-link-bundle-archive.hip
+++ b/clang/test/Driver/hip-link-bundle-archive.hip
@@ -5,15 +5,13 @@
 // value of the '-l' option, it should not interfere with
 // the discovery and unbundling of the archive.
 
-// RUN: rm -rf %t && mkdir %t
+// RUN: rm -rf %t hipBundled && mkdir %t hipBundled
 // RUN: touch %t/dummy.bc
-// RUN: mkdir hipBundled
 // RUN: llvm-ar cr %t/libhipBundled.a %t/dummy.bc
 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
 // RUN:   --target=x86_64-unknown-linux-gnu \
 // RUN:   -nogpulib %s -fgpu-rdc -L%t -lhipBundled \
 // RUN:   2>&1 | FileCheck -check-prefixes=GNU,GNU1,GNU-L %s
-// RUN: rm -rf hipBundled
 
 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
 // RUN:   --target=x86_64-unknown-linux-gnu \



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


[clang] b314d05 - [Driver][test] Remove invalid -fuse-ld=wasm-ld

2023-08-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-01T12:52:49-07:00
New Revision: b314d057e717b12d645b1a7542b2918e8c176a37

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

LOG: [Driver][test] Remove invalid -fuse-ld=wasm-ld

Added: 


Modified: 
clang/test/Driver/wasm-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index 909d27f0f2d9c9..78160e3da151a1 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -76,7 +76,7 @@
 
 // '-pthread' sets +atomics, +bulk-memory, +mutable-globals, +sign-ext, and 
--shared-memory
 // RUN: %clang -### --target=wasm32-unknown-unknown \
-// RUN:--sysroot=/foo %s -fuse-ld=wasm-ld -pthread 2>&1 \
+// RUN:--sysroot=/foo %s -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" 
"+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" 
"+sign-ext"
 // PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"



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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D156816#4551500 , @jdoerfert wrote:

> Macros seems to be good enough. If we really need clang attributes, we need 
> new docs, and naming convention etc.

Yeah an alternative would be a new set of attributes, then we make the old ones 
OpenCL language specific. One problem is that this will probably be copy 
pasting everything a second time with no difference, but it might be fine. This 
is just the easy version. Also `addrspace_` probably isn't the best name since 
there's other non-GPU targets that use address spaces. I just think that this 
GPU generic stuff should be moved out of OpenCL in whatever way is most 
convenient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1807
+
+  // Do not emit checks for disabled sanitizers to support recover
+  SmallVector, 2> Checks;

recover -> recovery?

Period at the end of the comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156821

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


[PATCH] D156192: [-Wunsafe-buffer-usage] Stop generating incorrect fix-its for variable declarations with unsupported specifiers

2023-08-01 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added a comment.

> Note that your patch doesn't actually address //type// attributes, only 
> //declaration// attributes.

It does not address type attribute.  We can address it in a follow-up patch.

> So it's likely that we have to give up on unsupported type attributes very 
> early, even before the fixit stage. Maybe on `hasPointerType()` stage; in 
> such cases we aren't even sure that's a pointer, what if it's like an `int 
> *__attribute__((vector_size(8)))`? (This actually can't happen; you can't 
> have vectors of pointers. But something similar totally could.)

This is a good idea!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156192

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


[PATCH] D156596: [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-08-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:290
+  "encoding prefix '%0' on an unevaluated string literal has no effect"
+  "%select{| and is incompatible with c++2c}1">,
+  InGroup>;

hubert.reinterpretcast wrote:
> I am not seeing any tests covering C mode.
> 
> @aaron.ballman, can you confirm that you are okay with the warning when 
> processing C code (and, moreover, the newly-added errors for numeric escape 
> sequences)?
> 
Good call on C test coverage, thank you for bringing that up!

I think the behavior in C is reasonable, even if it's not mandated by the 
standard. We're going from issuing an error in C to issuing a warning and the 
warning text helpfully omits the C++2c part of the diagnostic, so it seems like 
we're more relaxed in C than we previously were.

Do you have concerns about the behavior in C? (Or are you saying you'd prefer 
this to be an error in C as it was before?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156596

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


[PATCH] D155145: [X86] Add AVX-VNNI-INT16 instructions.

2023-08-01 Thread Anna Thomas via Phabricator via cfe-commits
anna added a comment.

In D155145#4544068 , @pengfei wrote:

> In D155145#4543326 , @anna wrote:
>
>> We see a crash bisected to this patch about using an illegal instruction. 
>> Here's the CPUInfo for the machine:
>>
>>   CPU info:
>>   current cpu id: 22
>>   total 32(physical cores 16) (assigned logical cores 32) (assigned physical 
>> cores 16) (assigned_sockets:2 of 2) (8 cores per cpu, 2 threads per core) 
>> family 6 model 45 stepping 7 microcode 0x71a, cmov, cx8, fxsr, mmx, sse, 
>> sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, vzeroupper, avx, aes, clmul, ht, 
>> tsc, tscinvbit, tscinv, clflush
>>   AvgLoads: 0.30, 0.10, 0.18
>>   CPU Model and flags from /proc/cpuinfo:
>>   model name  : Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
>>   flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca 
>> cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx 
>> pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology 
>> nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est 
>> tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt 
>> tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp 
>> tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts 
>> md_clear flush_l1d
>>   Online cpus: 0-31
>>   Offline cpus:
>>   BIOS frequency limitation: 
>>   Frequency switch latency (ns): 2
>>   Available cpu frequencies: 
>>   Current governor: schedutil
>>   Core performance/turbo boost: 
>>
>> I don't see `avxvnniint16` in the flags list nor avx2. So, this (relatively 
>> new) instruction shouldn't be generated for this machine. Any ideas on why 
>> this might be happening?
>
> As far as I can see from the patch, the only way to generate avxvnniint16 
> instructions is to call its specific intrinsics explicitly. And we will check 
> compiling options in FE before allowing to call the intrinsics. We do have an 
> optimization to generate vnni instructions without intrinsics, but we haven't 
> extend it to avxvnniint16 so far.
> So I don't know what's wrong in your case, could you provide a reproducer for 
> your problem?

I've investigated what is going on. With this patch, we are now passing in 
`+avxvnniint16` into machine attributes. With that attribute, we now generate 
an instruction which is illegal on sandybridge machine:

   0x3013f2af:  jmpq   0x3013f09b
 0x3013f2b4:mov%rax,%rdi
 0x3013f2b7:and$0xfff0,%rdi
  => 0x3013f2bb:vpbroadcastd %xmm0,%ymm2
 0x3013f2c0:vpbroadcastd %xmm1,%ymm3

The instruction `vpbroadcastd %xmm0,%ymm2` requires `AVX2` CPU flag: 
https://www.felixcloutier.com/x86/vpbroadcast. However, the machine has only 
AVX flag.

This is the complete mattr generated:

  !3 = 
!{!"-mattr=-prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-xsaves,-avx512fp16,-sm4,+sse4.1,-avx512ifma,+xsave,-avx512pf,+sse4.2,-tsxldtrk,-ptwrite,-widekl,-sm3,-invpcid,+64bit,-xsavec,-avx512vpopcntdq,+cmov,-avx512vp2intersect,-avx512cd,-movbe,-avxvnniint8,-avx512er,-amx-int8,-kl,-sha512,-avxvnni,-rtm,-adx,-avx2,-hreset,-movdiri,-serialize,-vpclmulqdq,-avx512vl,-uintr,-clflushopt,-raoint,-cmpccxadd,-bmi,-amx-tile,+sse,-gfni,+avxvnniint16,-amx-fp16,+xsaveopt,-rdrnd,-avx512f,-amx-bf16,-avx512bf16,-avx512vnni,+cx8,-avx512bw,+sse3,-pku,-fsgsbase,-clzero,-mwaitx,-lwp,-lzcnt,-sha,-movdir64b,-wbnoinvd,-enqcmd,-prefetchwt1,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,-bmi2,-fma,+popcnt,-avxifma,-f16c,-avx512bitalg,-rdpru,-clwb,+mmx,+sse2,-rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,-avx512dq,-sse4a"}

I've confirmed if we changed to `-avxvnniint16` we do not generate 
`vpbroadcastd`.

W.r.t. how we get the machine attributes generated through our front-end:

  if (!sys::getHostCPUFeatures(Features))
return std::move(mattr);

  // Fill mattr with default values.
  mattr.reserve(Features.getNumItems());
  for (auto  : Features) {
std::string attr(I.first());
mattr.emplace_back(std::string(I.second ? "+" : "-") + attr);
  }

So, the problem is in getHostCPUFeatures, possibly this line from the patch : 
`Features["avxvnniint16"] = HasLeaf7Subleaf1 && ((EDX >> 10) & 1) && 
HasAVXSave;`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155145

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


[PATCH] D156781: Use the canonical path for the include header search.

2023-08-01 Thread Jonas via Phabricator via cfe-commits
felberj added a comment.

Thanks a lot for your notes! Unfortunately I noticed that while the test that I 
created passed, my actual issue [0] still persists and I sent out the change 
too early. It seems you are right and the symlink handling is in fact more 
nuanced.

Enjoy your vacation! I will go on vacation soon as well, so no hurries with the 
review.

[0] https://github.com/hedronvision/bazel-compile-commands-extractor/issues/136


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156781

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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D156816#4551417 , @jhuber6 wrote:

> In D156816#4551409 , @Anastasia 
> wrote:
>
>> Why not to just use target address space and define it to some macro with 
>> desirable spelling?
>>
>> I don't think renaming OpenCL address space to something else makes sense. 
>> It might make more sense to just introduced different model of address 
>> spaces completely. But if you use OpenCL ones then it makes sense to have 
>> adequate naming so its documentation and etc can be located.
>
> My issue is that these address spaces aren't really OpenCL specific, they 
> describe a larger concept than the OpenCL language itself and we'd like to 
> use that without needing to invoke the `opencl` name, since it's unrelated in 
> this context.



1. AS is not language or backend specific. We have mostly converged and we want 
to have some neutral spelling for the common ones.
2. This is not helping. Now the OpenCL attributes have a second spelling, but 
they are still OpenCL attributes (for the user due to the docs and for the 
developer in clang). We also are tied to OpenCL semantic of future versions.

> Why not to just use target address space and define it to some macro with 
> desirable spelling?

Macros seems to be good enough. If we really need clang attributes, we need new 
docs, and naming convention etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[clang] 59a57ca - [clang][deps] NFC: Convert test to split-file

2023-08-01 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-01T12:27:14-07:00
New Revision: 59a57ca6d3e801a90dcef7b4216f6baca6ca99b8

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

LOG: [clang][deps] NFC: Convert test to split-file

Added: 


Modified: 
clang/test/ClangScanDeps/has_include_if_elif.cpp

Removed: 
clang/test/ClangScanDeps/Inputs/has_include_if_elif.json



diff  --git a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json 
b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
deleted file mode 100644
index 8fcc7ea34a9bce..00
--- a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
+++ /dev/null
@@ -1,12 +0,0 @@
-[
-{
-  "directory": "DIR",
-  "command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
-  "file": "DIR/has_include_if_elif2.cpp"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
-  "file": "DIR/has_include_if_elif2_clangcl.cpp"
-}
-]

diff  --git a/clang/test/ClangScanDeps/has_include_if_elif.cpp 
b/clang/test/ClangScanDeps/has_include_if_elif.cpp
index 5813bf08482ece..b8b5bb8b6bf09f 100644
--- a/clang/test/ClangScanDeps/has_include_if_elif.cpp
+++ b/clang/test/ClangScanDeps/has_include_if_elif.cpp
@@ -1,21 +1,18 @@
-// RUN: rm -rf %t.dir
-// RUN: rm -rf %t.cdb
-// RUN: mkdir -p %t.dir
-// RUN: cp %s %t.dir/has_include_if_elif2.cpp
-// RUN: cp %s %t.dir/has_include_if_elif2_clangcl.cpp
-// RUN: mkdir %t.dir/Inputs
-// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
-// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header2.h
-// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header3.h
-// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header4.h
-// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/has_include_if_elif.json > %t.cdb
-//
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode 
preprocess-dependency-directives | \
-// RUN:   FileCheck %s
-// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess | \
-// RUN:   FileCheck %s
+// RUN: rm -rf %t
+// RUN: split-file %s %t
 
-#if __has_include("header.h")
+//--- cdb.json.in
+[{
+  "directory": "DIR",
+  "command": "clang -c DIR/tu.c -o DIR/tu.o -IDIR/include",
+  "file": "DIR/tu.c"
+}]
+//--- include/header1.h
+//--- include/header2.h
+//--- include/header3.h
+//--- include/header4.h
+//--- tu.c
+#if __has_include("header1.h")
 #endif
 
 #if 0
@@ -27,19 +24,16 @@
 #endif
 
 #define H4 __has_include("header4.h")
-
 #if 0
 #elif H4
 #endif
 
-// CHECK: has_include_if_elif2.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
-// CHECK-NEXT: Inputs{{/|\\}}header2.h
-// CHECK-NEXT: Inputs{{/|\\}}header3.h
-// CHECK-NEXT: Inputs{{/|\\}}header4.h
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -mode 
preprocess-dependency-directives | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -mode preprocess | 
FileCheck %s
 
-// CHECK: has_include_if_elif2_clangcl.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
-// CHECK-NEXT: Inputs{{/|\\}}header2.h
-// CHECK-NEXT: Inputs{{/|\\}}header3.h
-// CHECK-NEXT: Inputs{{/|\\}}header4.h
+// CHECK: tu.c
+// CHECK-NEXT: header1.h
+// CHECK-NEXT: header2.h
+// CHECK-NEXT: header3.h
+// CHECK-NEXT: header4.h



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


[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-01 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 546182.
cpsughrue added a comment.

Update llvm-lit test to use split-file


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

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-cc1.cpp

Index: clang/test/ClangScanDeps/modules-cc1.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-cc1.cpp
@@ -0,0 +1,29 @@
+// Check that clang-scan-deps works with cc1 command lines
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+
+//--- modules_cc1.cpp
+#include "header.h"
+
+//--- header.h
+
+//--- module.modulemap
+module header1 { header "header.h" }
+
+//--- cdb.json.template
+[{
+  "file": "DIR/modules_cc1.cpp",
+  "directory": "DIR",
+  "command": "clang -cc1 DIR/modules_cc1.cpp -fimplicit-module-maps -o modules_cc1.o"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 -mode preprocess-dependency-directives | \
+// RUN:   FileCheck %s -DPREFIX=%t
+
+// CHECK: modules_cc1.o:
+// CHECK-NEXT: [[PREFIX]]/modules_cc1.cpp
+// CHECK-NEXT: [[PREFIX]]/module.modulemap
+// CHECK-NEXT: [[PREFIX]]/header.h
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+std::shared_ptr ,
+DiagnosticsEngine , DependencyConsumer ) {
+
+  // Save executable path before providing CommandLine to ToolInvocation
+  std::string Executable = CommandLine[0];
+  ToolInvocation Invocation(std::move(CommandLine), , ,
+PCHContainerOps);
+  Invocation.setDiagnosticConsumer(Diags.getClient());
+  Invocation.setDiagnosticOptions(());
+  if (!Invocation.run())
+return false;
+
+  std::vector Args = Action.takeLastCC1Arguments();
+  Consumer.handleBuildCommand({std::move(Executable), std::move(Args)});
+  return true;
+}
+
 bool DependencyScanningWorker::computeDependencies(
 StringRef WorkingDirectory, const std::vector ,
 DependencyConsumer , DependencyActionController ,
@@ -454,37 +477,37 @@
   DependencyScanningAction Action(WorkingDirectory, Consumer, Controller, DepFS,
   Format, OptimizeArgs, EagerLoadModules,
   DisableFree, ModuleName);
-  bool Success = forEachDriverJob(
-  FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
-if (StringRef(Cmd.getCreator().getName()) != "clang") {
-  // Non-clang command. Just pass through to the dependency
-  // consumer.
-  Consumer.handleBuildCommand(
-  {Cmd.getExecutable(),
-   {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
-  return true;
-}
-
-std::vector Argv;
-Argv.push_back(Cmd.getExecutable());
-Argv.insert(Argv.end(), Cmd.getArguments().begin(),
-Cmd.getArguments().end());
-
-// Create an invocation that uses the underlying file
-// system to ensure that any file system requests that
-// are made by the driver do not go through the
-// dependency scanning filesystem.
-ToolInvocation Invocation(std::move(Argv), , &*FileMgr,
-  PCHContainerOps);
-Invocation.setDiagnosticConsumer(Diags->getClient());
-Invocation.setDiagnosticOptions(>getDiagnosticOptions());
-if (!Invocation.run())
-  return false;
-
-std::vector Args = Action.takeLastCC1Arguments();
-Consumer.handleBuildCommand({Cmd.getExecutable(), std::move(Args)});
-return true;
-  });
+
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,
+ PCHContainerOps, *Diags, Consumer);
+  } else {
+Success = forEachDriverJob(
+FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
+  if (StringRef(Cmd.getCreator().getName()) != "clang") {
+// Non-clang command. Just pass through to the dependency
+// consumer.
+Consumer.handleBuildCommand(
+{Cmd.getExecutable(),
+ {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
+return true;
+ 

[PATCH] D156201: [ASTImporter] Fix corrupted RecordLayout introduced by circular referenced fields

2023-08-01 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!

In D156201#4551332 , @danix800 wrote:

> In D156201#4551270 , @steakhal 
> wrote:
>
>> Have you considered back porting this to clang-17?
>
> How to backport? I'm not familiar with this. Is it plain `cherry-pick` to 
> specific branch?

We have some documented instructions here: 
https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches -- 
I don't oppose adding this to the release branch (it seems simple and 
straightforward enough), but if it's not fixing a regression or other critical 
issue, it might make sense to leave it out of 17.x so there's less moving parts 
during the release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156201

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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D156816#4551409 , @Anastasia wrote:

> Why not to just use target address space and define it to some macro with 
> desirable spelling?
>
> I don't think renaming OpenCL address space to something else makes sense. It 
> might make more sense to just introduced different model of address spaces 
> completely. But if you use OpenCL ones then it makes sense to have adequate 
> naming so its documentation and etc can be located.

My issue is that these address spaces aren't really OpenCL specific, they 
describe a larger concept than the OpenCL language itself and we'd like to use 
that without needing to invoke the `opencl` name, since it's unrelated in this 
context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D156816#4551409 , @Anastasia wrote:

> Why not to just use target address space and define it to some macro with 
> desirable spelling?

If you mean the numbered address spaces, that's the broken thing this is 
specifically trying to disallow. We probably shouldn't even allow you to use 
those numbers. The numbered versions are not treated equivalently, and don't 
have the same enforced semantic rules. For example __constant__ disallows 
storing to it, but address_space(4) does. The lack of casting rules is also an 
issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[PATCH] D155814: Fix the linting problems which causes `clang/utils/ci/run-buildbot check-format` to return 1.

2023-08-01 Thread Amirreza Ashouri via Phabricator via cfe-commits
AMP999 added a comment.

Hi @ziqingluo-90 !
I don't have commit privileges, could you commit this for me?


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

https://reviews.llvm.org/D155814

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


[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D156816#4551357 , @jhuber6 wrote:

> In D156816#4551338 , @yaxunl wrote:
>
>>> FFI isn't the reason you'd use these, it's for generic access to the actual 
>>> backend. E.g. an `addrspace(3)` global is local memory, if it's external 
>>> it's dynamic. Having these named is better than doing it via the numerical 
>>> address space. I'd like to use these in the C++ / OpenMP codes instead of 
>>> the numeric ones but I don't like needing to use `opencl` in the name. 
>>> Similarly to how we have the OpenCL atomics that should be usable outside 
>>> of OpenCL.
>>
>> I agree these attributes are useful in other languages, but "global" and 
>> "local" may need a more generic name suitable for all offloading languages. 
>> To me, "device" can be a good alternative to "global". even "shared" seems 
>> clearer than "local".
>
> Global is common in https://llvm.org/docs/AMDGPUUsage.html#address-spaces and 
> https://llvm.org/docs/NVPTXUsage.html#address-spaces. The main problem is 
> `local` vs `shared` and `private` vs `local`. Unsure which one we should 
> prefer in this case. Generally I feel a lot of this OpenCL stuff should've 
> been named commonly at the start considering you can use most of them outside 
> of the actual OpenCL language just fine.

Why not to just use target address space and define it to some macro with 
desirable spelling?

I don't think renaming OpenCL address space to something else makes sense. It 
might make more sense to just introduced different model of address spaces 
completely. But if you use OpenCL ones then it makes sense to have adequate 
naming so its documentation and etc can be located.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

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


[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-01 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue added inline comments.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:482
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,

Bigcheese wrote:
> jansvoboda11 wrote:
> > cpsughrue wrote:
> > > Is there a good way to validate cc1 command lines?
> > I think that happens in `ToolInvocation::run()` that's called by 
> > `createAndRunToolInvocation`. Are you seeing cases where we don't emit a 
> > diagnostic for an invalid `-cc1` command line?
> Not really, you just have to parse it. Was there a particular reason you 
> wanted to validate here?
@jansvoboda11 You're right, `ToolInvocation::run()` fails if there are any 
issues when the function creates the compiler invocation - I missed that. I've 
not seen any cases where diagnostics aren't outputted.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:482
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,

cpsughrue wrote:
> Bigcheese wrote:
> > jansvoboda11 wrote:
> > > cpsughrue wrote:
> > > > Is there a good way to validate cc1 command lines?
> > > I think that happens in `ToolInvocation::run()` that's called by 
> > > `createAndRunToolInvocation`. Are you seeing cases where we don't emit a 
> > > diagnostic for an invalid `-cc1` command line?
> > Not really, you just have to parse it. Was there a particular reason you 
> > wanted to validate here?
> @jansvoboda11 You're right, `ToolInvocation::run()` fails if there are any 
> issues when the function creates the compiler invocation - I missed that. 
> I've not seen any cases where diagnostics aren't outputted.
@Bigcheese No, I just wanted to make sure some sort of validation was happening 
and missed the work being done in `ToolInvocation::run()`.



Comment at: clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json:1
+[
+{

jansvoboda11 wrote:
> I assume this was cargo-culted from 
> `clang/test/ClangScanDeps/Inputs/modules_cdb.json`. I don't think we need 
> multiple entries here and lots of the flags are unnecessary for just testing 
> out `-cc1` command lines work. I suggest having just one minimal `-cc1` 
> command line here.
That is an accurate assumption. Are you good with the following command line 
`clang -cc1 DIR/modules_cdb_input.cpp -IInputs -fimplicit-module-maps -o 
modules_cdb_input.o`?


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

https://reviews.llvm.org/D156234

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


[clang] eb8c4b1 - [clang][deps] NFC: Convert test to split-file

2023-08-01 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-08-01T11:48:25-07:00
New Revision: eb8c4b1d0f6154704af669c3f2f7514cb921

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

LOG: [clang][deps] NFC: Convert test to split-file

Added: 


Modified: 
clang/test/ClangScanDeps/error.cpp

Removed: 




diff  --git a/clang/test/ClangScanDeps/error.cpp 
b/clang/test/ClangScanDeps/error.cpp
index d94ba4c03e5088..0095a6c900c3b3 100644
--- a/clang/test/ClangScanDeps/error.cpp
+++ b/clang/test/ClangScanDeps/error.cpp
@@ -1,26 +1,35 @@
-// RUN: rm -rf %t.dir
-// RUN: rm -rf %t.cdb
-// RUN: mkdir -p %t.dir
-// RUN: cp %s %t.dir/regular_cdb_input.cpp
-// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb.json > %t.cdb
-// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb_clangcl.json > 
%t_clangcl.cdb
-//
-// RUN: not clang-scan-deps -compilation-database %t.cdb -j 1 2>%t.dir/errs
-// RUN: echo EOF >> %t.dir/errs
-// RUN: FileCheck %s --input-file %t.dir/errs
-
-// RUN: not clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 
2>%t.dir/errs_clangcl
-// RUN: echo EOF >> %t.dir/errs_clangcl
-// RUN: FileCheck %s --input-file %t.dir/errs_clangcl
+// RUN: rm -rf %t
+// RUN: split-file %s %t
 
+//--- missing_tu.json.in
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/missing_tu.c",
+  "file": "DIR/missing_tu.c"
+}]
+//--- missing_header.json.in
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/missing_header.c",
+  "file": "DIR/missing_header.c"
+}]
+//--- missing_header.c
 #include "missing.h"
 
-// CHECK: Error while scanning dependencies
-// CHECK-NEXT: error: no such file or directory:
-// CHECK-NEXT: error: no input files
-// CHECK-NEXT: error:
-// CHECK-NEXT: Error while scanning dependencies
-// CHECK-NEXT: fatal error: 'missing.h' file not found
-// CHECK-NEXT: Error while scanning dependencies
-// CHECK-NEXT: fatal error: 'missing.h' file not found
-// CHECK-NEXT: EOF
+// RUN: sed -e "s|DIR|%/t|g" %t/missing_tu.json.in > %t/missing_tu.json
+// RUN: not clang-scan-deps -compilation-database %t/missing_tu.json 
2>%t/missing_tu.errs
+// RUN: echo EOF >> %t/missing_tu.errs
+// RUN: cat %t/missing_tu.errs | sed 's:\?:/:g' | FileCheck %s 
--check-prefix=CHECK-MISSING-TU -DPREFIX=%/t
+// CHECK-MISSING-TU: Error while scanning dependencies for 
[[PREFIX]]/missing_tu.c
+// CHECK-MISSING-TU-NEXT: error: no such file or directory: 
'[[PREFIX]]/missing_tu.c'
+// CHECK-MISSING-TU-NEXT: error: no input files
+// CHECK-MISSING-TU-NEXT: error:
+// CHECK-MISSING-TU-NEXT: EOF
+
+// RUN: sed -e "s|DIR|%/t|g" %t/missing_header.json.in > %t/missing_header.json
+// RUN: not clang-scan-deps -compilation-database %t/missing_header.json 
2>%t/missing_header.errs
+// RUN: echo EOF >> %t/missing_header.errs
+// RUN: cat %t/missing_header.errs | sed 's:\?:/:g' | FileCheck %s 
--check-prefix=CHECK-MISSING-HEADER -DPREFIX=%/t
+// CHECK-MISSING-HEADER: Error while scanning dependencies for 
[[PREFIX]]/missing_header.c
+// CHECK-MISSING-HEADER-NEXT: fatal error: 'missing.h' file not found
+// CHECK-MISSING-HEADER-NEXT: EOF



___
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-08-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:291
+  /// the frontend.
+  OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown;
+

koops wrote:
> ABataev wrote:
> > I don't see where this field is stored/loaded for PCH support. You need add 
> > a support for this in Serialization.
> Since the ASTReader and ASTWriter are used by the developer of clang, it is 
> preferable to show the internal state of the compiler as is, e.g. if "#pragma 
> omp loop bind(parallel)" is changed to "#pragma omp for" then the ASTWriter 
> has to show it as "#pragma omp for". I can change it to "#pragma omp loop 
> bind(parallel)" using the MappedDirective that is stored however, that would 
> be misleading to the developer of clang.
How it is related to PCH? Try to serialize/deserialize the template and then 
try to create a new instance. There will be an issue since there is no 
serialization support, when you try to create new instance in the Rebuild... 
function (mapLoopConstruct will use OMPD_unknown as Prev value instead of 
oringal previous value, since it is not serialized/deserialized)


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] D156792: [Driver] Fix test usages of --rtlib= without --unwindlib=

2023-08-01 Thread Alex Brachet 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 rGd5ca1602f641: [Driver] Fix test usages of --rtlib= without 
--unwindlib= (authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D156792?vs=546030=546168#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156792

Files:
  clang/test/Driver/csky-toolchain.c
  clang/test/Driver/env.c
  clang/test/Driver/gcc-install-dir.cpp
  clang/test/Driver/gcc-toolchain.cpp
  clang/test/Driver/linux-cross.cpp
  clang/test/Driver/linux-ld.c
  clang/test/Driver/loongarch-toolchain.c
  clang/test/Driver/miamcu-opt.c
  clang/test/Driver/nolibc.c
  clang/test/Driver/pic.c
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c
  clang/test/OpenMP/linking.c

Index: clang/test/OpenMP/linking.c
===
--- clang/test/OpenMP/linking.c
+++ clang/test/OpenMP/linking.c
@@ -4,24 +4,24 @@
 // FIXME: Replace DEFAULT_OPENMP_LIB below with the value chosen at configure time.
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-32 %s
 // CHECK-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
 // CHECK-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-64 %s
 // CHECK-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
 // CHECK-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target i386-unknown-linux -rtlib=platform \
+// RUN: -fopenmp=libgomp -target i386-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-32 %s
 
-// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform --unwindlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s
 // SIMD-ONLY2-NOT: lgomp
 // SIMD-ONLY2-NOT: lomp
 // SIMD-ONLY2-NOT: liomp
@@ -29,27 +29,27 @@
 // CHECK-GOMP-LD-32: "-lgomp" "-lrt"
 // CHECK-GOMP-LD-32: "-lpthread" "-lc"
 
-// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform --unwindlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s
 // SIMD-ONLY2-NOT: lgomp
 // SIMD-ONLY2-NOT: lomp
 // SIMD-ONLY2-NOT: liomp
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target x86_64-unknown-linux -rtlib=platform \
+// RUN: -fopenmp=libgomp -target x86_64-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-64 %s
 // CHECK-GOMP-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-GOMP-LD-64: "-lgomp" "-lrt"
 // CHECK-GOMP-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-32 %s
 // CHECK-IOMP5-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
 // CHECK-IOMP5-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-64 %s
 // CHECK-IOMP5-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
@@ -67,7 +67,7 @@
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -fopenmp -fopenmp=libgomp -target i386-unknown-linux \
-// RUN: -rtlib=platform \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-OVERRIDE-32 %s
 // CHECK-LD-OVERRIDE-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-OVERRIDE-32: "-lgomp" "-lrt"
@@ -75,14 +75,14 @@
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // 

[clang] d5ca160 - [Driver] Fix test usages of --rtlib= without --unwindlib=

2023-08-01 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2023-08-01T18:39:40Z
New Revision: d5ca1602f64114f612ad5630f04e4aa90591c78d

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

LOG: [Driver] Fix test usages of --rtlib= without --unwindlib=

These errors surfaced after D156363. The error
"--rtlib=libgcc requires --unwindlib=libgcc" happens only when
`CLANG_DEFAULT_UNWINDLIB` has been specified at build time.

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

Added: 


Modified: 
clang/test/Driver/csky-toolchain.c
clang/test/Driver/env.c
clang/test/Driver/gcc-install-dir.cpp
clang/test/Driver/gcc-toolchain.cpp
clang/test/Driver/linux-cross.cpp
clang/test/Driver/linux-ld.c
clang/test/Driver/loongarch-toolchain.c
clang/test/Driver/miamcu-opt.c
clang/test/Driver/nolibc.c
clang/test/Driver/pic.c
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c
clang/test/OpenMP/linking.c

Removed: 




diff  --git a/clang/test/Driver/csky-toolchain.c 
b/clang/test/Driver/csky-toolchain.c
index 386317ad3e0c67..66485464652ac8 100644
--- a/clang/test/Driver/csky-toolchain.c
+++ b/clang/test/Driver/csky-toolchain.c
@@ -7,7 +7,7 @@
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
 
-// RUN: %clang -### %s -fuse-ld=ld -no-pie --target=csky-unknown-linux-gnu 
--rtlib=platform  \
+// RUN: %clang -### %s -fuse-ld=ld -no-pie --target=csky-unknown-linux-gnu 
--rtlib=platform --unwindlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_csky_linux_sdk  2>&1 | FileCheck 
-check-prefix=C-CSKY-LINUX-MULTI %s
 
 // C-CSKY-LINUX-MULTI: 
"{{.*}}/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/../../..{{/|}}..{{/|}}csky-linux-gnuabiv2/bin{{/|}}ld"
@@ -23,7 +23,7 @@
 // C-CSKY-LINUX-MULTI: 
"-L{{.*}}/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/../../..{{/|}}..{{/|}}csky-linux-gnuabiv2/libc/lib"
 // C-CSKY-LINUX-MULTI: 
"-L{{.*}}/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/../../..{{/|}}..{{/|}}csky-linux-gnuabiv2/libc/usr/lib"
 
-// RUN: %clang -### %s -fuse-ld=ld -fno-pic -no-pie 
--target=csky-unknown-linux-gnu --rtlib=platform -march=ck860v \
+// RUN: %clang -### %s -fuse-ld=ld -fno-pic -no-pie 
--target=csky-unknown-linux-gnu --rtlib=platform --unwindlib=platform 
-march=ck860v \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_csky_linux_sdk 2>&1 | FileCheck 
-check-prefix=C-CSKY-LINUX-CK860V %s
 
 // C-CSKY-LINUX-CK860V: 
"{{.*}}/Inputs/multilib_csky_linux_sdk/lib/gcc/csky-linux-gnuabiv2/6.3.0/../../..{{/|}}..{{/|}}csky-linux-gnuabiv2/bin{{/|}}ld"

diff  --git a/clang/test/Driver/env.c b/clang/test/Driver/env.c
index 0a60739db8718a..40a42dc9618576 100644
--- a/clang/test/Driver/env.c
+++ b/clang/test/Driver/env.c
@@ -7,13 +7,13 @@
 // RUN: env -i LC_ALL=C LD_LIBRARY_PATH="$LD_LIBRARY_PATH" 
CLANG_NO_DEFAULT_CONFIG=1 \
 // RUN:   %clang %s -### -o %t.o --target=i386-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: --rtlib=platform -no-pie \
+// RUN: --rtlib=platform --unwindlib=platform -no-pie \
 // RUN: --gcc-toolchain="" 2>&1 | FileCheck --check-prefix=CHECK-LD-32 %s
 //
 // RUN: env -i LC_ALL=C PATH="" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" 
CLANG_NO_DEFAULT_CONFIG=1 \
 // RUN:   %clang %s -### -o %t.o --target=i386-unknown-linux \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: --rtlib=platform -no-pie \
+// RUN: --rtlib=platform --unwindlib=platform -no-pie \
 // RUN: --gcc-toolchain="" 2>&1 | FileCheck --check-prefix=CHECK-LD-32 %s
 //
 // CHECK-LD-32-NOT: warning:

diff  --git a/clang/test/Driver/gcc-install-dir.cpp 
b/clang/test/Driver/gcc-install-dir.cpp
index 0d7094255812b4..5d45037860f771 100644
--- a/clang/test/Driver/gcc-install-dir.cpp
+++ b/clang/test/Driver/gcc-install-dir.cpp
@@ -2,7 +2,7 @@
 
 /// Test native GCC installation on Arch Linux i686.
 // RUN: %clang -### %s --target=i686-linux-gnu 
--sysroot=%S/Inputs/archlinux_i686_tree -ccc-install-dir 
%S/Inputs/basic_linux_tree/usr/bin \
-// RUN:   --stdlib=platform --rtlib=platform \
+// RUN:   --stdlib=platform --rtlib=platform --unwindlib=platform \
 // RUN:   
--gcc-install-dir=%S/Inputs/archlinux_i686_tree/usr/lib/gcc/i686-pc-linux-gnu/11.1.0
 2>&1 | FileCheck %s --check-prefix=ARCH_I686
 // ARCH_I686:  "-internal-isystem"
 // ARCH_I686-SAME: {{^}} 
"[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0"
@@ -14,7 +14,7 @@
 
 /// Test native GCC installation on Debian amd64. --gcc-install-dir= may end 
with /.
 // RUN: %clangxx %s -### --target=x86_64-unknown-linux-gnu 

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

2023-08-01 Thread Sunil K via Phabricator via cfe-commits
koops added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:291
+  /// the frontend.
+  OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown;
+

ABataev wrote:
> I don't see where this field is stored/loaded for PCH support. You need add a 
> support for this in Serialization.
Since the ASTReader and ASTWriter are used by the developer of clang, it is 
preferable to show the internal state of the compiler as is, e.g. if "#pragma 
omp loop bind(parallel)" is changed to "#pragma omp for" then the ASTWriter has 
to show it as "#pragma omp for". I can change it to "#pragma omp loop 
bind(parallel)" using the MappedDirective that is stored however, that would be 
misleading to the developer of clang.


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] D156743: clang/OpenCL: Add inline implementations of sqrt in builtin header

2023-08-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 546164.
arsenm retitled this revision from "[wip] clang/OpenCL: Add inline 
implementations of sqrt in builtin header" to "clang/OpenCL: Add inline 
implementations of sqrt in builtin header".
arsenm edited the summary of this revision.
arsenm added a comment.

Move to base header and fix test. update_cc_test_checks 
--include-generated-funcs does a terrible job here so write manually checks


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

https://reviews.llvm.org/D156743

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
  clang/test/CodeGenCUDA/correctly-rounded-div.cu
  clang/test/CodeGenOpenCL/fpmath.cl
  clang/test/CodeGenOpenCL/sqrt-fpmath.cl
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -111,6 +111,13 @@
   static_assert(!is_const::value);
 }
 
+void test_builtin_elementwise_sqrt() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
 void test_builtin_elementwise_log() {
   const float a = 42.0;
   float b = 42.3;
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -601,6 +601,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_sqrt(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_sqrt(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_sqrt();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_sqrt(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_sqrt(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_sqrt(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_sqrt(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_trunc(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_trunc(f);
Index: clang/test/CodeGenOpenCL/fpmath.cl
===
--- clang/test/CodeGenOpenCL/fpmath.cl
+++ clang/test/CodeGenOpenCL/fpmath.cl
@@ -28,6 +28,21 @@
   return __builtin_sqrtf(a);
 }
 
+float elementwise_sqrt_f32(float a) {
+  // CHECK-LABEL: @elementwise_sqrt_f32
+  // NODIVOPT: call float @llvm.sqrt.f32(float %{{.+}}), !fpmath ![[MD_SQRT:[0-9]+]]
+  // DIVOPT: call float @llvm.sqrt.f32(float %{{.+}}){{$}}
+  return __builtin_elementwise_sqrt(a);
+}
+
+float4 elementwise_sqrt_v4f32(float4 a) {
+  // CHECK-LABEL: @elementwise_sqrt_v4f32
+  // NODIVOPT: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %{{.+}}), !fpmath ![[MD_SQRT:[0-9]+]]
+  // DIVOPT: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %{{.+}}){{$}}
+  return __builtin_elementwise_sqrt(a);
+}
+
+
 #if __OPENCL_C_VERSION__ >=120
 void printf(constant char* fmt, ...);
 
@@ -61,6 +76,18 @@
   return __builtin_sqrt(a);
 }
 
+double elementwise_sqrt_f64(double a) {
+  // CHECK-LABEL: @elementwise_sqrt_f64
+  // CHECK: call double @llvm.sqrt.f64(double %{{.+}}){{$}}
+  return __builtin_elementwise_sqrt(a);
+}
+
+double4 elementwise_sqrt_v4f64(double4 a) {
+  // CHECK-LABEL: @elementwise_sqrt_v4f64
+  // CHECK: call <4 x double> @llvm.sqrt.v4f64(<4 x double> %{{.+}}){{$}}
+  return __builtin_elementwise_sqrt(a);
+}
+
 #endif
 
 // NODIVOPT: ![[MD_FDIV]] = !{float 2.50e+00}
Index: clang/test/CodeGenCUDA/correctly-rounded-div.cu
===
--- clang/test/CodeGenCUDA/correctly-rounded-div.cu
+++ clang/test/CodeGenCUDA/correctly-rounded-div.cu
@@ -46,4 +46,18 @@
   return __builtin_sqrt(a);
 }
 
+// COMMON-LABEL: @_Z28test_builtin_elementwise_f32f
+// NCRDIV: call contract float @llvm.sqrt.f32(float %{{.+}}), !fpmath ![[MD:[0-9]+]]
+// CRDIV: call contract float @llvm.sqrt.f32(float %{{.+}}){{$}}
+__device__ float 

[PATCH] D156816: [Clang] Make generic aliases to OpenCL address spaces

2023-08-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D156816#4551338 , @yaxunl wrote:

>> FFI isn't the reason you'd use these, it's for generic access to the actual 
>> backend. E.g. an `addrspace(3)` global is local memory, if it's external 
>> it's dynamic. Having these named is better than doing it via the numerical 
>> address space. I'd like to use these in the C++ / OpenMP codes instead of 
>> the numeric ones but I don't like needing to use `opencl` in the name. 
>> Similarly to how we have the OpenCL atomics that should be usable outside of 
>> OpenCL.
>
> I agree these attributes are useful in other languages, but "global" and 
> "local" may need a more generic name suitable for all offloading languages. 
> To me, "device" can be a good alternative to "global". even "shared" seems 
> clearer than "local".

Global is common in https://llvm.org/docs/AMDGPUUsage.html#address-spaces and 
https://llvm.org/docs/NVPTXUsage.html#address-spaces. The main problem is 
`local` vs `shared` and `private` vs `local`. Unsure which one we should prefer 
in this case. Generally I feel a lot of this OpenCL stuff should've been named 
commonly at the start considering you can use most of them outside of the 
actual OpenCL language just fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156816

___
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-08-01 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 546159.
koops added a comment.

1. clang/test/OpenMP/loop_bind_enclosed.cpp : Converting main and function 
names within it to use regular expressions to accomodate windows platform.
2.

i) Instead of calling setMappedDirective() after the the creation of the 
Directive, made the MappedDirective a parameter of the Create() method. 
ii) setMappedDirective() is called from the Directive::Create()
iii) The inheritance is : OMPExecutableDirective --> OMPLoopBasedDirective --> 
OMPLoopDirective --> OMPSimdDirective, from OMPSimdDirective constructor it 
involves a lot of changes to initialize PrevMappedDirective variable in 
OMPExecutableDirective starting from OMPSimdDirective, even if the variable is 
"protected". Hence we call setMappedDirective() from OMPSimdDirective::Create().


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

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/OpenMP/generic_loop_ast_print.cpp
  clang/test/OpenMP/generic_loop_codegen.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 

  1   2   3   >