[PATCH] D120395: [X86] Prohibit arithmatic operations on type `__bfloat16`

2022-02-25 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 411334.
pengfei added a comment.

Disscussed with GCC folks. We think it's better to use the same way as D120411 
 that replacing it with short int.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120395

Files:
  clang/lib/Headers/avx512bf16intrin.h
  clang/lib/Headers/avx512vlbf16intrin.h
  clang/test/CodeGen/X86/avx512bf16-builtins.c
  clang/test/CodeGen/X86/avx512bf16-error.c
  clang/test/CodeGen/X86/avx512vlbf16-builtins.c
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -3369,8 +3369,8 @@
* - ``bfloat``
  - 16-bit "brain" floating-point value (7-bit significand).  Provides the
same number of exponent bits as ``float``, so that it matches its 
dynamic
-   range, but with greatly reduced precision.  Used in Intel's AVX-512 BF16
-   extensions and Arm's ARMv8.6-A extensions, among others.
+   range, but with greatly reduced precision.  Used in Arm's ARMv8.6-A
+   extensions, among others.
 
* - ``float``
  - 32-bit floating-point value
Index: clang/test/CodeGen/X86/avx512vlbf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512vlbf16-builtins.c
+++ clang/test/CodeGen/X86/avx512vlbf16-builtins.c
@@ -162,7 +162,7 @@
   return _mm256_mask_dpbf16_ps(D, U, A, B);
 }
 
-__bfloat16 test_mm_cvtness_sbh(float A) {
+unsigned short test_mm_cvtness_sbh(float A) {
   // CHECK-LABEL: @test_mm_cvtness_sbh
   // CHECK: @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
   // CHECK: ret i16 %{{.*}}
Index: clang/test/CodeGen/X86/avx512bf16-error.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/avx512bf16-error.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding -triple 
x86_64-linux-pc %s
+
+// expected-error@+1 3 {{unknown type name '__bfloat16'}}
+__bfloat16 foo(__bfloat16 a, __bfloat16 b) {
+  return a + b;
+}
+
+#include 
+
+// expected-warning@+2 3 {{'__bfloat16' is deprecated: use unsigned short 
instead}}
+// expected-note@* 3 {{'__bfloat16' has been explicitly marked deprecated 
here}}
+__bfloat16 bar(__bfloat16 a, __bfloat16 b) {
+  return a + b;
+}
Index: clang/test/CodeGen/X86/avx512bf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512bf16-builtins.c
+++ clang/test/CodeGen/X86/avx512bf16-builtins.c
@@ -4,7 +4,7 @@
 
 #include 
 
-float test_mm_cvtsbh_ss(__bfloat16 A) {
+float test_mm_cvtsbh_ss(unsigned short A) {
   // CHECK-LABEL: @test_mm_cvtsbh_ss
   // CHECK: zext i16 %{{.*}} to i32
   // CHECK: shl i32 %{{.*}}, 16
Index: clang/lib/Headers/avx512vlbf16intrin.h
===
--- clang/lib/Headers/avx512vlbf16intrin.h
+++ clang/lib/Headers/avx512vlbf16intrin.h
@@ -413,7 +413,8 @@
 ///A float data.
 /// \returns A bf16 data whose sign field and exponent field keep unchanged,
 ///and fraction field is truncated to 7 bits.
-static __inline__ __bfloat16 __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) {
+static __inline__ unsigned short __DEFAULT_FN_ATTRS128
+_mm_cvtness_sbh(float __A) {
   __v4sf __V = {__A, 0, 0, 0};
   __v8hi __R = __builtin_ia32_cvtneps2bf16_128_mask(
   (__v4sf)__V, (__v8hi)_mm_undefined_si128(), (__mmask8)-1);
Index: clang/lib/Headers/avx512bf16intrin.h
===
--- clang/lib/Headers/avx512bf16intrin.h
+++ clang/lib/Headers/avx512bf16intrin.h
@@ -15,7 +15,8 @@
 
 typedef short __m512bh __attribute__((__vector_size__(64), __aligned__(64)));
 typedef short __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
-typedef unsigned short __bfloat16;
+typedef unsigned short __bfloat16
+__attribute__((deprecated("use unsigned short instead")));
 
 #define __DEFAULT_FN_ATTRS512 \
   __attribute__((__always_inline__, __nodebug__, __target__("avx512bf16"), \
@@ -33,7 +34,7 @@
 ///A bfloat data.
 /// \returns A float data whose sign field and exponent field keep unchanged,
 ///and fraction field is extended to 23 bits.
-static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(__bfloat16 __A) {
+static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(unsigned short __A) {
   return __builtin_ia32_cvtsbf162ss_32(__A);
 }
 


Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -3369,8 +3369,8 @@
* - ``bfloat``
  - 16-bit "brain" floating-point value (7-bit significand).  Provides the
same number of exponent bits as ``float``, so that it matches its dynamic
-   range, but with greatly reduced precision.  Used in Intel's AV

[PATCH] D116593: Fix `performance-unnecessary-value-param` for template specialization

2022-02-25 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 411336.
Sockke added a comment.

Removed the fix for the template.


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

https://reviews.llvm.org/D116593

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
@@ -109,7 +109,7 @@
 
 template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
   // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
-  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+  // CHECK-NOT-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
 }
 
 void instantiated() {
@@ -381,3 +381,24 @@
   // CHECK-FIXES: void 
templateFunction(ExpensiveToCopyType E) {
   E.constReference();
 }
+
+template 
+T templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'E' is copied
+  // CHECK-NOT-FIXES: T templateSpecializationFunction(const 
ExpensiveToCopyType& E) {
+  return T();
+}
+
+template <>
+bool templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:57: warning: the parameter 'E' is copied
+  // CHECK-NOT-FIXES: bool templateSpecializationFunction(const 
ExpensiveToCopyType& E) {
+  return true;
+}
+
+template <>
+int templateSpecializationFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:56: warning: the parameter 'E' is copied
+  // CHECK-NOT-FIXES: int templateSpecializationFunction(const 
ExpensiveToCopyType& E) {
+  return 0;
+}
Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
@@ -69,7 +69,7 @@
 
 template  void templateWithNonTemplatizedParameter(const 
ExpensiveToCopyType S, T V) {
   // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
-  // CHECK-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+  // CHECK-NOT-FIXES: template  void 
templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
 }
 
 void instantiated() {
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -51,18 +51,6 @@
   return Matches.empty();
 }
 
-bool isExplicitTemplateSpecialization(const FunctionDecl &Function) {
-  if (const auto *SpecializationInfo = 
Function.getTemplateSpecializationInfo())
-if (SpecializationInfo->getTemplateSpecializationKind() ==
-TSK_ExplicitSpecialization)
-  return true;
-  if (const auto *Method = llvm::dyn_cast(&Function))
-if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
-Method->getMemberSpecializationInfo()->isExplicitSpecialization())
-  return true;
-  return false;
-}
-
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -146,11 +134,12 @@
   // 2. the function is virtual as it might break overrides
   // 3. the function is referenced outside of a call expression within the
   //compilation unit as the signature change could introduce build errors.
-  // 4. the function is an explicit template specialization.
+  // 4. the function is a primary template or an explicit template
+  // specialization.
   const auto *Method = llvm::dyn_cast(Function);
   if (Param->getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
   isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
-  isExplicitTemplateSpecialization(*Function))
+  (Function->getTemplatedKind() != FunctionDecl::TK_NonTemplate))
 return;
   for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
+++ clang-tools-e

[PATCH] D102555: [libclang] Enhance support for source-to-source rewriting

2022-02-25 Thread Sam Vervaeck via Phabricator via cfe-commits
samvv added a comment.

ggeorgakoudis no currently not. It has been stale for about a year. I also 
don't have a lot of time to to follow up right now, but I'll try to help if 
there is anything I can do.

- Original Message 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102555

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


[PATCH] D120499: [NVPTX] Fix nvvm.match.sync*.i64 intrinsics return type (i64 -> i32)

2022-02-25 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411341.
krisb added a comment.

Add SM_70 requirement for 'match' builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/Headers/__clang_cuda_intrinsics.h
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/match.ll

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
 
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
-  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
-  %v1 = extractvalue {i64, i1} %r1, 0
-  %p1 = extractvalue {i64, i1} %r1, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
-  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
-  %v2 = extractvalue {i64, i1} %r2, 0
-  %p2 = extractvalue {i64, i1} %r2, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
-  %r3 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
-  %v3 = extractvalue {i64, i1} %r3, 0
-  %p3 = extractvalue {i64, i1} %r3, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 4, 3;
-  %r4 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 3, i64 4)
-  %v4 = extractvalue {i64, i1} %r4, 0
-  %p4 = extractvalue {i64, i1} %r4, 1
-
-  %vsum1 = add i64 %v1, %v2
-  %vsum2 = add i64 %v3, %v4
-  %vsum3 = add i64 %vsum1, %vsum2
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  match.all.syn

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411340.
balazske added a comment.

Removed `isErrnoAvailable`, added test for `getErrnoValue`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/Errno.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_getErrno();
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno() == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno()); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/analyzer-enabled-checkers.c
===
-

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/Errno.h:22
+namespace ento {
+namespace errno_check {
+

steakhal wrote:
> balazske wrote:
> > steakhal wrote:
> > > I think we can settle on something better. What about calling it simply 
> > > `errno`?
> > Just `errno` may not work because it collides with the "real" errno (that 
> > is a macro).
> Ah, I see. Ugly macros!
> Then why not simply leave it in the `clang::ento` namespace?
It is better to have separate namespaces for the different inter-checker API's. 
Probably more functions will be added later to the `errno_modeling`.



Comment at: clang/lib/StaticAnalyzer/Checkers/Errno.h:24-26
+/// Returns if modeling of 'errno' is available.
+/// If not, the other functions here should not be used.
+bool isErrnoAvailable(ProgramStateRef State);

steakhal wrote:
> NoQ wrote:
> > balazske wrote:
> > > steakhal wrote:
> > > > I don't think we need this.
> > > > In `getErrnoValue()` we should simply return `UnknownVal` if we don't 
> > > > have 'errno.
> > > > And in `setErrnoValue()` we should return the incoming `State` 
> > > > unmodified.
> > > > 
> > > > THat being said, only a top-level `Check::BeginFunction` callback could 
> > > > see an 'errno' uninitialized, which I don't think is a real issue.
> > > > All the rest of the callbacks would run after it's initialized, thus 
> > > > would behave as expected.
> > > > And in case the translation unit doesn't have nor 'errno' variable nor 
> > > > 'errno_location_ish' functions, ignoring these `set/get` functions is 
> > > > actually the expected behavior.
> > > > 
> > > > Having to check `isErrnoAvailable()` would be really an anti-pattern.
> > > These work now if no ErrnoRegion is available. Returning `Optional` seems 
> > > not better than a required check before the call. I think the current 
> > > version is not the best: It can be possible to make assumptions using 
> > > `assume` on the returned `SVal` value, but this must not be done on a 
> > > non-existing errno value. For this case probably `isErrnoAvailable` is 
> > > required to be used.
> > > 
> > > The `isErrnoAvailable` can be useful for a checker that does special 
> > > things only if there is a working errno modeling.
> > > 
> > `UnknownVal` implies that it's an actual value but we don't know which one. 
> > If the value doesn't exist we shouldn't use it. And if the user doesn't 
> > include the appropriate header then the value really doesn't exist in the 
> > translation unit. So flavor-wise I think we shouldn't use `UnknownVal` 
> > here; I'd rather have an `Optional`.
> > 
> > Other than that, yeah, I think this is a good suggestion.
> Yeah, probably the `Optional` is a better alternative.
> 
> However, I'd like to explain my reasoning behind my previous suggestion:
> `Unknown` can/should model any values that the analyzer cannot currently 
> reason about: e.g. floating-point numbers.
> In this case, we cannot reason about the `errno`, thus I recommended it.
> 
> My point is, that we shouldn't regress our API for a marginal problem. And 
> according to my reasoning, this seems to be a marginal issue.
> Using `Optional` here is better than the current implementation, but not by 
> much.
> It would still result in a suboptimal coding pattern, where we guard each 
> access to get/set `errno` by an `if` statement. In the cases where we would 
> use the `getOr()` getter, I'm expecting to see the users pass the 
> `UnknownVal()` as the fallback value in most cases anyway.
I have removed now `isErrnoAvailable` and the get function returns `Optional`. 
I am not sure if this is the best option, if more functions will be added (to 
get the errno location, and get and set an "errno state").


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[PATCH] D120305: [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON

2022-02-25 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Hm, it looks like enabling PIE has a pretty big negative compile-time impact, 
with a 20% regression on sqlite3: 
http://llvm-compile-time-tracker.com/compare.php?from=611122892e6d5813444bdd0e1fbe0a96f6e09779&to=3c4ed02698afec021c6bca80740d1e58e3ee019e&stat=instructions
 Code-size on kimwitu++ regresses by 13%.

Is that kind of impact expected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120305

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.

Looks great, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[PATCH] D120489: [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:2634-2647
+.. _alpha-unix-cstring-UninitializedRead:
+
+alpha.unix.cstring.UninitializedRead (C)
+""
+Check for uninitialized read from source in memory copy function: 
``memcpy,mempcpy``.
+
+.. code-block:: c 

I was thinking about something like this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

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


[PATCH] D120305: [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON

2022-02-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D120305#3344938 , @nikic wrote:

> Hm, it looks like enabling PIE has a pretty big negative compile-time impact, 
> with a 20% regression on sqlite3: 
> http://llvm-compile-time-tracker.com/compare.php?from=611122892e6d5813444bdd0e1fbe0a96f6e09779&to=3c4ed02698afec021c6bca80740d1e58e3ee019e&stat=instructions
>  Code-size on kimwitu++ regresses by 13%.
>
> Is that kind of impact expected?

It's not expected on aarch64/x86-64. Some architectures not supporting 
PC-relative relocations (i386/ppc32) may suffer and that's expected.

We need to investigate the -fno-pic vs -fpie difference.
Many groups already use PIE and the investigation will be useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120305

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


[PATCH] D120527: [OpaquePtr][AArch64] Use elementtype on ldxr/stxr

2022-02-25 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

An alternative I suggested on https://github.com/llvm/llvm-project/issues/51165 
was to overload these intrinsics by result/value type. I think that would be 
cleaner design-wise, but it also seems harder to implement (requires custom ISD 
nodes), so I'm okay with the elementtype approach.




Comment at: llvm/lib/IR/Verifier.cpp:5508
+   ->isOpaqueOrPointeeTypeMatches(ElemTy),
+   "elementtype/pointee type mismatch");
+break;

This is checked generically for all elementtype attributes. You can also merge 
this into the previous switch case.



Comment at: llvm/test/Verifier/AArch64/lit.local.cfg:2
+if not 'AArch64' in config.root.targets:
+config.unsupported = True

This is unnecessary, target intrinsics are available even if the target isn't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120527

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


[PATCH] D120498: [AST] Test RecursiveASTVisitor's current traversal of templates.

2022-02-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:12
+//
+// shouldVisitTemplateInstantiations() controls traversal of AST nodes that
+// were created by instantiation, rather than by written code. This means:

I think this is a very useful documentation about the RAV API, instead of 
staying in the test file, I would suggest moving it to the RAV.h file.



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:18
+//   - Explicit instantiations are a tricky case:
+// - the "declaration part" (template args, function params etc) was 
written
+//   and should always be traversed.

Conceptually, an instantiations create a specific {Class, 
Var}TemplateSpecializationDecl, functionDecl.

```
template  void foo(T) { }
template void foo(); // Line 2
```

For the statement on line 2 (called `explicit instantiation definition` I think)
- there is no corresponding node in the clang AST, this is a missing feature in 
clang
- it creates a FunctionDecl, that is `void foo(char) { }`,

does the "declaration part" in the comment refer to the declaration part of the 
`explicit instantiation definition` (I think so), or the declaration part of 
the FunctionDecl `void foo(char) {}`? The same question to the definition, my 
understanding from the comment is the function body of the `void foo(char) {}`, 
which is `{}`.

We describe the expected behavior, but there are some bugs or unimplemented 
features in clang, which creates discrepancies. I think this is confusing and 
hard to follow, not sure how to do here (encoding a bunch of FIXMEs here is not 
good,  not mentioning them at all is not good neither, can we mention only 
critical ones?)






Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120498

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


[PATCH] D120504: [AST] RAV doesn't traverse explicitly instantiated function bodies by default

2022-02-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:168
 extern template int foo<3>();
 // Explicit instantiation. Head traversed, body only with instantiations 
on.
 template int foo<4>();

What does the Head mean? 



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:209
   Visitor.Instantiations = false;
   Visitor.ChooseTraversalRoot = [](ASTContext &Ctx) -> Decl * {
 for (auto *D : Ctx.getTranslationUnitDecl()->decls()) {

There are many declaration in the testcode, hard to figure out which one we are 
chosen, can you add a comment about which declaration is chosen as the 
traversal root? I think it is function decl instantiated by the `template int 
foo<4>();`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120504

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


[PATCH] D120504: [AST] RAV doesn't traverse explicitly instantiated function bodies by default

2022-02-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2107
 
-  if (CXXConstructorDecl *Ctor = dyn_cast(D)) {
-// Constructor initializers.

moving this part of code to `if (VisitBody)` seems like a different fix (and I 
think it is reasonable, from the grammar, the ctor-initializer is part of the 
function-body), can we separate it and add a test? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120504

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


[PATCH] D120445: [clang-format] Treat && followed by noexcept operator as a binary operator inside template arguments

2022-02-25 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

In D120445#3344594 , @penagos wrote:

> I went ahead and did a git rebase but CI still appears to be failing (though 
> tests pass in my local clone). Also, I’ll need someone to commit this on my 
> behalf:
>
> - Luis Penagos
> - l...@penagos.co
>
> Thanks!

Thank you, the failures are unrelated, these tests (libarcher, libomp...) 
failed in other precommit CI builds.
I'll commit it this weekend probably but I let other reviewers have a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120445

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


[clang] 6114491 - [C++20][Modules][4/8] Handle generation of partition implementation CMIs.

2022-02-25 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-02-25T09:33:14Z
New Revision: 6114491441700cc8a614d284407e9a6e9bf74751

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

LOG: [C++20][Modules][4/8] Handle generation of partition implementation CMIs.

Partition implementations are special, they generate a CMI, but it
does not have an 'export' line, and we cannot export anything from the
it [that is it can only make decls available to other members of the
owning module, not to importers of that].

Add initial testcases for partition handling, derived from the examples in
Section 10 of the C++20 standard, which identifies what should be accepted
and/or rejected.

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

Added: 
clang/test/Modules/cxx20-10-1-ex1.cpp
clang/test/Modules/cxx20-10-1-ex2.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/cxx20-import-diagnostics-a.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 436718a54640e..0b872c48482db 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2943,8 +2943,10 @@ class Sema final {
   SourceLocation SemiLoc);
 
   enum class ModuleDeclKind {
-Interface,  ///< 'export module X;'
-Implementation, ///< 'module X;'
+Interface,   ///< 'export module X;'
+Implementation,  ///< 'module X;'
+PartitionInterface,  ///< 'export module X:Y;'
+PartitionImplementation, ///< 'module X:Y;'
   };
 
   /// An enumeration to represent the transition of states in parsing module

diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index a797644754b59..b2515075a7f23 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -110,9 +110,24 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
   // module state;
   ImportState = ModuleImportState::NotACXX20Module;
 
-  // A module implementation unit requires that we are not compiling a module
-  // of any kind. A module interface unit requires that we are not compiling a
-  // module map.
+  bool IsPartition = !Partition.empty();
+  if (IsPartition)
+switch (MDK) {
+case ModuleDeclKind::Implementation:
+  MDK = ModuleDeclKind::PartitionImplementation;
+  break;
+case ModuleDeclKind::Interface:
+  MDK = ModuleDeclKind::PartitionInterface;
+  break;
+default:
+  llvm_unreachable("how did we get a partition type set?");
+}
+
+  // A (non-partition) module implementation unit requires that we are not
+  // compiling a module of any kind.  A partition implementation emits an
+  // interface (and the AST for the implementation), which will subsequently
+  // be consumed to emit a binary.
+  // A module interface unit requires that we are not compiling a module map.
   switch (getLangOpts().getCompilingModule()) {
   case LangOptions::CMK_None:
 // It's OK to compile a module interface as a normal translation unit.
@@ -123,7 +138,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
   break;
 
 // We were asked to compile a module interface unit but this is a module
-// implementation unit. That indicates the 'export' is missing.
+// implementation unit.
 Diag(ModuleLoc, diag::err_module_interface_implementation_mismatch)
   << FixItHint::CreateInsertion(ModuleLoc, "export ");
 MDK = ModuleDeclKind::Interface;
@@ -180,7 +195,6 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
   // modules, the dots here are just another character that can appear in a
   // module name.
   std::string ModuleName = stringFromPath(Path);
-  bool IsPartition = !Partition.empty();
   if (IsPartition) {
 ModuleName += ":";
 ModuleName += stringFromPath(Partition);
@@ -202,7 +216,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
   Module *Mod;
 
   switch (MDK) {
-  case ModuleDeclKind::Interface: {
+  case ModuleDeclKind::Interface:
+  case ModuleDeclKind::PartitionInterface: {
 // We can't have parsed or imported a definition of this module or parsed a
 // module map defining it already.
 if (auto *M = Map.findModule(ModuleName)) {
@@ -219,36 +234,36 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
SourceLocation ModuleLoc,
 // Create a Module for the module that we're defining.
 Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName,
GlobalModuleFragment);
-if (IsPartition)
+if (MDK == ModuleDeclKind::PartitionInterface)
   Mod->Kind = Module::ModulePartitionInterface;
 assert(Mod && "module creation 

[PATCH] D118587: [C++20][Modules][4/8] Handle generation of partition implementation CMIs.

2022-02-25 Thread Iain Sandoe 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 rG611449144170: [C++20][Modules][4/8] Handle generation of 
partition implementation CMIs. (authored by iains).

Changed prior to commit:
  https://reviews.llvm.org/D118587?vs=410514&id=411349#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118587

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-10-1-ex1.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -95,9 +95,9 @@
 //--- import-diags-tu7.cpp
 
 module;
-// We can only have preprocessor commands here, which could include an include
+// We can only have preprocessor directives here, which permits an include-
 // translated header unit.  However those are identified specifically by the
-// preprocessor; non-preprocessed user code should not contain an import here.
+// preprocessor; non-preprocessed user code should not contain an 'import' here.
 import B; // expected-error {{module imports cannot be in the global module fragment}}
 
 export module D;
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -0,0 +1,64 @@
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu1.cpp \
+// RUN:  -o %t/B_Y.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu2.cpp \
+// RUN:  -fmodule-file=%t/B_Y.pcm -o %t/B.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu3.cpp \
+// RUN:   -o %t/B_X1.pcm -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu4.cpp \
+//   -fmodule-file=%t/B.pcm  -o %t/B_X2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex2-tu5.cpp \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu5.o
+
+// RUN: %clang_cc1 -std=c++20 -S %t/std10-1-ex2-tu6.cpp \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu6.s -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu7.cpp \
+//   -fmodule-file=%t/B_X2.pcm  -o %t/B_X3.pcm -verify
+
+//--- std10-1-ex2-tu1.cpp
+module B:Y;
+int y();
+// expected-no-diagnostics
+
+//--- std10-1-ex2-tu2.cpp
+export module B;
+import :Y;
+int n = y();
+// expected-no-diagnostics
+
+//--- std10-1-ex2-tu3.cpp
+module B:X1; // does not implicitly import B
+int &a = n;  // expected-error {{use of undeclared identifier }}
+
+//--- std10-1-ex2-tu4.cpp
+module B:X2; // does not implicitly import B
+import B;
+int &b = n; // OK
+// expected-no-diagnostics
+
+//--- std10-1-ex2-tu5.cpp
+module B;   // implicitly imports B
+int &c = n; // OK
+// expected-no-diagnostics
+
+//--- std10-1-ex2-tu6.cpp
+import B;
+// error, n is module-local and this is not a module.
+int &c = n; // expected-error {{use of undeclared identifier}}
+
+//--- std10-1-ex2-tu7.cpp
+module B:X3; // does not implicitly import B
+import :X2;  // X2 is an implementation so exports nothing.
+ // error: n not visible here.
+int &c = n;  // expected-error {{use of undeclared identifier }}
Index: clang/test/Modules/cxx20-10-1-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex1.cpp
@@ -0,0 +1,48 @@
+// The example in the standard is not in required build order.
+// revised here
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex1-tu1.cpp \
+// RUN:  -o %t/A_Internals.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex1-tu2.cpp \
+// RUN:  -fmodule-file=%t/A_Internals.pcm -o %t/A_Foo.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex1-tu3.cpp \
+// RUN:  -fmodule-file=%t/A_Foo.pcm -o %t/A.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex1-tu4.cpp \
+// RUN:  -fmodule-file=%t/A.pcm -o %t/ex1.o
+
+// expected-no-diagnostics
+
+//--- std10-1-ex1-tu1.cpp
+
+module A:Internals;
+int bar();
+
+//--- std10-1-ex1-tu2.cpp
+
+export module A:Foo;
+
+import :Internals;
+
+export int foo() { return 2 * (bar() + 1); }
+
+//--- std10-1-ex1-tu3.cpp
+
+export module A;
+export import :Foo;
+export int baz();
+
+//--- std10-1-ex1-tu4.cpp
+
+module A;
+
+import :Internals;
+
+int bar() { return baz() - 10; }
+int baz() { return 30; }
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/Sem

[clang] 2e9439e - [flang][driver] Add support for `--target`/`--triple`

2022-02-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-02-25T09:38:10Z
New Revision: 2e9439e4891c3d427c0fed477b54f3da2ff8ec28

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

LOG: [flang][driver] Add support for `--target`/`--triple`

This patch adds support for:
  * `--target` in the compiler driver (`flang-new`)
  * `--triple` in the frontend driver (`flang-new -fc1`)
The semantics of these flags are inherited from `clangDriver`, i.e.
consistent with `clang --target` and `clang -cc1 --triple`,
respectively.

A new structure is defined, `TargetOptions`, that will hold various
Frontend options related to the target. Currently, this is mostly a
placeholder that contains the target triple. In the future, it will be
used for storing e.g. the CPU to tune for or the target features to
enable.

Additionally, the following target/triple related options are enabled
[*]: `-print-effective-triple`, `-print-target-triple`. Definitions in
Options.td are updated accordingly and, to facilated testing,
`-emit-llvm` is added to the list of options available in `flang-new`
(previously it was only enabled in `flang-new -fc1`).

[*] These options were actually available before (like all other options
defined in `clangDriver`), but not included in `flang-new --help`.
Before this change, `flang-new` would just use `native` for defining the
target, so these options were of little value.

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

Added: 
flang/include/flang/Frontend/TargetOptions.h
flang/test/Driver/print-effective-triple.f90
flang/test/Driver/print-target-triple.f90
flang/test/Driver/target.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8dd16ca990a14..60e90f3f2237a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1078,7 +1078,7 @@ def d_Flag : Flag<["-"], "d">, Group;
 def d_Joined : Joined<["-"], "d">, Group;
 def emit_ast : Flag<["-"], "emit-ast">,
   HelpText<"Emit Clang AST files for source inputs">;
-def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option]>, 
Group,
+def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, 
FlangOption]>, Group,
   HelpText<"Use the LLVM representation for assembler and object files">;
 def emit_interface_stubs : Flag<["-"], "emit-interface-stubs">, 
Flags<[CC1Option]>, Group,
   HelpText<"Generate Interface Stub Files.">;
@@ -3894,9 +3894,9 @@ def print_multi_lib : Flag<["-", "--"], 
"print-multi-lib">;
 def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
   Flags<[Unsupported]>;
 def print_target_triple : Flag<["-", "--"], "print-target-triple">,
-  HelpText<"Print the normalized target triple">;
+  HelpText<"Print the normalized target triple">, Flags<[FlangOption]>;
 def print_effective_triple : Flag<["-", "--"], "print-effective-triple">,
-  HelpText<"Print the effective target triple">;
+  HelpText<"Print the effective target triple">, Flags<[FlangOption]>;
 def print_multiarch : Flag<["-", "--"], "print-multiarch">,
   HelpText<"Print the multiarch target triple">;
 def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
@@ -4014,7 +4014,7 @@ def no_system_header_prefix : Joined<["--"], 
"no-system-header-prefix=">,
"system header.">;
 def : Separate<["--"], "no-system-header-prefix">, 
Alias;
 def s : Flag<["-"], "s">, Group;
-def target : Joined<["--"], "target=">, Flags<[NoXarchOption, CoreOption]>,
+def target : Joined<["--"], "target=">, Flags<[NoXarchOption, CoreOption, 
FlangOption]>,
   HelpText<"Generate code for the given target">;
 def darwin_target_variant : Separate<["-"], "darwin-target-variant">,
   Flags<[NoXarchOption, CoreOption]>,
@@ -4803,7 +4803,7 @@ def emit_fir : Flag<["-"], "emit-fir">, Alias;
 let Flags = [CC1Option, NoDriverOption] in {
 
 
//===--===//
-// Target Options
+// Target Options (cc1 + cc1as)
 
//===--===//
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
@@ -4817,10 +4817,6 @@ def tune_cpu : Separate<["-"], "tune-cpu">,
 def target_feature : Separate<["-"], "target-feature">,
   HelpText<"Target specific attributes">,
   MarshallingInfoStringVector>;
-def triple : Separate<["-"], "triple">,
-  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
- 

[PATCH] D120246: [flang][driver] Add support for `--target`/`--triple`

2022-02-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e9439e4891c: [flang][driver] Add support for 
`--target`/`--triple` (authored by awarzynski).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120246

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/TargetOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/print-effective-triple.f90
  flang/test/Driver/print-target-triple.f90
  flang/test/Driver/target.f90

Index: flang/test/Driver/target.f90
===
--- /dev/null
+++ flang/test/Driver/target.f90
@@ -0,0 +1,13 @@
+!  Test that --target indeed sets the target
+
+!-
+! RUN LINES
+!-
+! RUN: %flang --target=unknown-unknown-unknown -emit-llvm -c %s \
+! RUN:   -o %t.o -### 2>&1 | FileCheck %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! CHECK: Target: unknown-unknown-unknown
+! CHECK: "-triple" "unknown-unknown-unknown"
Index: flang/test/Driver/print-target-triple.f90
===
--- /dev/null
+++ flang/test/Driver/print-target-triple.f90
@@ -0,0 +1,16 @@
+! Test that -print-target-triple prints correct triple
+
+!-
+! RUN LINES
+!-
+! RUN: %flang -print-target-triple 2>&1 --target=aarch64-linux-gnu \
+! RUN:   | FileCheck --check-prefix=AARCH64 %s
+
+! RUN: %flang -print-target-triple 2>&1 --target=x86_64-linux-gnu \
+! RUN:   | FileCheck --check-prefix=X86_64 %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! X86_64: x86_64-unknown-linux-gnu
+! AARCH64: aarch64-unknown-linux-gnu
Index: flang/test/Driver/print-effective-triple.f90
===
--- /dev/null
+++ flang/test/Driver/print-effective-triple.f90
@@ -0,0 +1,11 @@
+! Test that -print-target-triple prints correct triple.
+
+!-
+! RUN LINE
+!-
+! RUN: %flang -print-effective-triple 2>&1 --target=thumb-linux-gnu | FileCheck %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! CHECK: armv4t-unknown-linux-gnu
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -21,6 +21,7 @@
 ! HELP-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-NEXT: -c Only run preprocess, compile, and assemble steps
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -falternative-parameter-statement
 ! HELP-NEXT: Enable the old style PARAMETER statement
@@ -50,8 +51,11 @@
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -print-effective-triple Print the effective target triple
+! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -P Disable linemarker output in -E mode
 ! HELP-NEXT: -std=   Language standard to compile for
+! HELP-NEXT: --target=   Generate code for the given target
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -WEnable the specified warning
@@ -124,6 +128,7 @@
 ! HELP-FC1-NEXT: -P Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
+! HELP-FC1-NEXT: -triple Specify target triple (e.g. i686-apple-darwin9)
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 ! HELP-FC1-NEXT: -WEnable the specified warning
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -21,6 +21,7 @@
 ! CHECK-NEXT: -cpp  

[PATCH] D98152: [InstCombine] Canonicalize SPF to min/max intrinsics

2022-02-25 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

This fixed 9 bugs reports by Alive2:

- Transforms/InstCombine/max-of-nots.ll
- Transforms/InstCombine/max_known_bits.ll
- Transforms/InstCombine/minmax-fold.ll
- Transforms/InstCombine/saturating-add-sub.ll
- Transforms/InstCombine/select-pr39595.ll
- Transforms/InstCombine/select_meta.ll
- Transforms/InstCombine/sext.ll
- Transforms/InstCombine/sub.ll
- Transforms/InstCombine/with_overflow.ll

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98152

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411363.
balazske added a comment.

Fixed remaining problems.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/Errno.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_getErrno();
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno() == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno()); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/analyzer-enabled-checkers.c
===
--- clang/test/Analysis/analyzer-en

[clang] b48e3c8 - [OpenCL] opencl-c.h: Fix incorrect get_image_width guard

2022-02-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-25T11:05:56Z
New Revision: b48e3c805c253d0a1194bede81b3f8e225f40824

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

LOG: [OpenCL] opencl-c.h: Fix incorrect get_image_width guard

`cl_khr_3d_image_writes` should not guard `read_only image3d_t`.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 0adf07cc7e3db..9b8461bfccfda 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15715,9 +15715,7 @@ void __ovld write_imageh(read_write image1d_buffer_t, 
int, half4);
 int __ovld __cnfn get_image_width(read_only image1d_t);
 int __ovld __cnfn get_image_width(read_only image1d_buffer_t);
 int __ovld __cnfn get_image_width(read_only image2d_t);
-#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_only image3d_t);
-#endif
 int __ovld __cnfn get_image_width(read_only image1d_array_t);
 int __ovld __cnfn get_image_width(read_only image2d_array_t);
 #ifdef cl_khr_depth_images



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


[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-25 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 updated this revision to Diff 411368.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

Files:
  clang/include/clang/Lex/Lexer.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Lex/Lexer.cpp

Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -136,7 +136,8 @@
  Preprocessor &PP, bool IsFirstIncludeOfFile)
 : PreprocessorLexer(&PP, FID),
   FileLoc(PP.getSourceManager().getLocForStartOfFile(FID)),
-  LangOpts(PP.getLangOpts()), IsFirstTimeLexingFile(IsFirstIncludeOfFile) {
+  LangOpts(PP.getLangOpts()), LineComment(LangOpts.LineComment),
+  IsFirstTimeLexingFile(IsFirstIncludeOfFile) {
   InitLexer(InputFile.getBufferStart(), InputFile.getBufferStart(),
 InputFile.getBufferEnd());
 
@@ -149,7 +150,7 @@
 Lexer::Lexer(SourceLocation fileloc, const LangOptions &langOpts,
  const char *BufStart, const char *BufPtr, const char *BufEnd,
  bool IsFirstIncludeOfFile)
-: FileLoc(fileloc), LangOpts(langOpts),
+: FileLoc(fileloc), LangOpts(langOpts), LineComment(LangOpts.LineComment),
   IsFirstTimeLexingFile(IsFirstIncludeOfFile) {
   InitLexer(BufStart, BufPtr, BufEnd);
 
@@ -2376,13 +2377,13 @@
 bool &TokAtPhysicalStartOfLine) {
   // If Line comments aren't explicitly enabled for this language, emit an
   // extension warning.
-  if (!LangOpts.LineComment) {
+  if (!LineComment) {
 if (!isLexingRawMode()) // There's no PP in raw mode, so can't emit diags.
   Diag(BufferPtr, diag::ext_line_comment);
 
 // Mark them enabled so we only emit one warning for this translation
 // unit.
-LangOpts.LineComment = true;
+LineComment = true;
   }
 
   // Scan over the body of the comment.  The common case, when scanning, is that
@@ -3433,8 +3434,7 @@
 // If the next token is obviously a // or /* */ comment, skip it efficiently
 // too (without going through the big switch stmt).
 if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() &&
-LangOpts.LineComment &&
-(LangOpts.CPlusPlus || !LangOpts.TraditionalCPP)) {
+LineComment && (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP)) {
   if (SkipLineComment(Result, CurPtr+2, TokAtPhysicalStartOfLine))
 return true; // There is a token to return.
   goto SkipIgnoredUnits;
@@ -3741,8 +3741,8 @@
   // "foo".  Check to see if the character after the second slash is a '*'.
   // If so, we will lex that as a "/" instead of the start of a comment.
   // However, we never do this if we are just preprocessing.
-  bool TreatAsComment = LangOpts.LineComment &&
-(LangOpts.CPlusPlus || !LangOpts.TraditionalCPP);
+  bool TreatAsComment =
+  LineComment && (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP);
   if (!TreatAsComment)
 if (!(PP && PP->isPreprocessedOutput()))
   TreatAsComment = getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*';
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -17,6 +17,7 @@
 
 #include "Encoding.h"
 #include "FormatToken.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
@@ -101,6 +102,7 @@
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
+  LangOptions LangOpts;
   const SourceManager &SourceMgr;
   FileID ID;
   const FormatStyle &Style;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -28,13 +28,13 @@
 llvm::SpecificBumpPtrAllocator &Allocator,
 IdentifierTable &IdentTable)
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0),
+  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
-  Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr,
-  getFormattingLangOpts(Style)));
+  Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
   for (const std::string &ForEachMacro : Style.ForEachMacros) {
@@ -1079,9 +1079,9

[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-25 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added a comment.

Unfortunately after change there is lifetime issue in FormatTokenLexer because 
LangOpts received from getFormattingLangOpts has automatic storage duration and 
Lexer gets reference to it.
Fix issue and poke CI to make sure clang-tools-extra tests on CI are passing. 
For now it's only about making CI happy, I'm gonna check also if nice 
performance gains are preserved (I guess they should be).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

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


[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-25 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added a comment.

In D120334#3340639 , @cor3ntin wrote:

> I like this approach. it seems a lot easier to maintain as people don't have 
> to remember to use LangOptionsBase to not degrade performance

I like it either but we need to be careful about LangOptions lifetime as my 
previous comment shows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

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


[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-25 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added inline comments.



Comment at: clang/include/clang/Lex/Lexer.h:94
+  // LangOpts enabled by this language.
+  const LangOptions &LangOpts;
+

cor3ntin wrote:
> Should we add a comment to explain why this is a reference?
Good idea. It will be added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

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


[PATCH] D120484: More explicit message when failing to find a mandatory cfi ressource file

2022-02-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120484

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


[PATCH] D114425: [clang] Add __builtin_bswap128

2022-02-25 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114425

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


[PATCH] D116439: [clang-tidy] Fix `readability-const-return-type` for pure virtual function.

2022-02-25 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 411372.
Sockke added a comment.

Removed the fix for the virtual function.


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

https://reviews.llvm.org/D116439

Files:
  clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
@@ -271,3 +271,17 @@
 
 int **const * n_multiple_ptr();
 int *const & n_pointer_ref();
+
+class PVBase {
+public:
+  virtual const int getC() = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 
'const'-qualified at the top level, which may reduce code readability without 
improving const correctness
+  // CHECK-NOT-FIXES: virtual int getC() = 0;
+};
+
+class PVDerive : public PVBase {
+public:
+  const int getC() { return 1; }
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 
'const'-qualified at the top level, which may reduce code readability without 
improving const correctness
+  // CHECK-NOT-FIXES: int getC() { return 1; }
+};
Index: clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -97,7 +97,9 @@
   // Find all function definitions for which the return types are `const`
   // qualified.
   Finder->addMatcher(
-  functionDecl(returns(isConstQualified()), isDefinition()).bind("func"),
+  functionDecl(returns(isConstQualified()),
+   anyOf(isDefinition(), cxxMethodDecl(isPure(
+  .bind("func"),
   this);
 }
 
@@ -115,6 +117,12 @@
 << Def->getReturnType();
 if (CR.ConstRange.isValid())
   Diagnostic << CR.ConstRange;
+
+// Do not propose fixes for virtual function.
+const auto *Method = llvm::dyn_cast(Def);
+if (Method && Method->isVirtual())
+  return;
+
 for (auto &Hint : CR.Hints)
   Diagnostic << Hint;
   }


Index: clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp
@@ -271,3 +271,17 @@
 
 int **const * n_multiple_ptr();
 int *const & n_pointer_ref();
+
+class PVBase {
+public:
+  virtual const int getC() = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness
+  // CHECK-NOT-FIXES: virtual int getC() = 0;
+};
+
+class PVDerive : public PVBase {
+public:
+  const int getC() { return 1; }
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness
+  // CHECK-NOT-FIXES: int getC() { return 1; }
+};
Index: clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -97,7 +97,9 @@
   // Find all function definitions for which the return types are `const`
   // qualified.
   Finder->addMatcher(
-  functionDecl(returns(isConstQualified()), isDefinition()).bind("func"),
+  functionDecl(returns(isConstQualified()),
+   anyOf(isDefinition(), cxxMethodDecl(isPure(
+  .bind("func"),
   this);
 }
 
@@ -115,6 +117,12 @@
 << Def->getReturnType();
 if (CR.ConstRange.isValid())
   Diagnostic << CR.ConstRange;
+
+// Do not propose fixes for virtual function.
+const auto *Method = llvm::dyn_cast(Def);
+if (Method && Method->isVirtual())
+  return;
+
 for (auto &Hint : CR.Hints)
   Diagnostic << Hint;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 29b512b - [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-02-25T12:42:55+01:00
New Revision: 29b512ba322cb6dd2c45d5e07645e20db47fad0d

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

LOG: [clang][analyzer] Add modeling of 'errno'.

Add a checker to maintain the system-defined value 'errno'.
The value is supposed to be set in the future by existing or
new checkers that evaluate errno-modifying function calls.

Reviewed By: NoQ, steakhal

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

Added: 
clang/lib/StaticAnalyzer/Checkers/Errno.h
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
clang/test/Analysis/Inputs/errno_func.h
clang/test/Analysis/Inputs/errno_var.h
clang/test/Analysis/errno.c

Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/global-region-invalidation.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index fae4240e9d701..6b72d64950106 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -348,6 +348,10 @@ def NullableReturnedFromNonnullChecker : 
Checker<"NullableReturnedFromNonnull">,
 
 let ParentPackage = APIModeling in {
 
+def ErrnoModeling : Checker<"Errno">,
+  HelpText<"Make the special value 'errno' available to other checkers.">,
+  Documentation;
+
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   // Uninitialized value check is a mandatory dependency. This Checker asserts
@@ -1556,6 +1560,11 @@ def StreamTesterChecker : Checker<"StreamTester">,
"purposes.">,
   Documentation;
 
+def ErrnoTesterChecker : Checker<"ErrnoTest">,
+  HelpText<"Check modeling aspects of 'errno'.">,
+  Dependencies<[ErrnoModeling]>,
+  Documentation;
+
 def ExprInspectionChecker : Checker<"ExprInspection">,
   HelpText<"Check the analyzer's understanding of expressions">,
   Documentation;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index 9f85347db5df7..0db6d92c63131 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -764,7 +764,8 @@ class SymbolicRegion : public SubRegion {
 assert(s->getType()->isAnyPointerType() ||
s->getType()->isReferenceType() ||
s->getType()->isBlockPointerType());
-assert(isa(sreg) || isa(sreg));
+assert(isa(sreg) || isa(sreg) ||
+   isa(sreg));
   }
 
 public:
@@ -1375,7 +1376,9 @@ class MemRegionManager {
 const LocationContext *LC);
 
   /// Retrieve or create a "symbolic" memory region.
-  const SymbolicRegion* getSymbolicRegion(SymbolRef Sym);
+  /// If no memory space is specified, `UnknownSpaceRegion` will be used.
+  const SymbolicRegion *
+  getSymbolicRegion(SymbolRef Sym, const MemSpaceRegion *MemSpace = nullptr);
 
   /// Return a unique symbolic region belonging to heap memory space.
   const SymbolicRegion *getSymbolicHeapRegion(SymbolRef sym);

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 44fa2a06c3994..15043c1c632e4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -40,6 +40,8 @@ add_clang_library(clangStaticAnalyzerCheckers
   DynamicTypePropagation.cpp
   DynamicTypeChecker.cpp
   EnumCastOutOfRangeChecker.cpp
+  ErrnoModeling.cpp
+  ErrnoTesterChecker.cpp
   ExprInspectionChecker.cpp
   FixedAddressChecker.cpp
   FuchsiaHandleChecker.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/Errno.h 
b/clang/lib/StaticAnalyzer/Checkers/Errno.h
new file mode 100644
index 0..e564809d6bda9
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/Errno.h
@@ -0,0 +1,39 @@
+//=== Errno.h - Tracking value of 'errno'. -*- C++ 
-*-//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri 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 rG29b512ba322c: [clang][analyzer] Add modeling of 
'errno'. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/Errno.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_getErrno();
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno() == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno()); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/a

[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-25 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 411375.
achieveartificialintelligence added a comment.

Thanks for @craig.topper's patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

Files:
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoD.td
  llvm/lib/Target/RISCV/RISCVInstrInfoF.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/zfinx-types.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-valid.s
  llvm/test/MC/RISCV/rv32zfinx-invalid.s
  llvm/test/MC/RISCV/rv32zfinx-valid.s
  llvm/test/MC/RISCV/rv32zhinx-invalid.s
  llvm/test/MC/RISCV/rv32zhinx-valid.s
  llvm/test/MC/RISCV/rv32zhinxmin-invalid.s
  llvm/test/MC/RISCV/rv32zhinxmin-valid.s
  llvm/test/MC/RISCV/rv64zdinx-invalid.s
  llvm/test/MC/RISCV/rv64zdinx-valid.s
  llvm/test/MC/RISCV/rv64zfinx-invalid.s
  llvm/test/MC/RISCV/rv64zfinx-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinx-valid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-valid.s
  llvm/test/MC/RISCV/rvzdinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzhinx-aliases-valid.s

Index: llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
@@ -0,0 +1,82 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+
+##===--===##
+## Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
+##===--===##
+
+# CHECK-INST: fsgnjx.h s1, s2, s2
+# CHECK-ALIAS: fabs.h s1, s2
+fabs.h s1, s2
+# CHECK-INST: fsgnjn.h s2, s3, s3
+# CHECK-ALIAS: fneg.h s2, s3
+fneg.h s2, s3
+
+# CHECK-INST: flt.h tp, s6, s5
+# CHECK-ALIAS: flt.h tp, s6, s5
+fgt.h x4, s5, s6
+# CHECK-INST: fle.h t2, s1, s0
+# CHECK-ALIAS: fle.h t2, s1, s0
+fge.h x7, x8, x9
+
+##===--===##
+## Aliases which omit the rounding mode.
+##===--===##
+
+# CHECK-INST: fmadd.h a0, a1, a2, a3, dyn
+# CHECK-ALIAS: fmadd.h a0, a1, a2, a3
+fmadd.h x10, x11, x12, x13
+# CHECK-INST: fmsub.h a4, a5, a6, a7, dyn
+# CHECK-ALIAS: fmsub.h a4, a5, a6, a7
+fmsub.h x14, x15, x16, x17
+# CHECK-INST: fnmsub.h s2, s3, s4, s5, dyn
+# CHECK-ALIAS: fnmsub.h s2, s3, s4, s5
+fnmsub.h x18, x19, x20, x21
+# CHECK-INST: fnmadd.h s6, s7, s8, s9, dyn
+# CHECK-ALIAS: fnmadd.h s6, s7, s8, s9
+fnmadd.h x22, x23, x24, x25
+# CHECK-INST: fadd.h s10, s11, t3, dyn
+# CHECK-ALIAS: fadd.h s10, s11, t3
+fadd.h x26, x27, x28
+# CHECK-INST: fsub.h t4, t5, t6, dyn
+# CHECK-ALIAS: fsub.h t4, t5, t6
+fsub.h x29, x30, x31
+# CHECK-INST: fmul.h s0, s1, s2, dyn
+# CHECK-ALIAS: fmul.h s0, s1, s2
+fmul.h s0, s1, s2
+# CHECK-INST: fdiv.h s3, s4, s5, dyn
+# CHECK-ALIAS: fdiv.h s3, s4, s5
+fdiv.h s3, s4, s5
+# CHECK-INST: fsqrt.h s6, s7, dyn
+# CHECK-ALIAS: fsqrt.h s6, s7
+fsqrt.h s6, s7
+# CHECK-INST: fcvt.w.h a0, s5, dyn
+# CHECK-ALIAS: fcvt.w.h a0, s5
+fcvt.w.h a0, s5
+# CHECK-INST: fcvt.wu.h a1, s6, dyn
+# CHECK-ALIAS: fcvt.wu.h a1, s6
+fcvt.wu.h a1, s6
+# CHECK-INST: fcvt.h.w t6, a4, dyn
+# CHECK-ALIAS: fcvt.h.w t6, a4
+fcvt.h.w t6, a4
+# CHECK-INST: fcvt.h.wu s0, a5, dyn
+# CHECK-ALIAS: fcvt.h.wu s0, a5
+f

[PATCH] D114425: [clang] Add __builtin_bswap128

2022-02-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:64
+- Maximum _ExtInt size was decreased from 16,777,215 bits to 8,388,608 bits.
+  Motivation for this was discussed in PR51829.
+- Configuration file syntax extended with  token. This expands to

?

Wrong rebase?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114425

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


[PATCH] D116439: [clang-tidy] Fix `readability-const-return-type` for pure virtual function.

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

LGTM aside from a nit; can you also add a release note about the fix to 
clang-tools-extra/docs/ReleaseNotes.rst?




Comment at: 
clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp:122
+// Do not propose fixes for virtual function.
+const auto *Method = llvm::dyn_cast(Def);
+if (Method && Method->isVirtual())




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

https://reviews.llvm.org/D116439

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


[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> Also implemented decltype(auto)(x) (https://wg21.link/p0849r2) as a Clang 
> extension.

I'd like to better understand the use cases for this. WG21 considered this as 
part of the feature and ultimately rejected it (fairly strongly, according to 
the EWG polls). From the meeting minutes, it says that the reason EWG disliked 
the idea is because of its expert-friendly nature and that this facility would 
present teachability issues. I tend to agree, so I'm wondering why we want to 
add the feature as an extension when WG21 explicitly rejected it (that doesn't 
seem in line with our extension policy: 
https://clang.llvm.org/get_involved.html#criteria).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

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


[clang] f9e8e92 - Revert "[clang][analyzer] Add modeling of 'errno'."

2022-02-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-02-25T07:21:01-05:00
New Revision: f9e8e92cf586d9cf077139a338f062a91b8ce2d2

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

LOG: Revert "[clang][analyzer] Add modeling of 'errno'."

This reverts commit 29b512ba322cb6dd2c45d5e07645e20db47fad0d.

This broke several build bots:

https://lab.llvm.org/buildbot/#/builders/86/builds/30183
https://lab.llvm.org/buildbot/#/builders/216/builds/488

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/global-region-invalidation.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Removed: 
clang/lib/StaticAnalyzer/Checkers/Errno.h
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
clang/test/Analysis/Inputs/errno_func.h
clang/test/Analysis/Inputs/errno_var.h
clang/test/Analysis/errno.c



diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 6b72d64950106..fae4240e9d701 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -348,10 +348,6 @@ def NullableReturnedFromNonnullChecker : 
Checker<"NullableReturnedFromNonnull">,
 
 let ParentPackage = APIModeling in {
 
-def ErrnoModeling : Checker<"Errno">,
-  HelpText<"Make the special value 'errno' available to other checkers.">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   // Uninitialized value check is a mandatory dependency. This Checker asserts
@@ -1560,11 +1556,6 @@ def StreamTesterChecker : Checker<"StreamTester">,
"purposes.">,
   Documentation;
 
-def ErrnoTesterChecker : Checker<"ErrnoTest">,
-  HelpText<"Check modeling aspects of 'errno'.">,
-  Dependencies<[ErrnoModeling]>,
-  Documentation;
-
 def ExprInspectionChecker : Checker<"ExprInspection">,
   HelpText<"Check the analyzer's understanding of expressions">,
   Documentation;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index 0db6d92c63131..9f85347db5df7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -764,8 +764,7 @@ class SymbolicRegion : public SubRegion {
 assert(s->getType()->isAnyPointerType() ||
s->getType()->isReferenceType() ||
s->getType()->isBlockPointerType());
-assert(isa(sreg) || isa(sreg) ||
-   isa(sreg));
+assert(isa(sreg) || isa(sreg));
   }
 
 public:
@@ -1376,9 +1375,7 @@ class MemRegionManager {
 const LocationContext *LC);
 
   /// Retrieve or create a "symbolic" memory region.
-  /// If no memory space is specified, `UnknownSpaceRegion` will be used.
-  const SymbolicRegion *
-  getSymbolicRegion(SymbolRef Sym, const MemSpaceRegion *MemSpace = nullptr);
+  const SymbolicRegion* getSymbolicRegion(SymbolRef Sym);
 
   /// Return a unique symbolic region belonging to heap memory space.
   const SymbolicRegion *getSymbolicHeapRegion(SymbolRef sym);

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 15043c1c632e4..44fa2a06c3994 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -40,8 +40,6 @@ add_clang_library(clangStaticAnalyzerCheckers
   DynamicTypePropagation.cpp
   DynamicTypeChecker.cpp
   EnumCastOutOfRangeChecker.cpp
-  ErrnoModeling.cpp
-  ErrnoTesterChecker.cpp
   ExprInspectionChecker.cpp
   FixedAddressChecker.cpp
   FuchsiaHandleChecker.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/Errno.h 
b/clang/lib/StaticAnalyzer/Checkers/Errno.h
deleted file mode 100644
index e564809d6bda9..0
--- a/clang/lib/StaticAnalyzer/Checkers/Errno.h
+++ /dev/null
@@ -1,39 +0,0 @@
-//=== Errno.h - Tracking value of 'errno'. -*- C++ 
-*-//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===---

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Hello! I had to revert in f9e8e92cf586d9cf077139a338f062a91b8ce2d2 
 because 
this broke all of the builds on Windows. Here are some sample failures:

https://lab.llvm.org/buildbot/#/builders/86/builds/30183
https://lab.llvm.org/buildbot/#/builders/216/builds/488


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[PATCH] D120498: [AST] Test RecursiveASTVisitor's current traversal of templates.

2022-02-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:12
+//
+// shouldVisitTemplateInstantiations() controls traversal of AST nodes that
+// were created by instantiation, rather than by written code. This means:

hokein wrote:
> I think this is a very useful documentation about the RAV API, instead of 
> staying in the test file, I would suggest moving it to the RAV.h file.
Good idea. I suppose it belongs on shouldVisitTemplateInstantiations().



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:18
+//   - Explicit instantiations are a tricky case:
+// - the "declaration part" (template args, function params etc) was 
written
+//   and should always be traversed.

hokein wrote:
> Conceptually, an instantiations create a specific {Class, 
> Var}TemplateSpecializationDecl, functionDecl.
> 
> ```
> template  void foo(T) { }
> template void foo(); // Line 2
> ```
> 
> For the statement on line 2 (called `explicit instantiation definition` I 
> think)
> - there is no corresponding node in the clang AST, this is a missing feature 
> in clang
> - it creates a FunctionDecl, that is `void foo(char) { }`,
> 
> does the "declaration part" in the comment refer to the declaration part of 
> the `explicit instantiation definition` (I think so), or the declaration part 
> of the FunctionDecl `void foo(char) {}`? The same question to the definition, 
> my understanding from the comment is the function body of the `void foo(char) 
> {}`, which is `{}`.
> 
> We describe the expected behavior, but there are some bugs or unimplemented 
> features in clang, which creates discrepancies. I think this is confusing and 
> hard to follow, not sure how to do here (encoding a bunch of FIXMEs here is 
> not good,  not mentioning them at all is not good neither, can we mention 
> only critical ones?)
> 
> 
> 
> 
> Conceptually, an instantiations create a specific {Class, 
> Var}TemplateSpecializationDecl, functionDecl.
> 
> ```
> template  void foo(T) { }
> template void foo(); // Line 2
> ```
> 
> For the statement on line 2 (called `explicit instantiation definition` I 
> think)
> - there is no corresponding node in the clang AST, this is a missing feature 
> in clang
> - it creates a FunctionDecl, that is `void foo(char) { }`,

This is a plausible explanation (for functions and variables, but not classes). 
I don't think it's the best model - I'd prefer to say that the instantiated 
decl *corresponds* to the explicit instantiation definition.

In this example there are three decls: the template, the templated decl, and 
the instantiation.
For functions these are {FunctionTemplateDecl, FunctionDecl, FunctionDecl}.
For variables these are {VarTemplateDecl, VarDecl, 
VarTemplateSpecializationDecl}
For classes these are {ClassTemplateDecl, CXXRecordDecl, 
ClassTemplateSpecializationDecl}.
(Sometimes in -dump-ast they appear multiple times, but there are only 3 
distinct pointers).

There are inconsistencies here:
 - function specializations don't have a distinct node type. I'm not sure this 
is terribly significant. (I suspect it's related to the fact they can't be 
partially specialized).
 - class specializations have locations that point to the explicit 
instantiation where possible (primary location, template parameter locations 
etc), and the template body otherwise. Variable and function specializations 
point at the template always.
 - in `-dump-ast` output it's inconsistent whether specializations are shown at 
the top level, under the template, or both. But I don't think there's any 
significant meaning behind this.

The second inconsistency (locations) is the closest to answering the question 
"do they correspond"?
Possible answers:
 - specializations should correspond to the explicit instantiations, so 
function + var are deficient in not reporting the locations
 - specializations should not correspond, and class specializations are buggy 
in reporting explicit instantiation locations
 - class specializations should correspond to the explicit instantiations, but 
others not (this seems silly)

I think #1 is the most plausible here, especially given that the 
specializations do know (getTemplateSpecializationKind()) if they were produced 
from an explicit instantiation.


> does the "declaration part" in the comment refer to the declaration part of 
> the `explicit instantiation definition` (I think so), or the declaration part 
> of the FunctionDecl `void foo(char) {}`? The same question to the definition, 
> my understanding from the comment is the function body of the `void foo(char) 
> {}`, which is `{}`.

This comment is talking about attributing AST nodes to source code, so it's 
talking about the FunctionDecl. By "declaration part" I mean the 
FunctionTypeLoc etc. I'll clarify this.

> We describe the expected behavior, but there are some bugs or unimplemented 
> fea

[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-02-25 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 411379.
achieveartificialintelligence added a comment.

Ping & Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  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-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/riscv32-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksh.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/riscv64-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksh.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c

Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -31,6 +31,17 @@
 // CHECK-NOT: __riscv_zfh
 // CHECK-NOT: __riscv_v
 // CHECK-NOT: __riscv_vector
+// CHECK-NOT: __riscv_zbkc
+// CHECK-NOT: __riscv_zbkx
+// CHECK-NOT: __riscv_zbkb
+// CHECK-NOT: __riscv_zkne
+// CHECK-NOT: __riscv_zknd
+// CHECK-NOT: __riscv_zknh
+// CHECK-NOT: __riscv_zksh
+// CHECK-NOT: __riscv_zksed
+// CHECK-NOT: __riscv_zkr
+// CHECK-NOT: __riscv_zkt
+// CHECK-NOT: __riscv_zk
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -343,3 +354,58 @@
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkc1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKC-EXT %s
+// CHECK-ZBKC-EXT: __riscv_zbkc
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkx1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKX-EXT %s
+// CHECK-ZBKX-EXT: __riscv_zbkx
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkb1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKB-EXT %s
+// CHECK-ZBKB-EXT: __riscv_zbkb
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknd1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKND-EXT %s
+// CHECK-ZKND-EXT: __riscv_zknd
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkne1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNE-EXT %s
+// CHECK-ZKNE-EXT: __riscv_zkne
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNH-EXT %s
+// CHECK-ZKNH-EXT: __riscv_zknh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSH-EXT %s
+// CHECK-ZKSH-EXT: __riscv_zksh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksed1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSED-EXT %s
+// CHECK-ZKSED-EXT: __riscv_zksed
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkr1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKR-EXT %s
+// CHECK-ZKR-EXT: __riscv_zkr
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkt1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKT-EXT %s
+// CHECK-ZKT-EXT: __riscv_zkt
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izk1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZK-EXT %s
+// CHECK-ZK-EXT: __riscv_zk
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -414,3 +414,47 @@
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv1p0_zvl32b1p0 -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-ZVL-GOODVERS %s
 // RV32-ZVL-GOODVERS: "-target-feature" "+zvl32b"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbkc1p0 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBKC %s
+// RV32-ZBKC: "

[PATCH] D120504: [AST] RAV doesn't traverse explicitly instantiated function bodies by default

2022-02-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2107
 
-  if (CXXConstructorDecl *Ctor = dyn_cast(D)) {
-// Constructor initializers.

hokein wrote:
> moving this part of code to `if (VisitBody)` seems like a different fix (and 
> I think it is reasonable, from the grammar, the ctor-initializer is part of 
> the function-body), can we separate it and add a test? 
I can do it as a separate patch before if you like, but it's NFC.

Behavior only differs if there is an init list and VisitBody is false.
However !VisitBody requires one of:
 - this is a declaration only => no init list
 - this is a defaulted function => no init list



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp:168
 extern template int foo<3>();
 // Explicit instantiation. Head traversed, body only with instantiations 
on.
 template int foo<4>();

hokein wrote:
> What does the Head mean? 
Within the function 

int foo<4>() { return 0; }.

I've called `int foo<4>()` the "head" and `{return 0;}` the "body".
The distinction is that the head was written, and the body was instantiated.

are there better terms? (I'd probably like this "head" better than "declaration 
part" so maybe we should just define these terms in the 
shouldVisitTemplateInstantiations() comment)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120504

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


[PATCH] D119816: [SanitizerBounds] Add support for NoSanitizeBounds function

2022-02-25 Thread Marco Elver via Phabricator via cfe-commits
melver requested changes to this revision.
melver added a comment.
This revision now requires changes to proceed.

Looks good. Few minor changes.

I did some more digging, and it's only fsanitize=local-bounds, so please verify 
this and also update the commit description. In fact, the Linux kernel already 
has a comment about Clang's weirdness of local-bounds vs. array-bounds here: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/Kconfig.ubsan#n62


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119816

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


[PATCH] D119816: [SanitizerBounds] Add support for NoSanitizeBounds function

2022-02-25 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:757
 SanOpts.set(SanitizerKind::HWAddress, false);
+  if (mask & SanitizerKind::LocalBounds)
+Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds);

These 2 checks can be reduced to 1 due to SanitizerKind::Bounds including both. 
However, as noted, this only affects local-bounds, so I'm not sure if we want 
to include both -- perhaps for completeness it makes sense, but in the 
array-bounds only case this attribute will be a nop (AFAIK).

Also, I think we don't want to attach the attribute if bounds checking isn't 
enabled -- at least it seems unnecessary to do so.

See the following suggested change:

```
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 842ce0245d45..c1f3a3014a19 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -740,6 +740,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
   } while (false);
 
   if (D) {
+const bool SanitizeBounds = SanOpts.hasOneOf(SanitizerKind::Bounds);
 bool NoSanitizeCoverage = false;
 
 for (auto Attr : D->specific_attrs()) {
@@ -754,16 +755,15 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 SanOpts.set(SanitizerKind::KernelHWAddress, false);
   if (mask & SanitizerKind::KernelHWAddress)
 SanOpts.set(SanitizerKind::HWAddress, false);
-  if (mask & SanitizerKind::LocalBounds)
-Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds);
-  if (mask & SanitizerKind::ArrayBounds)
-Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds);
 
   // SanitizeCoverage is not handled by SanOpts.
   if (Attr->hasCoverage())
 NoSanitizeCoverage = true;
 }
 
+if (SanitizeBounds && !SanOpts.hasOneOf(SanitizerKind::Bounds))
+  Fn->addFnAttr(llvm::Attribute::NoSanitizeBounds);
+
 if (NoSanitizeCoverage && CGM.getCodeGenOpts().hasSanitizeCoverage())
   Fn->addFnAttr(llvm::Attribute::NoSanitizeCoverage);
   }

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119816

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


[PATCH] D119061: [Clang] noinline call site attribute

2022-02-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 411383.
xbolva00 added a comment.
Herald added a subscriber: jdoerfert.

Fixed tests.

Addressed review feedback.


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

https://reviews.llvm.org/D119061

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-noinline.cpp
  clang/test/Parser/stmt-attributes.c
  clang/test/Sema/attr-noinline.c
  clang/test/Sema/attr-noinline.cpp

Index: clang/test/Sema/attr-noinline.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-noinline.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+int bar();
+
+[[gnu::always_inline]] void always_inline_fn(void) { }
+[[gnu::flatten]] void flatten_fn(void) { }
+
+[[gnu::noinline]] void noinline_fn(void) { }
+
+void foo() {
+  [[clang::noinline]] bar();
+  [[clang::noinline(0)]] bar(); // expected-error {{'noinline' attribute takes no arguments}}
+  int x;
+  [[clang::noinline]] x = 0; // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::noinline]] { asm("nop"); } // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::noinline]] label: x = 1; // expected-error {{'noinline' attribute only applies to functions and statements}}
+
+
+  [[clang::noinline]] always_inline_fn(); // expected-warning {{statement attribute 'noinline' has higher precedence than function attribute 'always_inline'}}
+  [[clang::noinline]] flatten_fn(); // expected-warning {{statement attribute 'noinline' has higher precedence than function attribute 'flatten'}}
+  [[clang::noinline]] noinline_fn();
+
+  [[gnu::noinline]] bar(); // expected-warning {{'noinline' attribute is ignored in statements as it only applies to functions}}
+}
+
+[[clang::noinline]] static int i = bar(); // expected-error {{'noinline' attribute only applies to functions and statements}}
Index: clang/test/Sema/attr-noinline.c
===
--- clang/test/Sema/attr-noinline.c
+++ clang/test/Sema/attr-noinline.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
 
-int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to functions}}
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to functions and statements}}
 
 void t1(void) __attribute__((noinline));
 
Index: clang/test/Parser/stmt-attributes.c
===
--- clang/test/Parser/stmt-attributes.c
+++ clang/test/Parser/stmt-attributes.c
@@ -45,7 +45,7 @@
   }
 
   __attribute__((fastcall)) goto there; // expected-error {{'fastcall' attribute cannot be applied to a statement}}
-  __attribute__((noinline)) there : // expected-warning {{'noinline' attribute only applies to functions}}
+  __attribute__((noinline)) there : // expected-warning {{'noinline' attribute only applies to functions and statements}}
 
 __attribute__((weakref)) return; // expected-error {{'weakref' attribute only applies to variables and functions}}
 
Index: clang/test/CodeGen/attr-noinline.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-noinline.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+
+bool bar();
+void f(bool, bool);
+void g(bool);
+
+static int baz(int x) {
+return x * 10;
+}
+
+[[clang::noinline]] bool noi() { }
+
+void foo(int i) {
+  [[clang::noinline]] bar();
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]]
+  [[clang::noinline]] i = baz(i);
+// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]]
+  [[clang::noinline]] (i = 4, bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[clang::noinline]] (void)(bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[clang::noinline]] f(bar(), bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]]
+  [[clang::noinline]] [] { bar(); bar(); }(); // noinline only applies to the anonymous function call
+// CHECK: call void @"_ZZ3fooiENK3$_0clEv"(%class.anon* {{[^,]*}} %ref.tmp) #[[NOINLINEATTR]]
+  [[clang::noinline]] for (bar(); bar(); bar()) {}
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  bar

[PATCH] D119061: [Clang] noinline call site attribute

2022-02-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1764
+def NoInline : DeclOrStmtAttr {
+  let Spellings = [Clang<"noinline">, Declspec<"noinline">];
+  let Documentation = [NoInlineDocs];

aaron.ballman wrote:
> xbolva00 wrote:
> > What I need to mention here. With Clang<"noinline">, we lost support for 
> > [[gnu::noinline]] syntax, now unrecognized. Maybe it is ok, as we have now 
> > more powerful attribute?
> > 
> > 
> Nope, we need to retain at least part of `GCC<"noinline">` because people may 
> be relying on `[[gnu::noinline]]`. The GNU version should be disallowed as a 
> statement attribute unless GCC gets the same functionality. I suspect using 
> the `GCC` spelling may cause issues (because GCC spelling implies a GNU 
> attribute as does the Clang spelling). So you may need to use `CXX11<"gnu", 
> "noinline">` and `C2x<"gnu", "noinline">` to retain those spellings.
> 
> Btw, you can use an `Accessors` field here to give the semantic attribute the 
> ability to differentiate between the GCC and the Clang spellings. The GNU 
> spelling is a bit of a question mark; I think it's fine to allow it as a 
> statement attribute, but we might want to warn that the use is not compatible 
> with GCC.
> 
> You'll have to update the documentation to describe what's supported where 
> and under which spelling.
Thanks for advices, Accessors is really useful here. Added warning and updated 
doc a bit.


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

https://reviews.llvm.org/D119061

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


[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity created this revision.
whisperity added reviewers: aaron.ballman, steakhal.
whisperity added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, martong, gamesh411, Szelethus, dkrupp, 
rnkovacs, xazax.hun.
whisperity requested review of this revision.
Herald added a subscriber: cfe-commits.

As originally reported by @steakhal in #54074 
, the name extraction logic 
in `readability-suspicious-call-argument` crashes if the argument passed to a 
function was a function call to a non-trivially named entity (e.g. an operator).

Fixed this crash case by ignoring such constructs and considering them as 
having no name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120555

Files:
  clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 
'a') looks like it might be swapped with the 2nd, 'a' (passed to 
'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', 
declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -711,23 +711,28 @@
 
   for (std::size_t I = InitialArgIndex, J = MatchedCallExpr->getNumArgs();
I < J; ++I) {
+assert(ArgTypes.size() == I - InitialArgIndex &&
+   ArgNames.size() == ArgTypes.size() &&
+   "Every iteration must put an element into the vectors!");
+
 if (const auto *ArgExpr = dyn_cast(
 MatchedCallExpr->getArg(I)->IgnoreUnlessSpelledInSource())) {
   if (const auto *Var = dyn_cast(ArgExpr->getDecl())) {
 ArgTypes.push_back(Var->getType());
 ArgNames.push_back(Var->getName());
-  } else if (const auto *FCall =
- dyn_cast(ArgExpr->getDecl())) {
-ArgTypes.push_back(FCall->getType());
-ArgNames.push_back(FCall->getName());
-  } else {
-ArgTypes.push_back(QualType());
-ArgNames.push_back(StringRef());
+continue;
+  }
+  if (const auto *FCall = dyn_cast(ArgExpr->getDecl())) {
+if (FCall->getNameInfo().getName().isIdentifier()) {
+  ArgTypes.push_back(FCall->getType());
+  ArgNames.push_back(FCall->getName());
+  continue;
+}
   }
-} else {
-  ArgTypes.push_back(QualType());
-  ArgNames.push_back(StringRef());
 }
+
+ArgTypes.push_back(QualType());
+ArgNames.push_back(StringRef());
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 'a') looks like it might be swapped with the 2nd, 'a' (passed to 'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck

[PATCH] D120557: [HIP] File device library ABI version file name

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kerbowa, jvesely.
yaxunl requested review of this revision.

It should be oclc_abi_version* instead of abi_version*.


https://reviews.llvm.org/D120557

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_400.bc
  clang/test/Driver/Inputs/rocm/amdgcn/bitcode/abi_version_500.bc
  clang/test/Driver/hip-device-libs.hip


Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -217,10 +217,10 @@
 // DIVSQRT-SAME: "-mlink-builtin-bitcode" 
"{{.*}}oclc_correctly_rounded_sqrt_off.bc"
 
 // ABI4-NOT: error:
-// ABI4: "-mlink-builtin-bitcode" "{{.*}}abi_version_400.bc"
+// ABI4: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_400.bc"
 // ABI5-NOT: error:
-// ABI5: "-mlink-builtin-bitcode" "{{.*}}abi_version_500.bc"
+// ABI5: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_500.bc"
 // NOABI4-NOT: error:
-// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}abi_version_400.bc"
-// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}abi_version_500.bc"
+// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_400.bc"
+// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_500.bc"
 // NOABI5: error: cannot find ROCm device libraryfor ABI version 5; provide 
its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to 
build without ROCm device library
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -91,7 +91,7 @@
 else if (FileName.endswith(Suffix))
   BaseName = FileName.drop_back(Suffix.size());
 
-const StringRef ABIVersionPrefix = "abi_version_";
+const StringRef ABIVersionPrefix = "oclc_abi_version_";
 if (BaseName == "ocml") {
   OCML = FilePath;
 } else if (BaseName == "ockl") {


Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -217,10 +217,10 @@
 // DIVSQRT-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_correctly_rounded_sqrt_off.bc"
 
 // ABI4-NOT: error:
-// ABI4: "-mlink-builtin-bitcode" "{{.*}}abi_version_400.bc"
+// ABI4: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_400.bc"
 // ABI5-NOT: error:
-// ABI5: "-mlink-builtin-bitcode" "{{.*}}abi_version_500.bc"
+// ABI5: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_500.bc"
 // NOABI4-NOT: error:
-// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}abi_version_400.bc"
-// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}abi_version_500.bc"
+// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_400.bc"
+// NOABI4-NOT: "-mlink-builtin-bitcode" "{{.*}}oclc_abi_version_500.bc"
 // NOABI5: error: cannot find ROCm device libraryfor ABI version 5; provide its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build without ROCm device library
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -91,7 +91,7 @@
 else if (FileName.endswith(Suffix))
   BaseName = FileName.drop_back(Suffix.size());
 
-const StringRef ABIVersionPrefix = "abi_version_";
+const StringRef ABIVersionPrefix = "oclc_abi_version_";
 if (BaseName == "ocml") {
   OCML = FilePath;
 } else if (BaseName == "ockl") {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120366: [CUDA][SPIRV] Assign global address space to CUDA kernel arguments

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D120366#3344428 , @shangwuyao 
wrote:

> @yaxunl I saw that you added the test recently, could you provide some 
> context? I think this test is broken at HEAD as I saw it is broken for other 
> patches (see this build 
> ) as well.

which test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120366

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


[PATCH] D120366: [CUDA][SPIRV] Assign global address space to CUDA kernel arguments

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D120366#3345401 , @yaxunl wrote:

> In D120366#3344428 , @shangwuyao 
> wrote:
>
>> @yaxunl I saw that you added the test recently, could you provide some 
>> context? I think this test is broken at HEAD as I saw it is broken for other 
>> patches (see this build 
>> ) as well.
>
> which test?

OK. I saw it. Thanks for handling it. I will fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120366

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


[PATCH] D120529: Disable broken hip test on Windows

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Sorry I missed this failure. Thanks for disabling it.

I will come up with a fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120529

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


[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D120563: [HIP] Fix test hip-link-bundled-archive.hip

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, shangwuyao.
yaxunl requested review of this revision.

match pattern should match lld.exe on windows


https://reviews.llvm.org/D120563

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


Index: clang/test/Driver/hip-link-bundle-archive.hip
===
--- clang/test/Driver/hip-link-bundle-archive.hip
+++ clang/test/Driver/hip-link-bundle-archive.hip
@@ -9,6 +9,6 @@
 // RUN:   2>&1 | FileCheck -check-prefix=CHECK %s
 
 // CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" 
"-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" 
"-outputs=[[A1030:.*\.a]]" "-allow-missing-bundles"
-// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
+// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
 // CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" 
"-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" 
"-outputs=[[A906:.*\.a]]" "-allow-missing-bundles"
-// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
+// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"


Index: clang/test/Driver/hip-link-bundle-archive.hip
===
--- clang/test/Driver/hip-link-bundle-archive.hip
+++ clang/test/Driver/hip-link-bundle-archive.hip
@@ -9,6 +9,6 @@
 // RUN:   2>&1 | FileCheck -check-prefix=CHECK %s
 
 // CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-outputs=[[A1030:.*\.a]]" "-allow-missing-bundles"
-// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
+// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
 // CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-outputs=[[A906:.*\.a]]" "-allow-missing-bundles"
-// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
+// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120529: Disable broken hip test on Windows

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

https://reviews.llvm.org/D120563


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120529

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


[clang-tools-extra] 27d39e4 - Use function prototypes when appropriate; NFC

2022-02-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-02-25T09:08:27-05:00
New Revision: 27d39e4da0b45a93a16f932be66a3607cba1d116

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

LOG: Use function prototypes when appropriate; NFC

This prepares the clang-tools-extra project for -Wstrict-prototypes
being enabled by default.

Added: 


Modified: 
clang-tools-extra/test/clang-reorder-fields/PlainCStructFieldsOrder.c

clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c

clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry.c
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.m

clang-tools-extra/test/clang-tidy/checkers/bugprone-branch-clone-macro-crash.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-relatedness.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-memcpy-safe-other.c
clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-c.c
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-spuriously-wake-up-functions.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-string-compare.c
clang-tools-extra/test/clang-tidy/checkers/cert-err33-c.c
clang-tools-extra/test/clang-tidy/checkers/cert-limited-randomness.c
clang-tools-extra/test/clang-tidy/checkers/cert-msc32-c.c
clang-tools-extra/test/clang-tidy/checkers/google-runtime-int.c
clang-tools-extra/test/clang-tidy/checkers/linuxkernel-must-check-errs.c
clang-tools-extra/test/clang-tidy/checkers/misc-static-assert.c
clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.c
clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.c
clang-tools-extra/test/clang-tidy/checkers/objc-assert-equals.m

clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m
clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-isolate-declaration.c

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.c

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-reorder-fields/PlainCStructFieldsOrder.c 
b/clang-tools-extra/test/clang-reorder-fields/PlainCStructFieldsOrder.c
index 5b4fe9e654e49..32ce569df943f 100644
--- a/clang-tools-extra/test/clang-reorder-fields/PlainCStructFieldsOrder.c
+++ b/clang-tools-extra/test/clang-reorder-fields/PlainCStructFieldsOrder.c
@@ -7,7 +7,7 @@ struct Foo {
   int w;// CHECK-NEXT: {{^  const int\* x}}
 };
 
-int main() {
+int main(void) {
   const int x = 13;
   struct Foo foo = { &x, 0, 1.29, 17 }; // CHECK: {{^  struct Foo foo = { 
1.29, 17, 0, &x };}} 
   return 0;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
 
b/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
index dde03ddabbcb0..5acfcafcead36 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
@@ -18,10 +18,10 @@
 __z;   \
   })
 
-int foo();
+int foo(void);
 int bar(int a);
 
-void with_custom_macro() {
+void with_custom_macro(void) {
   MY_TEMP_FAILURE_RETRY(foo());
   MY_TEMP_FAILURE_RETRY(foo() == 1);
   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: top-level comparison in 
MY_TEMP_FAILURE_RETRY
@@ -33,7 +33,7 @@ void with_custom_macro() {
   // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: top-level comparison in 
MY_TEMP_FAILURE_RETRY
 }
 
-void with_other_custom_macro() {
+void with_other_custom_macro(void) {
   MY_OTHER_TEMP_FAILURE_RETRY(foo());
   MY_OTHER_TEMP_FAILURE_RETRY(foo() == 1);
   // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: top-level comparison in 
MY_OTHER_TEMP_FAILURE_RETRY

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry.c
 
b/clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry.c
index 3be3eecce1cb4..461fb4ad52542 100644
--- 
a/clang-tools-extra/test/clang-tidy/ch

[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 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, please add a release note for the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411398.
balazske added a comment.

Rename of "Errno.h", maybe fixes Windows build problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,58 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_getErrno();
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno() == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ErrnoTesterChecker_getErrno()); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/analyzer-enabled-checkers.c
=

[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 411400.
sgatev marked 5 inline comments as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

Files:
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -0,0 +1,274 @@
+//===- unittests/Analysis/FlowSensitive/SolverTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/Solver.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+class SolverTest : public ::testing::Test {
+protected:
+  // Checks if the conjunction of `Vals` is satisfiable and returns the
+  // corresponding result.
+  Solver::Result solve(llvm::DenseSet Vals) {
+return WatchedLiteralsSolver().solve(std::move(Vals));
+  }
+
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
+TEST_F(SolverTest, Var) {
+  auto X = atom();
+
+  // X
+  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, NegatedVar) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // !X
+  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, UnitConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // X ^ !X
+  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DistinctVars) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotY = neg(Y);
+
+  // X ^ !Y
+  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, DoubleNegation) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto NotNotX = neg(NotX);
+
+  // !!X ^ !X
+  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedDisjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XOrY = disj(X, Y);
+  auto NotXOrY = neg(XOrY);
+
+  // !(X v Y) ^ (X v Y)
+  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedConjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XAndY = conj(X, Y);
+  auto NotXAndY = neg(XAndY);
+
+  // !(X ^ Y) ^ (X ^ Y)
+  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DisjunctionSameVars) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XOrNotX = disj(X, NotX);
+
+  // X v !X
+  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, ConjunctionSameVarsConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XAndNotX = conj(X, NotX);
+
+  // X ^ !X
+  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, PureVar) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotX = neg(X);
+  auto NotXOrY = disj(NotX, Y);
+  auto NotY = neg(Y);
+  auto NotXOrNotY = disj(NotX, NotY);
+
+  // (!X v Y) ^ (!X v !Y)
+  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+}
+
+TEST_F(Solver

[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added a comment.

> Are there plans to get a model/assignment of the variables from the solver? 
> That could be helpful for generating warning messages in the future :)

Absolutely! That was only discussed briefly so far. One challenge would be 
distilling this model to present only relevant information to the user. That 
could also be best effort, of course. It's certainly something I think we 
should provide at some point.




Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:159
+  /// Adds the 3-literal `L1 v L2 v L3` clause to the formula.
+  void addClause(Literal L1, Literal L2, Literal L3) {
+// The literals are guaranteed to be distinct from properties of BoolValue

xazax.hun wrote:
> Shouldn't we make this function variadic (or taking a container) instead of 
> having multiple overloads?
I'd like to avoid containers here to minimize allocations. I'd love to use a 
fold expression, but that's C++ 17. I opted for setting default values for the 
last two arguments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:213
+// Visit the sub-values of `Val`.
+if (auto *C = dyn_cast(Val)) {
+  UnprocessedSubVals.push(&C->getLeftSubValue());

xazax.hun wrote:
> Switch on the kind instead? That way `DisjunctionValue` and 
> `ConjunctionValue` could be handled by the same case.
Unfortunately, I don't think we can handle them in the same case because they 
don't share a parent that represents a binary operation. Perhaps an improvement 
worth considering, as we discussed in one of the previous patches.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:241
+  for (BoolValue *Val : Vals)
+UnprocessedSubVals.push(Val);
+  while (!UnprocessedSubVals.empty()) {

xazax.hun wrote:
> While I get that this should be empty before this loop due to the loop 
> condition at the previous use, but I find such code confusing. I'd prefer to 
> either use a separate queue or have at least an assert to remind us that this 
> one should be a clean container before the loop.
I agree that this would be an improvement. I opted for narrowing the scope of 
the first container and adding a second container for this operation.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:355
+
+LevelVars.resize(Formula.LargestVar + 1);
+

xazax.hun wrote:
> Shouldn't we call the right ctor directly in the initialization list instead 
> of resizing a default constructed vector?
Makes complete sense. Updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

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


[PATCH] D120132: [HIP] Fix HIP include path

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl planned changes to this revision.
yaxunl added a comment.

I just found one issue with the current patch. It adds HIP include path for 
non-HIP programs.

We should only add HIP include path for JobAction with HIP offloading kind. 
However, AddClangSystemIncludeArgs is not per job action.

I feel I should not complicate AddClangSystemIncludeArgs API by making it 
accept a JobAction argument. Then I should add HIP include path in 
Clang::AddPreprocessingOptions instead of AddClangSystemIncludeArgs. Then I 
have to add ToolChain::AddPostSystemHIPIncludeArgs since not all ToolChain have 
RocmInstallation.

Basically this will end up as ToolChain having two APIs: one for adding HIP 
wrapper include args, one for adding HIP include args.


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

https://reviews.llvm.org/D120132

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


[PATCH] D120566: [OpenCL][AMDGPU]: Do not allow a call to kernel

2022-02-25 Thread Christudasan Devadasan via Phabricator via cfe-commits
cdevadas created this revision.
cdevadas added reviewers: rjmccall, Anastasia, yaxunl, arsenm.
Herald added subscribers: Naghasan, ldrumm, kerbowa, t-tye, tpr, dstuttard, 
jvesely, kzhuravl.
cdevadas requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

In OpenCL, a kernel is allowed to call other kernels as if
they are regular functions. To support it, clang emits
amdgpu_kernel calling convention for both caller and callee.
A backend pass in our downstream compiler alters such calls
by introducing regular function bodies which are clones of
the callee kernels. This implementation currently limits us
in certain ways. For instance, the restriction to not use
byref attribute for callee kernels.

To avoid such limitations, this patch brings in those
cloned functions early on and prevents clang from generating
amdgpu_kernel call sites. A new function body will be added
for each kernel in the compilation unit expecting that the
unused clones will get removed at link time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120566

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGenOpenCL/amdgpu-kernel-calls.cl
  clang/test/CodeGenOpenCL/visibility.cl

Index: clang/test/CodeGenOpenCL/visibility.cl
===
--- clang/test/CodeGenOpenCL/visibility.cl
+++ clang/test/CodeGenOpenCL/visibility.cl
@@ -94,23 +94,6 @@
 ext_func_default();
 }
 
-// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern()
-// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern()
-// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern()
-
-// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_hidden()
-// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_hidden()
-// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_hidden()
-
-// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_protected()
-// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_protected()
-// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_protected()
-
-// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern_default()
-// FVIS-PROTECTED: declare amdgpu_kernel void @ext_kern_default()
-// FVIS-HIDDEN: declare amdgpu_kernel void @ext_kern_default()
-
-
 // FVIS-DEFAULT: declare void @ext_func()
 // FVIS-PROTECTED: declare protected void @ext_func()
 // FVIS-HIDDEN: declare hidden void @ext_func()
@@ -126,3 +109,21 @@
 // FVIS-DEFAULT: declare void @ext_func_default()
 // FVIS-PROTECTED: declare void @ext_func_default()
 // FVIS-HIDDEN: declare void @ext_func_default()
+
+// A kernel call will be emitted as a call to its cloned function
+// of non-kernel convention.
+// FVIS-DEFAULT: declare void @__amdgpu_ext_kern_kernel_body()
+// FVIS-PROTECTED: declare void @__amdgpu_ext_kern_kernel_body()
+// FVIS-HIDDEN: declare void @__amdgpu_ext_kern_kernel_body()
+
+// FVIS-DEFAULT: declare void @__amdgpu_ext_kern_hidden_kernel_body()
+// FVIS-PROTECTED: declare void @__amdgpu_ext_kern_hidden_kernel_body()
+// FVIS-HIDDEN: declare void @__amdgpu_ext_kern_hidden_kernel_body()
+
+// FVIS-DEFAULT: declare void @__amdgpu_ext_kern_protected_kernel_body()
+// FVIS-PROTECTED: declare void @__amdgpu_ext_kern_protected_kernel_body()
+// FVIS-HIDDEN: declare void @__amdgpu_ext_kern_protected_kernel_body()
+
+// FVIS-DEFAULT: declare void @__amdgpu_ext_kern_default_kernel_body()
+// FVIS-PROTECTED: declare void @__amdgpu_ext_kern_default_kernel_body()
+// FVIS-HIDDEN: declare void @__amdgpu_ext_kern_default_kernel_body()
Index: clang/test/CodeGenOpenCL/amdgpu-kernel-calls.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/amdgpu-kernel-calls.cl
@@ -0,0 +1,60 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -S -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+// AMDGPU disallows kernel callsites from another kernels. For each kernel, clang codegen will introduce
+// a cloned function body with a non-kernel calling convention and amdgpu_kernel callsites will get
+// transformed to call appropriate clones.
+
+extern kernel void test_extern_kernel_callee(global int *in);
+
+// CHECK: define dso_local amdgpu_kernel void @test_kernel_callee(i32 addrspace(1)* noundef align 4 %in)
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca i32 addrspace(1)*, align 8, addrspace(5)
+// CHECK-NEXT:store i32 addrspace(1)* [[IN:%.*]], i32 addrspace(1)* addrspace(5)* [[IN_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(5)* [[IN_ADDR]], align 8
+// CHECK-NEXT:store i32 10, i32 addrspace(1)* [[TMP0]], align 4
+// CHECK-NEXT:ret void
+//
+kernel void test_kernel_callee(global int *in) {
+  *in = (int)(10);
+}
+
+// CHECK: define dso_lo

[clang] 53dcd9e - [clang][dataflow] Add SAT solver interface and implementation

2022-02-25 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-02-25T14:46:52Z
New Revision: 53dcd9efd16fc881b01470767ac17c4b221f3e08

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

LOG: [clang][dataflow] Add SAT solver interface and implementation

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: ymandel, xazax.hun

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

Added: 
clang/include/clang/Analysis/FlowSensitive/Solver.h
clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Modified: 
clang/lib/Analysis/FlowSensitive/CMakeLists.txt
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/Solver.h 
b/clang/include/clang/Analysis/FlowSensitive/Solver.h
new file mode 100644
index 0..6b685b9b3c9a7
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/Solver.h
@@ -0,0 +1,56 @@
+//===- Solver.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines an interface for a SAT solver that can be used by
+//  dataflow analyses.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H
+
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/ADT/DenseSet.h"
+
+namespace clang {
+namespace dataflow {
+
+/// An interface for a SAT solver that can be used by dataflow analyses.
+class Solver {
+public:
+  enum class Result {
+/// Indicates that there exists a satisfying assignment for a boolean
+/// formula.
+Satisfiable,
+
+/// Indicates that there is no satisfying assignment for a boolean formula.
+Unsatisfiable,
+
+/// Indicates that the solver gave up trying to find a satisfying 
assignment
+/// for a boolean formula.
+TimedOut,
+  };
+
+  virtual ~Solver() = default;
+
+  /// Checks if the conjunction of `Vals` is satisfiable and returns the
+  /// corresponding result.
+  ///
+  /// Requirements:
+  ///
+  ///  All elements in `Vals` must not be null.
+  ///
+  /// FIXME: Consider returning a model in case the conjunction of `Vals` is
+  /// satisfiable so that it can be used to generate warning messages.
+  virtual Result solve(llvm::DenseSet Vals) = 0;
+};
+
+} // namespace dataflow
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h 
b/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
new file mode 100644
index 0..702da97349da9
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -0,0 +1,37 @@
+//===- WatchedLiteralsSolver.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a SAT solver implementation that can be used by dataflow
+//  analyses.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H
+
+#include "clang/Analysis/FlowSensitive/Solver.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/ADT/DenseSet.h"
+
+namespace clang {
+namespace dataflow {
+
+/// A SAT solver that is an implementation of Algorithm D from Knuth's The Art
+/// of Computer Programming Volume 4: Satisfiability, Fascicle 6. It is based 
on
+/// the Davis-Putnam-Logemann-Loveland (DPLL) algorithm, keeps references to a
+/// single "watched" literal per clause, and uses a set of "active" variables
+/// for unit propagation.
+class WatchedLiteralsSolver : public Solver {
+public:
+  Result solve(llvm::DenseSet Vals) override;
+};
+
+} // namespace dataflow
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H

diff  --git a/clang/lib/Analysis/FlowSensitive/CMakeLists.txt 
b/clang/lib/Analysi

[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-25 Thread Stanislav Gatev 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 rG53dcd9efd16f: [clang][dataflow] Add SAT solver interface and 
implementation (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

Files:
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -0,0 +1,274 @@
+//===- unittests/Analysis/FlowSensitive/SolverTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/Solver.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+class SolverTest : public ::testing::Test {
+protected:
+  // Checks if the conjunction of `Vals` is satisfiable and returns the
+  // corresponding result.
+  Solver::Result solve(llvm::DenseSet Vals) {
+return WatchedLiteralsSolver().solve(std::move(Vals));
+  }
+
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
+TEST_F(SolverTest, Var) {
+  auto X = atom();
+
+  // X
+  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, NegatedVar) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // !X
+  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, UnitConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // X ^ !X
+  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DistinctVars) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotY = neg(Y);
+
+  // X ^ !Y
+  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, DoubleNegation) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto NotNotX = neg(NotX);
+
+  // !!X ^ !X
+  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedDisjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XOrY = disj(X, Y);
+  auto NotXOrY = neg(XOrY);
+
+  // !(X v Y) ^ (X v Y)
+  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedConjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XAndY = conj(X, Y);
+  auto NotXAndY = neg(XAndY);
+
+  // !(X ^ Y) ^ (X ^ Y)
+  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DisjunctionSameVars) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XOrNotX = disj(X, NotX);
+
+  // X v !X
+  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, ConjunctionSameVarsConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XAndNotX = conj(X, NotX);
+
+  // X ^ !X
+  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, PureVar) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotX = neg(X);
+  auto NotXOrY = disj(NotX, Y);
+  auto NotY = neg(Y);
+  auto NotXOrNotY = disj(NotX, NotY);
+
+  // (!X v 

[PATCH] D120111: [AArch64] Default HBC/MOPS features in clang

2022-02-25 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson requested changes to this revision.
tmatheson added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:269
 success = getAArch64MicroArchFeaturesFromMcpu(
-D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
+D, getAArch64TargetCPU(Args, Triple, A), Args, Features, AF);
 

Looks like you could do `AF = Features.back()` below all these if/else 
conditions (where it is first used) based on the value of `success`. Maybe 
there is no need to pass it into `getAArch64MicroArchFeaturesFromMcpu` and the 
other functions?

Adding an extra output parameter to each of these functions (which duplicates 
an existing output parameter) seems unnecessary and makes the interfaces more 
complicated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120111

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


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rjmccall, rsmith, erichkeane.
aaron.ballman added a comment.

In D120296#3343673 , @yonghong-song 
wrote:

> @aaron.ballman  ping, did you get time to look at this patch?

Sorry, I was in C meetings all last week, still digging out from under the 
emails that piled up.

I think the approach taken here is likely incorrect. Not all `AttributedType` 
objects need this "extra info" as a string, and there's no reason to believe 
future attributes will want their extra info to be in the form of a string. 
However, there's also a fundamental flaw -- the `AttributedType` isn't tracking 
that extra information, so it cannot be profiled in all circumstances (I left a 
comment in the review for that).

As best I can tell, you want a different attribute argument to result in a 
different type in the type system. That needs to happen by adding a new type to 
the type system instead of using the generic `AttributedType` type. This new 
type can track the extra information needed for uniquing the type within the 
type system. As an example, `VectorType` is formed via an attribute, but it 
needs additional information about what kind of vector it is. I don't think you 
can do what you're trying in this patch because the `AttributedType` tracks the 
attribute *kind* but not the actual semantic attribute in use. You need an 
`AttributedTypeLoc` to get access to that via the type system, and you don't 
always have access to type locations.




Comment at: clang/include/clang/AST/Type.h:4774
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
   }

This form of type profiling was not updated (and can't be, because there's 
nothing tracking what extra info is associated with the type), which further 
suggests we need a new type in the type system.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120296

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


[PATCH] D120567: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-25 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein created this revision.
ibookstein requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The purpose of this change is to fix the following codegen bug:

  // main.c
  __attribute__((cpu_specific(generic)))
  int *foo(void) { static int z; return &z;}
  int main() { return *foo() = 5; }
  
  // other.c
  __attribute__((cpu_dispatch(generic))) int *foo(void);
  
  // run:
  clang main.c other.c -o main; ./main

This will segfault prior to the change, and return the correct
exit code 5 after the change.

The underlying cause is that when a translation unit contains
a cpu_specific function without the corresponding cpu_dispatch
the generated code binds the reference to foo() against a
GlobalIFunc whose resolver is undefined. This is invalid: the
resolver must be defined in the same translation unit as the
ifunc, but historically the LLVM bitcode verifier did not check
that. The generated code then binds against the resolver rather
than the ifunc, so it ends up calling the resolver rather than
the resolvee. In the example above it treats its return value as
an int *, therefore trying to write to program text.

The root issue at the representation level is that GlobalIFunc,
like GlobalAlias, does not support a "declaration" state. The
object which provides the correct semantics in these cases
is a Function declaration, but unlike Functions, changing a
declaration to a definition in the GlobalIFunc case constitutes
a change of the object type, as opposed to simply emitting code
into a Function.

I think this limitation is unlikely to change, so I implemented
the fix by returning a function declaration rather than an ifunc
when encountering cpu_specific, and upgrading it to an ifunc
when emitting cpu_dispatch.
This uses `takeName` + `replaceAllUsesWith` in similar vein to
other places where the correct IR object type cannot be known
locally/up-front, like in `CodeGenModule::EmitAliasDefinition`.

Signed-off-by: Itay Bookstein 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120567

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.S() #[[S]]
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
+ATTR(cpu_specific(knl))
+int CpuSpecificNoDispatch(void) { return 1; }
+// CHECK: define {{.*}}i32 @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+
 void usages(void) {
   SingleVersion();
   // LINUX: @SingleVersion.ifunc()
@@ -93,6 +113,9 @@
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
+  CpuSpecificNoDispatch();
+  // LINUX: @CpuSpecificNoDispatch.ifunc()
+  // WINDOWS: @CpuSpecificNoDispatch()
 }
 
 // has 

[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D120555#3345471 , @aaron.ballman 
wrote:

> LGTM, please add a release note for the fix.

That being said, should backport this to clang-14? @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D120566: [OpenCL][AMDGPU]: Do not allow a call to kernel

2022-02-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

One of my concerns is that all kernels are duplicated which may cause code 
object size doubled.

Do we need to make the clone always_inline and let the kernel call its clone to 
avoid duplicate function bodies? Or LLVM has some pass to do that?

Another concern is that the duplicate non-kernel functions have actual kernel 
ABI. Not sure if that can cause any issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120566

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


[PATCH] D120111: [AArch64] Default HBC/MOPS features in clang

2022-02-25 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:269
 success = getAArch64MicroArchFeaturesFromMcpu(
-D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
+D, getAArch64TargetCPU(Args, Triple, A), Args, Features, AF);
 

tmatheson wrote:
> Looks like you could do `AF = Features.back()` below all these if/else 
> conditions (where it is first used) based on the value of `success`. Maybe 
> there is no need to pass it into `getAArch64MicroArchFeaturesFromMcpu` and 
> the other functions?
> 
> Adding an extra output parameter to each of these functions (which duplicates 
> an existing output parameter) seems unnecessary and makes the interfaces more 
> complicated.
we can't do `AF = Features.back()` below all the if/else conditions because 
`getAArch64MicroArchFeaturesFromM*` adds (usually) the architecture feature 
first, followed by a bunch of other features,  so when it returns, 
`Features.back()` is not the architecture feature anymore.

I see your point about complicating the interfaces, maybe @nickdesaulniers can 
help us here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120111

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

according to the pre-merge checks it still fails on windows and Debian.
https://buildkite.com/llvm-project/premerge-checks/builds/81130#ce8f3062-699e-4043-aed9-b891ec8ebee6
https://buildkite.com/llvm-project/premerge-checks/builds/81130#53beb4a2-2c53-4ff0-b60f-6130ed5d25cd

  
  Failed Tests (3):
Clang :: Analysis/errno.c
Clang :: Analysis/global-region-invalidation.c
Clang :: Driver/hip-link-bundle-archive.hip
   
  Testing Time: 836.49s
Skipped  : 3
Unsupported  :   201
Passed   : 29682
Expectedly Failed:31
Failed   : 3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D120555#3345603 , @steakhal wrote:

> In D120555#3345471 , @aaron.ballman 
> wrote:
>
>> LGTM, please add a release note for the fix.
>
> That being said, should backport this to clang-14? @aaron.ballman

I think it's safe enough for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-25 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein updated this revision to Diff 411409.
ibookstein edited the summary of this revision.
ibookstein added a comment.

Changed code to generating a function declaration and 'upgrading'
it to an ifunc instead of generating and ifunc and 'downgrading'
it to a function declaration. I decided against changing it to
bind against the unsuffixed alias instead of the ifunc, though,
because that seems to be more involved for little benefit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120266

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.S() #[[S]]
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
+ATTR(cpu_specific(knl))
+int CpuSpecificNoDispatch(void) { return 1; }
+// CHECK: define {{.*}}i32 @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+
 void usages(void) {
   SingleVersion();
   // LINUX: @SingleVersion.ifunc()
@@ -93,6 +113,9 @@
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
+  CpuSpecificNoDispatch();
+  // LINUX: @CpuSpecificNoDispatch.ifunc()
+  // WINDOWS: @CpuSpecificNoDispatch()
 }
 
 // has an extra config to emit!
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3593,16 +3593,28 @@
   CGF.EmitMultiVersionResolver(ResolverFunc, Options);
 
   if (getTarget().supportsIFunc()) {
+llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage(*this, GD);
+auto *IFunc = cast(
+GetOrCreateMultiVersionResolver(GD, DeclTy, FD));
+
+// Fix up function declarations that were created for cpu_specific before
+// cpu_dispatch was known
+if (!dyn_cast(IFunc)) {
+  assert(cast(IFunc)->isDeclaration());
+  auto *GI = llvm::GlobalIFunc::create(DeclTy, 0, Linkage, "", ResolverFunc,
+   &getModule());
+  GI->takeName(IFunc);
+  IFunc->replaceAllUsesWith(GI);
+  IFunc->eraseFromParent();
+  IFunc = GI;
+}
+
 std::string AliasName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
 llvm::Constant *AliasFunc = GetGlobalValue(AliasName);
 if (!AliasFunc) {
-  auto *IFunc = cast(GetOrCreateLLVMFunction(
-  AliasName, DeclTy, GD, /*ForVTable=*/false, /*DontDefer=*/true,
-  /*IsThunk=*/false, llvm::AttributeList(), NotForDefinition));
-  auto *GA = llvm::GlobalAlias::create(DeclTy, 0,
-   getMultiversionLinkage(*this, GD),
- 

[PATCH] D120566: [OpenCL][AMDGPU]: Do not allow a call to kernel

2022-02-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D120566#3345604 , @yaxunl wrote:

> One of my concerns is that all kernels are duplicated which may cause code 
> object size doubled.

Not really, the kernel should just be a stub that calls the real implementation 
function. In the real world this will always be inlined

> Do we need to make the clone always_inline and let the kernel call its clone 
> to avoid duplicate function bodies? Or LLVM has some pass to do that?

It's not a special case, there's no real need to put always_inline. Nobody uses 
this feature in the real world anyway, and single use functions will be inlined

> Another concern is that the duplicate non-kernel functions have actual kernel 
> ABI. Not sure if that can cause any issues.

My main question is how we have the symbol for the kernel and function coexist


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120566

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


[PATCH] D120566: [OpenCL][AMDGPU]: Do not allow a call to kernel

2022-02-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9238
 
+static llvm::Function *getKernelClone(llvm::Function &F) {
+  llvm::Module *M = F.getParent();

I don't think we can really start with the function IR. The TargetABIInfo could 
be different from the kernel and function form (and will due to using 
byval/byref etc.)



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9240
+  llvm::Module *M = F.getParent();
+  SmallString<128> MangledName("__amdgpu_");
+  MangledName.append(F.getName());

I don't think adding a prefix and suffix is a good strategy for something which 
in principle should be ABI visible. A period + suffix I think would be a better 
convention



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9478-9479
+
+  CI->setCalledFunction(Clone);
+  CI->setCallingConv(llvm::CallingConv::C);
+}

This is basically just moving what the current hack does into clang. Can we 
emit calls to the function version up front?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120566

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


[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 411413.
whisperity added a comment.

Added //Release notes// entry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

Files:
  clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 
'a') looks like it might be swapped with the 2nd, 'a' (passed to 
'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', 
declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,6 +112,9 @@
 - Fixed a false positive in :doc:`readability-non-const-parameter
   ` when the parameter is 
referenced by an lvalue
 
+- Fixed a crash in :doc:`readability-suspicious-call-argument
+  ` related to passing
+  arguments that refer to program elements without a trivial identifier.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -711,23 +711,28 @@
 
   for (std::size_t I = InitialArgIndex, J = MatchedCallExpr->getNumArgs();
I < J; ++I) {
+assert(ArgTypes.size() == I - InitialArgIndex &&
+   ArgNames.size() == ArgTypes.size() &&
+   "Every iteration must put an element into the vectors!");
+
 if (const auto *ArgExpr = dyn_cast(
 MatchedCallExpr->getArg(I)->IgnoreUnlessSpelledInSource())) {
   if (const auto *Var = dyn_cast(ArgExpr->getDecl())) {
 ArgTypes.push_back(Var->getType());
 ArgNames.push_back(Var->getName());
-  } else if (const auto *FCall =
- dyn_cast(ArgExpr->getDecl())) {
-ArgTypes.push_back(FCall->getType());
-ArgNames.push_back(FCall->getName());
-  } else {
-ArgTypes.push_back(QualType());
-ArgNames.push_back(StringRef());
+continue;
+  }
+  if (const auto *FCall = dyn_cast(ArgExpr->getDecl())) {
+if (FCall->getNameInfo().getName().isIdentifier()) {
+  ArgTypes.push_back(FCall->getType());
+  ArgNames.push_back(FCall->getName());
+  continue;
+}
   }
-} else {
-  ArgTypes.push_back(QualType());
-  ArgNames.push_back(StringRef());
 }
+
+ArgTypes.push_back(QualType());
+ArgNames.push_back(StringRef());
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 'a') looks like it might be swapped with the 2nd, 'a' (passed to 'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,6 +112,9 @@
 - Fixed a false p

[clang-tools-extra] 416e689 - [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread via cfe-commits

Author: Whisperity
Date: 2022-02-25T16:24:27+01:00
New Revision: 416e689ecda66616da855c82f7ec652657730c6a

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

LOG: [clang-tidy] Fix `readability-suspicious-call-argument` crash for 
arguments without name-like identifier

As originally reported by @steakhal in
http://github.com/llvm/llvm-project/issues/54074, the name extraction logic of
`readability-suspicious-call-argument` crashes if the argument passed to a
function was a function call to a non-trivially named entity (e.g. an operator).

Fixed this crash case by ignoring such constructs and considering them as having
no name.

Reviewed By: aaron.ballman, steakhal

Differential Revision: http://reviews.llvm.org/D120555

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index 4d7c3451acc7a..ac6bda3ff09ff 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -711,23 +711,28 @@ void SuspiciousCallArgumentCheck::setArgNamesAndTypes(
 
   for (std::size_t I = InitialArgIndex, J = MatchedCallExpr->getNumArgs();
I < J; ++I) {
+assert(ArgTypes.size() == I - InitialArgIndex &&
+   ArgNames.size() == ArgTypes.size() &&
+   "Every iteration must put an element into the vectors!");
+
 if (const auto *ArgExpr = dyn_cast(
 MatchedCallExpr->getArg(I)->IgnoreUnlessSpelledInSource())) {
   if (const auto *Var = dyn_cast(ArgExpr->getDecl())) {
 ArgTypes.push_back(Var->getType());
 ArgNames.push_back(Var->getName());
-  } else if (const auto *FCall =
- dyn_cast(ArgExpr->getDecl())) {
-ArgTypes.push_back(FCall->getType());
-ArgNames.push_back(FCall->getName());
-  } else {
-ArgTypes.push_back(QualType());
-ArgNames.push_back(StringRef());
+continue;
+  }
+  if (const auto *FCall = dyn_cast(ArgExpr->getDecl())) {
+if (FCall->getNameInfo().getName().isIdentifier()) {
+  ArgTypes.push_back(FCall->getType());
+  ArgNames.push_back(FCall->getName());
+  continue;
+}
   }
-} else {
-  ArgTypes.push_back(QualType());
-  ArgNames.push_back(StringRef());
 }
+
+ArgTypes.push_back(QualType());
+ArgNames.push_back(StringRef());
   }
 }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fc00598ad495e..3227fb5ce576a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,6 +112,9 @@ Changes in existing checks
 - Fixed a false positive in :doc:`readability-non-const-parameter
   ` when the parameter is 
referenced by an lvalue
 
+- Fixed a crash in :doc:`readability-suspicious-call-argument
+  ` related to passing
+  arguments that refer to program elements without a trivial identifier.
 
 Removed checks
 ^^

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
index 2597ee3b9e030..edd3591517af3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@ int main() {
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 
'a') looks like it might be swapped with the 2nd, 'a' (passed to 
'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', 
declared here
+}
+
+} // namespace Issue_54074



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


[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Whisperity 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 rG416e689ecda6: [clang-tidy] Fix 
`readability-suspicious-call-argument` crash for arguments… (authored by 
whisperity).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

Files:
  clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 
'a') looks like it might be swapped with the 2nd, 'a' (passed to 
'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', 
declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,6 +112,9 @@
 - Fixed a false positive in :doc:`readability-non-const-parameter
   ` when the parameter is 
referenced by an lvalue
 
+- Fixed a crash in :doc:`readability-suspicious-call-argument
+  ` related to passing
+  arguments that refer to program elements without a trivial identifier.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -711,23 +711,28 @@
 
   for (std::size_t I = InitialArgIndex, J = MatchedCallExpr->getNumArgs();
I < J; ++I) {
+assert(ArgTypes.size() == I - InitialArgIndex &&
+   ArgNames.size() == ArgTypes.size() &&
+   "Every iteration must put an element into the vectors!");
+
 if (const auto *ArgExpr = dyn_cast(
 MatchedCallExpr->getArg(I)->IgnoreUnlessSpelledInSource())) {
   if (const auto *Var = dyn_cast(ArgExpr->getDecl())) {
 ArgTypes.push_back(Var->getType());
 ArgNames.push_back(Var->getName());
-  } else if (const auto *FCall =
- dyn_cast(ArgExpr->getDecl())) {
-ArgTypes.push_back(FCall->getType());
-ArgNames.push_back(FCall->getName());
-  } else {
-ArgTypes.push_back(QualType());
-ArgNames.push_back(StringRef());
+continue;
+  }
+  if (const auto *FCall = dyn_cast(ArgExpr->getDecl())) {
+if (FCall->getNameInfo().getName().isIdentifier()) {
+  ArgTypes.push_back(FCall->getType());
+  ArgNames.push_back(FCall->getName());
+  continue;
+}
   }
-} else {
-  ArgTypes.push_back(QualType());
-  ArgNames.push_back(StringRef());
 }
+
+ArgTypes.push_back(QualType());
+ArgNames.push_back(StringRef());
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-suspicious-call-argument.cpp
@@ -485,3 +485,32 @@
 
   return 0;
 }
+
+namespace Issue_54074 {
+
+class T {};
+using OperatorTy = int(const T &, const T &);
+int operator-(const T &, const T &);
+
+template 
+struct Wrap {
+  Wrap(U);
+};
+
+template 
+void wrapTaker(V, Wrap);
+
+template 
+void wrapTaker(V a, V b, Wrap);
+
+void test() {
+  wrapTaker(0, operator-);
+  // NO-WARN. No crash!
+
+  int a = 4, b = 8;
+  wrapTaker(b, a, operator-);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 1st argument 'b' (passed to 'a') looks like it might be swapped with the 2nd, 'a' (passed to 'b')
+  // CHECK-MESSAGES: :[[@LINE-9]]:6: note: in the call to 'wrapTaker', declared here
+}
+
+} // namespace Issue_54074
Index: clang-tools-extra/docs/ReleaseNotes.rst

[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-25 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein added a comment.

Ah, I saw your comment just now, good thing I didn't continue down that 
plain-alias-name route then!
The change now satisfies that requirement in a way that binding against the 
alias name indeed would not: TU1 will have the callsite in `caller` bind 
against `foo.ifunc`, which is not a symbol that TU2 defines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120266

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


[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D120266#3345649 , @ibookstein 
wrote:

> Ah, I saw your comment just now, good thing I didn't continue down that 
> plain-alias-name route then!
> The change now satisfies that requirement in a way that binding against the 
> alias name indeed would not: TU1 will have the callsite in `caller` bind 
> against `foo.ifunc`, which is not a symbol that TU2 defines.

Ah!  I'm glad you did too!  Thanks for the patch.  I think this works for me, I 
definitely like the 'upgrade' better than the 'downgrade'.

Can you please make sure there is an 'upgrade' path test in all of the 
configurations in the tests before committing?

That is, something like:
dispatch def
specific def
call

in all orders?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120266

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


[PATCH] D120499: [NVPTX] Fix nvvm.match.sync*.i64 intrinsics return type (i64 -> i32)

2022-02-25 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411416.
krisb added a comment.

Fix a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120499

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/Headers/__clang_cuda_intrinsics.h
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/match.ll

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
 
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
-  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
-  %v1 = extractvalue {i64, i1} %r1, 0
-  %p1 = extractvalue {i64, i1} %r1, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
-  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
-  %v2 = extractvalue {i64, i1} %r2, 0
-  %p2 = extractvalue {i64, i1} %r2, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
-  %r3 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
-  %v3 = extractvalue {i64, i1} %r3, 0
-  %p3 = extractvalue {i64, i1} %r3, 1
-
-  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 4, 3;
-  %r4 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 3, i64 4)
-  %v4 = extractvalue {i64, i1} %r4, 0
-  %p4 = extractvalue {i64, i1} %r4, 1
-
-  %vsum1 = add i64 %v1, %v2
-  %vsum2 = add i64 %v3, %v4
-  %vsum3 = add i64 %vsum1, %vsum2
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32 2, i64 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  match.all.sync.b64 {{%r[0-9]+\|%p[0-9]+}}, 4,

[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Thanks! I'll re-run the tests on top of **14.0** and do the backport too, soon. 
🙂


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D120246: [flang][driver] Add support for `--target`/`--triple`

2022-02-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thank you all for taking a look!

I've just realised this: "This revision was not accepted when it landed; it 
landed in state Needs Review." Just to clarify, I merged this as two reviewers 
accepted this in comments (with "LGTM"). Also, I believe that I addressed all 
your comments. If you feel otherwise, I'm happy to re-open the discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120246

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


[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-25 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

In D113393#3345275 , @aaron.ballman 
wrote:

>> Also implemented decltype(auto)(x) (https://wg21.link/p0849r2) as a Clang 
>> extension.
>
> I'd like to better understand the use cases for this. WG21 considered this as 
> part of the feature and ultimately rejected it (fairly strongly, according to 
> the EWG polls). From the meeting minutes, it says that the reason EWG 
> disliked the idea is because of its expert-friendly nature and that this 
> facility would present teachability issues. I tend to agree, so I'm wondering 
> why we want to add the feature as an extension when WG21 explicitly rejected 
> it (that doesn't seem in line with our extension policy: 
> https://clang.llvm.org/get_involved.html#criteria).

(I'm not directly answering Aaron's question.)  Personally I think it makes 
sense to support `decltype(auto)(x)` in the same release as `auto(x)`, for the 
same reason we supported `Constrained decltype(auto)` in the same release as 
`Constrained auto`. //But//, rather than have that essentially tangential 
policy discussion in //this// PR, @lichray, would you be willing to split out 
all the changes related to `decltype(auto)(x)` into their own separate PR, (1) 
so that we could land the uncontroversial C++20 `auto(x)` parts sooner rather 
than later, and (2) so that if three years from now someone //does// decide to 
revert `decltype(auto)(x)`, all its changes will be nicely isolated in their 
own commit instead of mixed in with important bits of our C++20 conformance? 
And (3) so that we could have the "Should we do this?" policy discussion in 
//that// PR, instead of here, and (4) the discussion would be more focused 
because we could see //exactly// the set of diffs we're talking about, instead 
of mixed in etc etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

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


[PATCH] D120323: [clang][SVE] Add support for arithmetic operators on SVE types

2022-02-25 Thread David Truby via Phabricator via cfe-commits
DavidTruby added a comment.

In D120323#3341468 , @efriedma wrote:

> Is there a corresponding ARM specification update for this?

We are planning on updating the specification in future for this but are 
waiting on some other changes first. What we're intending to do here is just 
match the behaviour of the NEON types, for which these operators are already 
supported, as closely as possible.
Since there is also nothing in the spec about operators on NEON types, we 
didn't think there was a need to hold up the implementation to wait for the 
spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120323

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

The "hip-link-bundle-archive" test looks really unrelated, the others are fixed 
if we go back to `-DERRNO_VAR` (no `"` characters in command line, and probably 
`/` does not work too). There are Debian build errors but these look 
unrelated(?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[clang] 5048a58 - [analyzer] Don't crash if the analyzer-constraint is set to Z3, but llvm is not built with it

2022-02-25 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2022-02-25T17:51:37+01:00
New Revision: 5048a58a6792ee7432b749a48c937cc9b6a9dc93

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

LOG: [analyzer] Don't crash if the analyzer-constraint is set to Z3, but llvm 
is not built with it

Exactly what it says on the tin! We had a nasty crash with the following 
incovation:

$ clang --analyze -Xclang -analyzer-constraints=z3 test.c
fatal error: error in backend: LLVM was not compiled with Z3 support, rebuild 
with -DLLVM_ENABLE_Z3_SOLVER=ON
...  ...

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

Added: 
clang/test/Analysis/missing-z3-nocrash.c

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index b608b8ec50682..1ac5bf844efe6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -438,6 +438,9 @@ def err_analyzer_checker_option_invalid_input : Error<
   "invalid input for checker option '%0', that expects %1">;
 def err_analyzer_checker_incompatible_analyzer_option : Error<
   "checker cannot be enabled with analyzer option '%0' == %1">;
+def err_analyzer_not_built_with_z3 : Error<
+  "analyzer constraint manager 'z3' is only available if LLVM was built with "
+  "-DLLVM_ENABLE_Z3_SOLVER=ON">;
 
 def warn_drv_needs_hvx : Warning<
   "%0 requires HVX, use -mhvx/-mhvx= to enable it">,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1014147451091..5d7c999b0143a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -915,6 +915,11 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, 
ArgList &Args,
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << Name;
 } else {
+#ifndef LLVM_WITH_Z3
+  if (Value == AnalysisConstraints::Z3ConstraintsModel) {
+Diags.Report(diag::err_analyzer_not_built_with_z3);
+  }
+#endif // LLVM_WITH_Z3
   Opts.AnalysisConstraintsOpt = Value;
 }
   }

diff  --git a/clang/test/Analysis/missing-z3-nocrash.c 
b/clang/test/Analysis/missing-z3-nocrash.c
new file mode 100644
index 0..698430fffe1a1
--- /dev/null
+++ b/clang/test/Analysis/missing-z3-nocrash.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_analyze_cc1 -analyzer-constraints=z3 %s 2>&1 | FileCheck %s
+// REQUIRES: no-z3
+
+// CHECK: error: analyzer constraint manager 'z3' is only available if LLVM
+// CHECK: was built with -DLLVM_ENABLE_Z3_SOLVER=ON

diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index a8efe6c593e98..31425e4009fe2 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -100,6 +100,8 @@ def have_host_jit_support():
 
 if config.clang_staticanalyzer_z3:
 config.available_features.add('z3')
+else:
+config.available_features.add('no-z3')
 
 check_analyzer_fixit_path = os.path.join(
 config.test_source_root, "Analysis", "check-analyzer-fixit.py")



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


[PATCH] D120325: [analyzer] Don't crash if the analyzer-constraint is set to Z3, but llvm is not built with it

2022-02-25 Thread Kristóf Umann 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 rG5048a58a6792: [analyzer] Don't crash if the 
analyzer-constraint is set to Z3, but llvm is not… (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D120325?vs=410526&id=411418#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120325

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Analysis/missing-z3-nocrash.c
  clang/test/lit.cfg.py


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -100,6 +100,8 @@
 
 if config.clang_staticanalyzer_z3:
 config.available_features.add('z3')
+else:
+config.available_features.add('no-z3')
 
 check_analyzer_fixit_path = os.path.join(
 config.test_source_root, "Analysis", "check-analyzer-fixit.py")
Index: clang/test/Analysis/missing-z3-nocrash.c
===
--- /dev/null
+++ clang/test/Analysis/missing-z3-nocrash.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_analyze_cc1 -analyzer-constraints=z3 %s 2>&1 | FileCheck %s
+// REQUIRES: no-z3
+
+// CHECK: error: analyzer constraint manager 'z3' is only available if LLVM
+// CHECK: was built with -DLLVM_ENABLE_Z3_SOLVER=ON
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -915,6 +915,11 @@
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << Name;
 } else {
+#ifndef LLVM_WITH_Z3
+  if (Value == AnalysisConstraints::Z3ConstraintsModel) {
+Diags.Report(diag::err_analyzer_not_built_with_z3);
+  }
+#endif // LLVM_WITH_Z3
   Opts.AnalysisConstraintsOpt = Value;
 }
   }
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -438,6 +438,9 @@
   "invalid input for checker option '%0', that expects %1">;
 def err_analyzer_checker_incompatible_analyzer_option : Error<
   "checker cannot be enabled with analyzer option '%0' == %1">;
+def err_analyzer_not_built_with_z3 : Error<
+  "analyzer constraint manager 'z3' is only available if LLVM was built with "
+  "-DLLVM_ENABLE_Z3_SOLVER=ON">;
 
 def warn_drv_needs_hvx : Warning<
   "%0 requires HVX, use -mhvx/-mhvx= to enable it">,


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -100,6 +100,8 @@
 
 if config.clang_staticanalyzer_z3:
 config.available_features.add('z3')
+else:
+config.available_features.add('no-z3')
 
 check_analyzer_fixit_path = os.path.join(
 config.test_source_root, "Analysis", "check-analyzer-fixit.py")
Index: clang/test/Analysis/missing-z3-nocrash.c
===
--- /dev/null
+++ clang/test/Analysis/missing-z3-nocrash.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_analyze_cc1 -analyzer-constraints=z3 %s 2>&1 | FileCheck %s
+// REQUIRES: no-z3
+
+// CHECK: error: analyzer constraint manager 'z3' is only available if LLVM
+// CHECK: was built with -DLLVM_ENABLE_Z3_SOLVER=ON
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -915,6 +915,11 @@
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << Name;
 } else {
+#ifndef LLVM_WITH_Z3
+  if (Value == AnalysisConstraints::Z3ConstraintsModel) {
+Diags.Report(diag::err_analyzer_not_built_with_z3);
+  }
+#endif // LLVM_WITH_Z3
   Opts.AnalysisConstraintsOpt = Value;
 }
   }
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -438,6 +438,9 @@
   "invalid input for checker option '%0', that expects %1">;
 def err_analyzer_checker_incompatible_analyzer_option : Error<
   "checker cannot be enabled with analyzer option '%0' == %1">;
+def err_analyzer_not_built_with_z3 : Error<
+  "analyzer constraint manager 'z3' is only available if LLVM was built with "
+  "-DLLVM_ENABLE_Z3_SOLVER=ON">;
 
 def warn_drv_needs_hvx : Warning<
   "%0 requires HVX, use -mhvx/-mhvx= to enable it">,
___
cfe-commits mailing list
c

[PATCH] D120555: [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier

2022-02-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D120555#3345664 , @whisperity 
wrote:

> Thanks! I'll re-run the tests on top of **14.0** and do the backport too, 
> soon. 🙂

If you backport, the release notes change on trunk should then be reverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120555

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


[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D113393#3345672 , @Quuxplusone 
wrote:

> In D113393#3345275 , @aaron.ballman 
> wrote:
>
>>> Also implemented decltype(auto)(x) (https://wg21.link/p0849r2) as a Clang 
>>> extension.
>>
>> I'd like to better understand the use cases for this. WG21 considered this 
>> as part of the feature and ultimately rejected it (fairly strongly, 
>> according to the EWG polls). From the meeting minutes, it says that the 
>> reason EWG disliked the idea is because of its expert-friendly nature and 
>> that this facility would present teachability issues. I tend to agree, so 
>> I'm wondering why we want to add the feature as an extension when WG21 
>> explicitly rejected it (that doesn't seem in line with our extension policy: 
>> https://clang.llvm.org/get_involved.html#criteria).
>
> (I'm not directly answering Aaron's question.)  Personally I think it makes 
> sense to support `decltype(auto)(x)` in the same release as `auto(x)`, for 
> the same reason we supported `Constrained decltype(auto)` in the same release 
> as `Constrained auto`. //But//, rather than have that essentially tangential 
> policy discussion in //this// PR, @lichray, would you be willing to split out 
> all the changes related to `decltype(auto)(x)` into their own separate PR, 
> (1) so that we could land the uncontroversial C++20 `auto(x)` parts sooner 
> rather than later, and (2) so that if three years from now someone //does// 
> decide to revert `decltype(auto)(x)`, all its changes will be nicely isolated 
> in their own commit instead of mixed in with important bits of our C++20 
> conformance? And (3) so that we could have the "Should we do this?" policy 
> discussion in //that// PR, instead of here, and (4) the discussion would be 
> more focused because we could see //exactly// the set of diffs we're talking 
> about, instead of mixed in etc etc.

This option sounds quite sensible to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411421.
balazske added a comment.

Another try to fix the test failures, rebased to current main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation-errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection
 
 void clang_analyzer_eval(int);
 
@@ -35,33 +36,6 @@
   return m + j; // expected-warning + {{tainted}}
 }
 
-// Test errno gets invalidated by a system call.
-int testErrnoSystem(void) {
-  int i;
-  int *p = 0;
-  fscanf(stdin, "%d", &i);
-  if (errno == 0) {
-fscanf(stdin, "%d", &i); // errno gets invalidated here.
-return 5 / errno; // no-warning
-  }
-
-  errno = 0;
-  fscanf(stdin, "%d", &i); // errno gets invalidated here.
-  return 5 / errno; // no-warning
-}
-
-// Test that errno gets invalidated by internal calls.
-int testErrnoInternal(void) {
-  int i;
-  int *p = 0;
-  fscanf(stdin, "%d", &i);
-  if (errno == 0) {
-foo(); // errno gets invalidated here.
-return 5 / errno; // no-warning
-  }
-  return 0;
-}
-
 // Test that const integer does not get invalidated.
 const int x = 0;
 int constIntGlob(void) {
@@ -124,4 +98,3 @@
   static int g = 5;
   clang_analyzer_eval(g == 5); // expected-warning{{TRUE}}
 }
-
Index: clang/test/Analysis/global-region-invalidation-errno.c
===
--- /dev/null
+++ clang/test/Analysis/global-region-invalidation-errno.c
@@ -0,0 +1,49 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint \
+// RUN:   -DERRNO_VAR
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint \
+// RUN:   -DERRNO_FUNC
+
+// Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+// The errno value can be defined in multiple ways, test with each one.
+#ifdef ERRNO_VAR
+#include "Inputs/errno_var.h"
+#endif
+#ifdef ERRNO_FUNC
+#include "Inputs/errno_func.h"
+#endif
+#include "Inputs/system-header-simulator.h"
+
+
+void foo(void);
+
+// expected-no-diagnostics
+
+// Test errno gets invalidated by a system call.
+int testErrnoSystem(void) {
+  int i;
+  int *p = 0;
+  fscanf(stdin, "%d", &i);
+  if (errno == 0) {
+fscanf(stdin, "%d", &i); // errno gets invalidated here.
+return 5 / errno; // no-warning
+  }
+
+  errno = 0;
+  fscanf(stdin, "%d", &i); // errno gets invalidated here.
+  return 5 / errno; // no-warning
+}
+
+// Test that errno gets invalidated by internal calls.
+int testErrnoInternal(void) {
+  int i;
+  int *p = 0;
+  fscanf(stdin, "%d", &i);
+  if (errno == 0) {
+foo(); // errno gets invalidated here.
+return 5 / errno; // no-warning
+  }
+  return 0;
+}
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/er

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D120310#3345696 , @balazske wrote:

> The "hip-link-bundle-archive" test looks really unrelated, the others are 
> fixed if we go back to `-DERRNO_VAR` (no `"` characters in command line, and 
> probably `/` does not work too). There are Debian build errors but these look 
> unrelated(?).

I think its the forward slashes.

We could workaround the issue by adding this line to the test files: `// 
REQUIRES: system-linux`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[clang] c5e1b5e - [Clang][Sema] Do not evaluate value-dependent immediate invocations

2022-02-25 Thread Corentin Jabot via cfe-commits

Author: Evgeny Shulgin
Date: 2022-02-25T17:23:36+01:00
New Revision: c5e1b5e6a99f1ab78dafb54262d8f1fff998cb26

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

LOG: [Clang][Sema] Do not evaluate value-dependent immediate invocations

Value-dependent ConstantExprs are not meant to be evaluated.
There is an assert in Expr::EvaluateAsConstantExpr that ensures this condition.
But before this patch the method was called without prior check.

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

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 454e21ecfa2d9..b24caa56a38ad 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16817,7 +16817,10 @@ ExprResult 
Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
   ConstantExpr::getStorageKind(Decl->getReturnType().getTypePtr(),
getASTContext()),
   /*IsImmediateInvocation*/ true);
-  ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
+  /// Value-dependent constant expressions should not be immediately
+  /// evaluated until they are instantiated.
+  if (!Res->isValueDependent())
+ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
   return Res;
 }
 

diff  --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index e909f2f303764..941d47dcb055e 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,32 @@ static_assert(is_same::value);
 
 } // namespace unevaluated
 
+namespace value_dependent {
+
+consteval int foo(int x) {
+  return x;
+}
+
+template  constexpr int bar() {
+  // Previously this call was rejected as value-dependent constant expressions
+  // can't be immediately evaluated. Now we show that we don't immediately
+  // evaluate them until they are instantiated.
+  return foo(X);
+}
+
+template  constexpr int baz() {
+  constexpr int t = sizeof(T);
+  // Previously this call was rejected as `t` is value-dependent and its value
+  // is unknown until the function is instantiated. Now we show that we don't
+  // reject such calls.
+  return foo(t);
+}
+
+static_assert(bar<15>() == 15);
+static_assert(baz() == sizeof(int));
+
+} // namespace value_dependent
+
 namespace PR50779 {
 struct derp {
   int b = 0;



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


[PATCH] D119375: [Clang][Sema] Do not evaluate value-dependent immediate invocations

2022-02-25 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc5e1b5e6a99f: [Clang][Sema] Do not evaluate value-dependent 
immediate invocations (authored by Izaron, committed by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119375

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,32 @@
 
 } // namespace unevaluated
 
+namespace value_dependent {
+
+consteval int foo(int x) {
+  return x;
+}
+
+template  constexpr int bar() {
+  // Previously this call was rejected as value-dependent constant expressions
+  // can't be immediately evaluated. Now we show that we don't immediately
+  // evaluate them until they are instantiated.
+  return foo(X);
+}
+
+template  constexpr int baz() {
+  constexpr int t = sizeof(T);
+  // Previously this call was rejected as `t` is value-dependent and its value
+  // is unknown until the function is instantiated. Now we show that we don't
+  // reject such calls.
+  return foo(t);
+}
+
+static_assert(bar<15>() == 15);
+static_assert(baz() == sizeof(int));
+
+} // namespace value_dependent
+
 namespace PR50779 {
 struct derp {
   int b = 0;
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16817,7 +16817,10 @@
   ConstantExpr::getStorageKind(Decl->getReturnType().getTypePtr(),
getASTContext()),
   /*IsImmediateInvocation*/ true);
-  ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
+  /// Value-dependent constant expressions should not be immediately
+  /// evaluated until they are instantiated.
+  if (!Res->isValueDependent())
+ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
   return Res;
 }
 


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,32 @@
 
 } // namespace unevaluated
 
+namespace value_dependent {
+
+consteval int foo(int x) {
+  return x;
+}
+
+template  constexpr int bar() {
+  // Previously this call was rejected as value-dependent constant expressions
+  // can't be immediately evaluated. Now we show that we don't immediately
+  // evaluate them until they are instantiated.
+  return foo(X);
+}
+
+template  constexpr int baz() {
+  constexpr int t = sizeof(T);
+  // Previously this call was rejected as `t` is value-dependent and its value
+  // is unknown until the function is instantiated. Now we show that we don't
+  // reject such calls.
+  return foo(t);
+}
+
+static_assert(bar<15>() == 15);
+static_assert(baz() == sizeof(int));
+
+} // namespace value_dependent
+
 namespace PR50779 {
 struct derp {
   int b = 0;
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16817,7 +16817,10 @@
   ConstantExpr::getStorageKind(Decl->getReturnType().getTypePtr(),
getASTContext()),
   /*IsImmediateInvocation*/ true);
-  ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
+  /// Value-dependent constant expressions should not be immediately
+  /// evaluated until they are instantiated.
+  if (!Res->isValueDependent())
+ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
   return Res;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119375: [Clang][Sema] Do not evaluate value-dependent immediate invocations

2022-02-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D119375#3329014 , @Izaron wrote:

> A friendly ping =) Seems like I don't have write access, so unfortunately I 
> have to ask people to merge commits on my behalf. Let me copy-paste the usual 
> comment of my reviews:

I landed your change.
Thanks for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119375

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


[PATCH] D120568: [flang][driver] Add support for -S and implement -c/-emit-obj

2022-02-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added reviewers: rovka, clementval, schweitz, Leporacanthicus.
Herald added subscribers: Chia-hungDuan, mehdi_amini, dang, rriddle, pengfei, 
kristof.beyls, mgorny.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer, jdoerfert.
Herald added a project: clang.

This patch adds support for:

- `-S` in Flang's compiler and frontend drivers

and implements (these options were already available as placeholders):

- `-emit-obj` in Flang's frontend driver and `-c` in Flang's compiler driver

The semantics of these options in Clang and Flang are identical.

The `EmitObjAction` frontend action is renamed as `BackendAction`. The
new name more accurately reflects the fact that this action will
primarily run the code-gen/backend pipeline in LLVM. It also makes more
sense as an action implementing both `-emit-obj` and `-S` (originally it
was just `-emit-obj`).

`tripleName` in FirContext.cpp is updated from `fir.triple` to
`llvm.target_triple`. The former was effectively ignored. The latter is
used when lowering from the LLVM dialect in MLIR to LLVM IR (i.e. it's
embedded in the generated LLVM IR module). The driver can then re-use
that when configuring the backend. With this change, the LLVM IR files
generated by e.g. `tco` will from now on contain the correct target
triple.

The code-gen.f90 test is replaced with code-gen-x86.f90 and
code-gen-aarch64.f90. With 2 seperate files we can verify that
`--target` is correctly taken into account. LIT configuration is updated
to enable e.g.:

  ! REQUIRES: aarch64-registered-target


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120568

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/lib/Optimizer/Support/FIRContext.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/code-gen-aarch64.f90
  flang/test/Driver/code-gen-x86.f90
  flang/test/Driver/code-gen.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-asm-aarch64.f90
  flang/test/Driver/emit-asm-x86.f90
  flang/test/Driver/syntax-only.f90
  flang/test/Fir/target-rewrite-triple.fir
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in
  flang/tools/flang-driver/fc1_main.cpp
  flang/unittests/Frontend/CMakeLists.txt
  flang/unittests/Frontend/FrontendActionTest.cpp

Index: flang/unittests/Frontend/FrontendActionTest.cpp
===
--- flang/unittests/Frontend/FrontendActionTest.cpp
+++ flang/unittests/Frontend/FrontendActionTest.cpp
@@ -11,6 +11,7 @@
 #include "flang/Frontend/FrontendOptions.h"
 #include "flang/FrontendTool/Utils.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include "gtest/gtest.h"
@@ -188,4 +189,35 @@
   EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
   .contains("define void @_QQmain()"));
 }
+
+TEST_F(FrontendActionTest, EmitAsm) {
+  // Populate the input file with the pre-defined input and flush it.
+  *(inputFileOs_) << "end program";
+  inputFileOs_.reset();
+
+  // Set-up the action kind.
+  compInst_.invocation().frontendOpts().programAction = EmitAssembly;
+  compInst_.invocation().preprocessorOpts().noReformat = true;
+
+  // Initialise LLVM backend
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+
+  // Set-up the output stream. We are using output buffer wrapped as an output
+  // stream, as opposed to an actual file (or a file descriptor).
+  llvm::SmallVector outputFileBuffer;
+  std::unique_ptr outputFileStream(
+  new llvm::raw_svector_ostream(outputFileBuffer));
+  compInst_.set_outputStream(std::move(outputFileStream));
+
+  // Execute the action.
+  bool success = ExecuteCompilerInvocation(&compInst_);
+
+  // Validate the expected output.
+  EXPECT_TRUE(success);
+  EXPECT_TRUE(!outputFileBuffer.empty());
+
+  EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data()).contains("_QQmain"));
+}
 } // namespace
Index: flang/unittests/Frontend/CMakeLists.txt
===
--- flang/unittests/Frontend/CMakeLists.txt
+++ flang/unittests/Frontend/CMakeLists.txt
@@ -1,3 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+)
+
 add_flang_unittest(FlangFrontendTests
   CompilerInstanceTest.cpp
   FrontendActionTest.cpp
Index: flang/tools/flang-driver/fc1_main.cpp
===
--- flang/tools/flang-driver/fc1_main.cpp
+++ flang/tools/flang-driver/fc1_main.cpp
@@

[PATCH] D120569: [clang] Improve laziness of resolving module map headers.

2022-02-25 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: kadircet.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang has support for lazy headers in module maps - if size and/or
modtime and provided in the cppmap file, headers are only resolved when
an include directive for a file with that size/modtime is encoutered.

Before this change, the lazy resolution was all-or-nothing per module.
That means as soon as even one file in that module potentially matched
an include, all lazy files in that module were resolved. With this
change, only files with matching size/modtime will be resolved.

The goal is to avoid unnecessary stat() calls on non-included files,
which is especially valuable on networked file systems, with higher
latency.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120569

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1879,7 +1879,7 @@
   // headers list when emitting resolved headers in the first loop below.
   // FIXME: It'd be preferable to avoid doing this if we were given
   // sufficient stat information in the module map.
-  HS.getModuleMap().resolveHeaderDirectives(M);
+  HS.getModuleMap().resolveHeaderDirectives(M, /*File=*/llvm::None);
 
   // If the file didn't exist, we can still create a module if we were given
   // enough information in the module map.
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -482,7 +482,7 @@
 
   if (RequestingModule) {
 resolveUses(RequestingModule, /*Complain=*/false);
-resolveHeaderDirectives(RequestingModule);
+resolveHeaderDirectives(RequestingModule, /*File=*/llvm::None);
   }
 
   bool Excluded = false;
@@ -1191,25 +1191,35 @@
   auto BySize = LazyHeadersBySize.find(File->getSize());
   if (BySize != LazyHeadersBySize.end()) {
 for (auto *M : BySize->second)
-  resolveHeaderDirectives(M);
+  resolveHeaderDirectives(M, File);
 LazyHeadersBySize.erase(BySize);
   }
 
   auto ByModTime = LazyHeadersByModTime.find(File->getModificationTime());
   if (ByModTime != LazyHeadersByModTime.end()) {
 for (auto *M : ByModTime->second)
-  resolveHeaderDirectives(M);
+  resolveHeaderDirectives(M, File);
 LazyHeadersByModTime.erase(ByModTime);
   }
 }
 
-void ModuleMap::resolveHeaderDirectives(Module *Mod) const {
+void ModuleMap::resolveHeaderDirectives(
+Module *Mod, llvm::Optional File) const {
   bool NeedsFramework = false;
-  for (auto &Header : Mod->UnresolvedHeaders)
-// This operation is logically const; we're just changing how we represent
-// the header information for this file.
-const_cast(this)->resolveHeader(Mod, Header, NeedsFramework);
-  Mod->UnresolvedHeaders.clear();
+  SmallVector NewHeaders;
+  const auto Size = File ? File.getValue()->getSize() : 0;
+  const auto ModTime = File ? File.getValue()->getModificationTime() : 0;
+
+  for (auto &Header : Mod->UnresolvedHeaders) {
+if (File && ((Header.ModTime && Header.ModTime != ModTime) ||
+ (Header.Size && Header.Size != Size)))
+  NewHeaders.push_back(Header);
+else
+  // This operation is logically const; we're just changing how we represent
+  // the header information for this file.
+  const_cast(this)->resolveHeader(Mod, Header, NeedsFramework);
+  }
+  Mod->UnresolvedHeaders.swap(NewHeaders);
 }
 
 void ModuleMap::addHeader(Module *Mod, Module::Header Header,
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -331,7 +331,7 @@
 return std::error_code();
 
   // Resolve all lazy header directives to header files.
-  ModMap.resolveHeaderDirectives(Module);
+  ModMap.resolveHeaderDirectives(Module, /*File=*/llvm::None);
 
   // If any headers are missing, we can't build this module. In most cases,
   // diagnostics for this should have already been produced; we only get here
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -456,8 +456,11 @@
   /// is effectively internal, but is exposed so HeaderSearch can call it.
   void resolveHeaderDirectives(const FileEntry *File) const;
 
-  /// Resolve all lazy header directives for the specified module.
-  void resolveHeaderDirectives(Module *Mod) const;
+  /// Resolve lazy header directives for the specified module. If Fi

[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

> This option sounds quite sensible to me!

I'd like that too!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

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


[PATCH] D120305: [Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON

2022-02-25 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@MaskRay The ppc buildbots have been red since these patches - please can you 
take a look? https://lab.llvm.org/buildbot/#/builders/57/builds/15454


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120305

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


[PATCH] D120568: [flang][driver] Add support for -S and implement -c/-emit-obj

2022-02-25 Thread Eric Schweitz via Phabricator via cfe-commits
schweitz added inline comments.



Comment at: flang/lib/Frontend/FrontendActions.cpp:43
 using namespace Fortran::frontend;
+using namespace llvm;
 

You'll want to keep in mind that some class names are overloaded between llvm 
and Fortran::xyz namespaces and even between Fortran::uvw and Fortran::xyz 
namespaces.



Comment at: flang/lib/Frontend/FrontendActions.cpp:506
+  std::string error;
+  std::string theTriple = llvmModule->getTargetTriple();
+  const llvm::Target *theTarget =





Comment at: flang/lib/Frontend/FrontendActions.cpp:516
+  llvmModule->setDataLayout(TM->createDataLayout());
+  assert(TM && "Failed to create TargetMachine");
+

This assert comes after `TM` is dereferenced in the line above.



Comment at: flang/lib/Frontend/FrontendActions.cpp:556
+  CodeGenPasses.add(createTargetTransformInfoWrapperPass(TargetIRAnalysis()));
+  Triple triple(llvmModule->getTargetTriple());
+  std::unique_ptr TLII =

getTargetTriple() was already saved into `theTriple` variable above.



Comment at: flang/lib/Frontend/FrontendActions.cpp:559
+  std::make_unique(triple);
+  CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
+

Do you want to assert on this RAII of `TLII`?



Comment at: flang/lib/Optimizer/Support/FIRContext.cpp:19
 
-static constexpr const char *tripleName = "fir.triple";
+static constexpr const char *tripleName = "llvm.target_triple";
 

Why is this being changed? This is a FIR specific attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120568

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


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-02-25 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@aaron.ballman Thanks for suggestion. Agree that Having a new Type is a better 
idea. I guess, I will add BTFTagAttributeType which extends AttributeType to 
see whether it works or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120296

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


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-02-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D120296#3345831 , @yonghong-song 
wrote:

> @aaron.ballman Thanks for suggestion. Agree that Having a new Type is a 
> better idea. I guess, I will add BTFTagAttributeType which extends 
> AttributeType to see whether it works or not.

It almost definitely does NOT want to extend AttributedType, but be its own 
type.  VectorType/BitIntType are both somewhat good examples to follow (besides 
the 'dependent' version, since this is C only). That said, make sure you 
implement ExprConstant.cpp's visitors for your type so that you get these types 
to 'work' like normal types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120296

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


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-02-25 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@erichkeane Thanks for suggestion. I will add as an independent type then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120296

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


  1   2   >