r339112 - Fix clash of gcc toolchains in driver regression tests

2018-08-07 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Tue Aug  7 01:10:33 2018
New Revision: 339112

URL: http://llvm.org/viewvc/llvm-project?rev=339112&view=rev
Log:
Fix clash of gcc toolchains in driver regression tests

For some regression tests the path to the right toolchain is specified
using the -sysroot switch. However, if clang was configured with a
custom gcc toolchain (either by using GCC_INSTALL_PREFIX in cmake or the
equivalent configure command), the path to the custom gcc toolchain path
takes precedence to the one specified by sysroot. This causes several
regression tests to fail as they will be using an unexpected path. This
patch fixes this issue by adding --gcc-toolchain='' to all tests that
rely on that. The empty string causes the driver to pick the path from
sysroot instead.

This patch contain the same kind of fixes as done in rC225182

Modified:
cfe/trunk/test/Driver/linux-header-search.cpp
cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/test/Driver/linux-header-search.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-header-search.cpp?rev=339112&r1=339111&r2=339112&view=diff
==
--- cfe/trunk/test/Driver/linux-header-search.cpp (original)
+++ cfe/trunk/test/Driver/linux-header-search.cpp Tue Aug  7 01:10:33 2018
@@ -498,6 +498,7 @@
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target arm-oe-linux-gnueabi -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/openembedded_arm_linux_tree \
+// RUN: --gcc-toolchain="" \
 // RUN:   | FileCheck --check-prefix=CHECK-OE-ARM %s
 
 // CHECK-OE-ARM: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
@@ -509,6 +510,7 @@
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target aarch64-oe-linux -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/openembedded_aarch64_linux_tree \
+// RUN: --gcc-toolchain="" \
 // RUN:   | FileCheck --check-prefix=CHECK-OE-AARCH64 %s
 
 // CHECK-OE-AARCH64: "{{[^"]*}}clang{{[^"]*}}" "-cc1"

Modified: cfe/trunk/test/Driver/linux-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-ld.c?rev=339112&r1=339111&r2=339112&view=diff
==
--- cfe/trunk/test/Driver/linux-ld.c (original)
+++ cfe/trunk/test/Driver/linux-ld.c Tue Aug  7 01:10:33 2018
@@ -1817,6 +1817,7 @@
 // Check whether the OpenEmbedded ARM libs are added correctly.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-oe-linux-gnueabi -rtlib=libgcc \
+// RUN: --gcc-toolchain="" \
 // RUN: --sysroot=%S/Inputs/openembedded_arm_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-OE-ARM %s
 
@@ -1836,6 +1837,7 @@
 // Check whether the OpenEmbedded AArch64 libs are added correctly.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=aarch64-oe-linux -rtlib=libgcc \
+// RUN: --gcc-toolchain="" \
 // RUN: --sysroot=%S/Inputs/openembedded_aarch64_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-OE-AARCH64 %s
 


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


r338831 - Fix unused variable warning in tablegen generated code

2018-08-03 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Fri Aug  3 02:13:15 2018
New Revision: 338831

URL: http://llvm.org/viewvc/llvm-project?rev=338831&view=rev
Log:
Fix unused variable warning in tablegen generated code

Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=338831&r1=338830&r2=338831&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Fri Aug  3 02:13:15 2018
@@ -3274,11 +3274,15 @@ static std::string GenerateCustomApperta
 return "";
   }
 
+  const StringRef CheckCodeValue = Subject.getValueAsString("CheckCode");
+
   OS << "static bool " << FnName << "(const Decl *D) {\n";
-  OS << "  if (const auto *S = dyn_cast<";
-  OS << GetSubjectWithSuffix(Base);
-  OS << ">(D))\n";
-  OS << "return " << Subject.getValueAsString("CheckCode") << ";\n";
+  if (CheckCodeValue != "false") {
+OS << "  if (const auto *S = dyn_cast<";
+OS << GetSubjectWithSuffix(Base);
+OS << ">(D))\n";
+OS << "return " << Subject.getValueAsString("CheckCode") << ";\n";
+  }
   OS << "  return false;\n";
   OS << "}\n\n";
 


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


r312627 - Corrected testcase to work with release build

2017-09-06 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Wed Sep  6 03:12:32 2017
New Revision: 312627

URL: http://llvm.org/viewvc/llvm-project?rev=312627&view=rev
Log:
Corrected testcase to work with release build

The fault was introduced in r312623

Modified:
cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c

Modified: cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c?rev=312627&r1=312626&r2=312627&view=diff
==
--- cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c Wed Sep  6 03:12:32 2017
@@ -6,7 +6,7 @@ void f(_Bool b)
   while (b);
 }
 
-// CHECK: br label %while.cond, !dbg ![[NUM:[0-9]+]]
-// CHECK: br i1 %tobool, label %while.body, label %while.end, !dbg ![[NUM]]
-// CHECK: br label %while.cond, !dbg ![[NUM]], !llvm.loop
+// CHECK: br label {{.*}}, !dbg ![[NUM:[0-9]+]]
+// CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !dbg ![[NUM]]
+// CHECK: br label {{.*}}, !dbg ![[NUM]], !llvm.loop
 // CHECK: ![[NUM]] = !DILocation(line: 6,


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


r312623 - Debug info: Fixed faulty debug locations for attributed statements

2017-09-06 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Wed Sep  6 01:47:18 2017
New Revision: 312623

URL: http://llvm.org/viewvc/llvm-project?rev=312623&view=rev
Log:
Debug info: Fixed faulty debug locations for attributed statements

Summary:
As the attributed statements are considered simple statements no
stoppoint was generated before emitting attributed do/while/for/range-
statement. This lead to faulty debug locations.

Reviewers: echristo, aaron.ballman, dblaikie

Reviewed By: dblaikie

Subscribers: bjope, aprantl, cfe-commits

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

Added:
cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=312623&r1=312622&r2=312623&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Sep  6 01:47:18 2017
@@ -45,7 +45,7 @@ void CodeGenFunction::EmitStopPoint(cons
   }
 }
 
-void CodeGenFunction::EmitStmt(const Stmt *S) {
+void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef Attrs) {
   assert(S && "Null statement?");
   PGO.setCurrentStmt(S);
 
@@ -131,16 +131,16 @@ void CodeGenFunction::EmitStmt(const Stm
   case Stmt::IndirectGotoStmtClass:
 EmitIndirectGotoStmt(cast(*S)); break;
 
-  case Stmt::IfStmtClass:   EmitIfStmt(cast(*S)); 
break;
-  case Stmt::WhileStmtClass:EmitWhileStmt(cast(*S));   
break;
-  case Stmt::DoStmtClass:   EmitDoStmt(cast(*S)); 
break;
-  case Stmt::ForStmtClass:  EmitForStmt(cast(*S));   
break;
-
-  case Stmt::ReturnStmtClass:   EmitReturnStmt(cast(*S)); 
break;
-
-  case Stmt::SwitchStmtClass:   EmitSwitchStmt(cast(*S)); 
break;
-  case Stmt::GCCAsmStmtClass:   // Intentional fall-through.
-  case Stmt::MSAsmStmtClass:EmitAsmStmt(cast(*S));   
break;
+  case Stmt::IfStmtClass:  EmitIfStmt(cast(*S));  
break;
+  case Stmt::WhileStmtClass:   EmitWhileStmt(cast(*S), Attrs); 
break;
+  case Stmt::DoStmtClass:  EmitDoStmt(cast(*S), Attrs);   
break;
+  case Stmt::ForStmtClass: EmitForStmt(cast(*S), Attrs); 
break;
+
+  case Stmt::ReturnStmtClass:  EmitReturnStmt(cast(*S));  
break;
+
+  case Stmt::SwitchStmtClass:  EmitSwitchStmt(cast(*S));  
break;
+  case Stmt::GCCAsmStmtClass:  // Intentional fall-through.
+  case Stmt::MSAsmStmtClass:   EmitAsmStmt(cast(*S));
break;
   case Stmt::CoroutineBodyStmtClass:
 EmitCoroutineBody(cast(*S));
 break;
@@ -178,7 +178,7 @@ void CodeGenFunction::EmitStmt(const Stm
 EmitCXXTryStmt(cast(*S));
 break;
   case Stmt::CXXForRangeStmtClass:
-EmitCXXForRangeStmt(cast(*S));
+EmitCXXForRangeStmt(cast(*S), Attrs);
 break;
   case Stmt::SEHTryStmtClass:
 EmitSEHTryStmt(cast(*S));
@@ -555,23 +555,7 @@ void CodeGenFunction::EmitLabelStmt(cons
 }
 
 void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) {
-  const Stmt *SubStmt = S.getSubStmt();
-  switch (SubStmt->getStmtClass()) {
-  case Stmt::DoStmtClass:
-EmitDoStmt(cast(*SubStmt), S.getAttrs());
-break;
-  case Stmt::ForStmtClass:
-EmitForStmt(cast(*SubStmt), S.getAttrs());
-break;
-  case Stmt::WhileStmtClass:
-EmitWhileStmt(cast(*SubStmt), S.getAttrs());
-break;
-  case Stmt::CXXForRangeStmtClass:
-EmitCXXForRangeStmt(cast(*SubStmt), S.getAttrs());
-break;
-  default:
-EmitStmt(SubStmt);
-  }
+  EmitStmt(S.getSubStmt(), S.getAttrs());
 }
 
 void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=312623&r1=312622&r2=312623&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Sep  6 01:47:18 2017
@@ -2534,7 +2534,7 @@ public:
   /// This function may clear the current insertion point; callers should use
   /// EnsureInsertPoint if they wish to subsequently generate code without 
first
   /// calling EmitBlock, EmitBranch, or EmitStmt.
-  void EmitStmt(const Stmt *S);
+  void EmitStmt(const Stmt *S, ArrayRef Attrs = None);
 
   /// EmitSimpleStmt - Try to emit a "simple" statement which does not
   /// necessarily require an insertion point or debug information; typically

Added: cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c?rev=312623&view=auto
==
--- cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-attributed-stmt.c Wed Sep  6 01:47:18 2017
@@ -0,0 +1,12 @@
+/

r360863 - [builtin] Fixed definitions of builtins that rely on the int/long long type is 32/64 bits

2019-05-16 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Thu May 16 00:18:02 2019
New Revision: 360863

URL: http://llvm.org/viewvc/llvm-project?rev=360863&view=rev
Log:
[builtin] Fixed definitions of builtins that rely on the int/long long type is 
32/64 bits

Summary:
The definition of the builtins __builtin_bswap32, __builtin_bitreverse32, 
__builtin_rotateleft32 and __builtin_rotateright32 rely on that the int type is 
32 bits wide on the target.
The defintions of the builtins __builtin_bswap64, __builtin_bitreverse64, 
__builtin_rotateleft64, and __builtin_rotateright64 rely on that the long long 
type is 64 bits wide.

On targets where this is not the case (e.g. AVR) clang will generate faulty 
code (wrong llvm assembler intrinsics).

This patch add support for using 'Z' (the int32_t type) in Bultins.def. The 
builtins above are changed to be based on the int32_t type instead of the int 
type, and the int64_t type instead of the long long type.

The AVR backend (experimental) have a native int type that is only 16 bits 
wide. The supplied testcase will therefore fail if running the testcase on 
trunk as clang will convert e.g. __builtin_bitreverse32 into 
llvm.bitreverse.i16 on AVR.

Reviewers: dylanmckay, spatel, rsmith, efriedma

Reviewed By: efriedma

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

Added:
cfe/trunk/test/CodeGen/avr-builtins.c
cfe/trunk/test/CodeGen/builtins.cpp
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=360863&r1=360862&r2=360863&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Thu May 16 00:18:02 2019
@@ -50,7 +50,8 @@
 //  L   -> long (e.g. Li for 'long int', Ld for 'long double')
 //  LL  -> long long (e.g. LLi for 'long long int', LLd for __float128)
 //  LLL -> __int128_t (e.g. LLLi)
-//  W   -> int64_t
+//  Z   -> int32_t (require a native 32-bit integer type on the target)
+//  W   -> int64_t (require a native 64-bit integer type on the target)
 //  N   -> 'int' size if target is LP64, 'L' otherwise.
 //  S   -> signed
 //  U   -> unsigned
@@ -418,25 +419,27 @@ BUILTIN(__builtin_clrsb  , "ii"  , "nc")
 BUILTIN(__builtin_clrsbl , "iLi" , "nc")
 BUILTIN(__builtin_clrsbll, "iLLi", "nc")
 
-// FIXME: These type signatures are not correct for targets with int != 32-bits
-// or with ULL != 64-bits.
+// The following builtins rely on that char == 8 bits, short == 16 bits and 
that
+// there exists native types on the target that are 32- and 64-bits wide, 
unless
+// these conditions are fulfilled these builtins will operate on a not intended
+// bitwidth.
 BUILTIN(__builtin_bswap16, "UsUs", "nc")
-BUILTIN(__builtin_bswap32, "UiUi", "nc")
-BUILTIN(__builtin_bswap64, "ULLiULLi", "nc")
+BUILTIN(__builtin_bswap32, "UZiUZi", "nc")
+BUILTIN(__builtin_bswap64, "UWiUWi", "nc")
 
 BUILTIN(__builtin_bitreverse8, "UcUc", "nc")
 BUILTIN(__builtin_bitreverse16, "UsUs", "nc")
-BUILTIN(__builtin_bitreverse32, "UiUi", "nc")
-BUILTIN(__builtin_bitreverse64, "ULLiULLi", "nc")
+BUILTIN(__builtin_bitreverse32, "UZiUZi", "nc")
+BUILTIN(__builtin_bitreverse64, "UWiUWi", "nc")
 
 BUILTIN(__builtin_rotateleft8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateleft16, "UsUsUs", "nc")
-BUILTIN(__builtin_rotateleft32, "UiUiUi", "nc")
-BUILTIN(__builtin_rotateleft64, "ULLiULLiULLi", "nc")
+BUILTIN(__builtin_rotateleft32, "UZiUZiUZi", "nc")
+BUILTIN(__builtin_rotateleft64, "UWiUWiUWi", "nc")
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
-BUILTIN(__builtin_rotateright32, "UiUiUi", "nc")
-BUILTIN(__builtin_rotateright64, "ULLiULLiULLi", "nc")
+BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=360863&r1=360862&r2=360863&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu May 16 00:18:02 2019
@@ -9286,7 +9286,7 @@ static QualType DecodeTypeFromStr(const
   // Read the prefixed modifiers first.
   bool Done = false;
   #ifndef NDEBUG
-  bool IsSpecialLong = false;
+  bool IsSpecial = false;
   #endif
   while (!Done) {
 switch (*Str++) {
@@ -9305,26 +9305,26 @@ static QualType DecodeTypeFromStr(const
   Unsigned = true;
   break;
 case 'L':
-  assert(!IsSpecialLong && "Can't use 'L' with 'W' or 'N' modifiers");
+  assert(!IsSpecial && "Can't use 'L' with 'W', 'N' or 'Z' modifiers");
   assert(HowLong <= 2 && "Can't have  modifier");
   ++HowLong;
   br

r371969 - Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Mon Sep 16 02:52:23 2019
New Revision: 371969

URL: http://llvm.org/viewvc/llvm-project?rev=371969&view=rev
Log:
Change signature of __builtin_rotateright64 back to unsigned

The signature of __builtin_rotateright64 was by misstake changed from
unsigned to signed in r360863, this patch will change it back to
unsigned as intended.

This fixes pr43309

Reviewers: efriedma, hans

Reviewed By: hans

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

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/test/CodeGen/avr-builtins.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=371969&r1=371968&r2=371969&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Sep 16 02:52:23 2019
@@ -461,7 +461,7 @@ BUILTIN(__builtin_rotateleft64, "UWiUWiU
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")

Modified: cfe/trunk/test/CodeGen/avr-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avr-builtins.c?rev=371969&r1=371968&r2=371969&view=diff
==
--- cfe/trunk/test/CodeGen/avr-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avr-builtins.c Mon Sep 16 02:52:23 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
 
+// Check that the parameter types match. This verifies pr43309.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }


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


r331438 - Fix -Wunused-variable warning in Clang.cpp

2018-05-03 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Wed May  2 22:53:29 2018
New Revision: 331438

URL: http://llvm.org/viewvc/llvm-project?rev=331438&view=rev
Log:
Fix -Wunused-variable warning in Clang.cpp

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331438&r1=331437&r2=331438&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed May  2 22:53:29 2018
@@ -1485,7 +1485,7 @@ void Clang::AddAArch64TargetArgs(const A
   CmdArgs.push_back("-aarch64-enable-global-merge=true");
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_foutline)) {
+  if (Args.getLastArg(options::OPT_foutline)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-enable-machine-outliner");
   }


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


[clang-tools-extra] 39e9149 - Fix unused variable warning in Protocol.cpp, NFCI

2020-04-06 Thread Karl-Johan Karlsson via cfe-commits

Author: Karl-Johan Karlsson
Date: 2020-04-07T08:39:17+02:00
New Revision: 39e9149d8e12d77cd389f55860ac2cb9a30b4552

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

LOG: Fix unused variable warning in Protocol.cpp, NFCI

Fixed gcc warning:
clang-tools-extra/clangd/Protocol.cpp:300:16: warning: unused variable 
'SemanticHighlighting' [-Wunused-variable]

Added: 


Modified: 
clang-tools-extra/clangd/Protocol.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index cd8e6bc10dce..aa7b901da3f0 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -297,7 +297,7 @@ bool fromJSON(const llvm::json::Value &Params, 
ClientCapabilities &R) {
   SemanticHighlighting->getBoolean("semanticHighlighting"))
 R.TheiaSemanticHighlighting = *SemanticHighlightingSupport;
 }
-if (auto *SemanticHighlighting = TextDocument->getObject("semanticTokens"))
+if (TextDocument->getObject("semanticTokens"))
   R.SemanticTokens = true;
 if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
   if (auto CategorySupport = Diagnostics->getBoolean("categorySupport"))



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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-05 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/74440

In gcc there exist a modifier option -Wformat-signedness that turns on 
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef60..c267a32be4d6f 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc12..a9562e7d8dcb0 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..04fdf9a7eb92d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a2..670cde017d3ac 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedn

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-05 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/2] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef60..c267a32be4d6f 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc12..a9562e7d8dcb0 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..04fdf9a7eb92d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a2..670cde017d3ac 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 break;
  

[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-05 Thread Karl-Johan Karlsson via cfe-commits


@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,

karka228 wrote:

I have tried to mimic the gcc behavior when implementing this and in gcc it 
seems like -Wformat-signedness don't introduce a new warning but only modify 
the behavior of the already existing -Wformat warning.
If I place the warning option config in 
clang/include/clang/Basic/DiagnosticSemaKinds.td as you suggest don't I then 
also create a new warning with a new warning text? ... that is not what gcc do 
(as far as I understand).

Well, with that said we don't have to follow exactly how gcc implemented this 
if we think there is a better way to implement this in clang.

I agree that support for -Wno-format-signednes is missing from my patch and 
that should be added.


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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-06 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> I'd like to understand the need for this diagnostic a bit more. I realize GCC 
> has it, but it's off-by-default in GCC and `-Wformat` does not enable it 
> either: https://godbolt.org/z/Gxczsjdj5
> 
> We believe that users don't enable off by default warnings often enough to 
> warrant supporting them, and this feels like a very pedantic warning in many 
> cases. e.g., `printf("%u", 0);`

I work on an out of tree backend and our customers requested the warning 
-Wformat-signedness to be implemented in clang (as they found it in gcc). I 
agree that the warning is pedantic. Note that gcc will with the options 
-Wformat and -pedantic enable at least the warnings related to scanf (see 
https://godbolt.org/z/WjzWKj89G). 

If you feel that the clang community don't really want -Wformat-signedness I 
can simply implement this in our downstream llvm-project repo and abandon this 
pull request. We already have a large number of diffs compared to 
https://github.com/llvm/llvm-project and a few more probably don't make any 
difference.


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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-06 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

I have started to implement defining the -Wformat-signedness option config in 
clang/include/clang/Basic/DiagnosticSemaKinds.td as suggested originally by 
@hazohelet and I agree that the implementation is a lot cleaner that way.
However before finishing implementing that I think we need to conclude what 
level of gcc compatibility that we aim for in clang.

Below I list the characteristics of -Wformat-signedness that I have seen by 
testing it out in gcc and reading the gcc documentation (I have not inspected 
the gcc source code):

1. The option -Wformat-signedness is default off.
2. The -Wformat-signedness warnings are not enabled alone by the -Wformat 
option.
3. The -Wformat-signedness warnings are not enabled alone by the 
-Wformat-signedness option.
4. The -Wformat-signedness warnings are enabled by the option -Wformat together 
with the option -Wformat-signedness.
5. Parts of the -Wformat-signedness warnings (regarding scanf) are enabled by 
the options -Wformat together with the option -pedantic.
6. Warnings produced by -Wformat-signedness is reported as a -Wformat warnings 
(e.g "warning: format ‘%u’ expects argument of type ‘unsigned int’, but 
argument 2 has type ‘int’ [-Wformat=]"
7. Warnings produced by -Wformat-signedness can be suppressed by "#pragma GCC 
diagnostic ignored -Wformat"

Which of the above points are important for us to follow in clang to get a 
reasonable gcc compatibility?
To me I think point 1, 2 and maybe 7 is the most important to follow.

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-07 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/3] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef608..c267a32be4d6f4 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d9..04fdf9a7eb92d6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a24..670cde017d3ac2 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-08 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/4] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef60..c267a32be4d6f 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc12..a9562e7d8dcb0 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..04fdf9a7eb92d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a2..670cde017d3ac 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 break;
  

[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-08 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/5] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef608..c267a32be4d6f4 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d9..04fdf9a7eb92d6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a24..670cde017d3ac2 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> > 1. The option -Wformat-signedness is default off.
> > 
> > 2. The -Wformat-signedness warnings are not enabled alone by the -Wformat 
> > option.
> > 
> > 3. The -Wformat-signedness warnings are not enabled alone by the 
> > -Wformat-signedness option.
> > 
> > 4. The -Wformat-signedness warnings are enabled by the option -Wformat 
> > together with the option -Wformat-signedness.
> > 
> > 5. Parts of the -Wformat-signedness warnings (regarding scanf) are enabled 
> > by the options -Wformat together with the option -pedantic.
> > 
> > 6. Warnings produced by -Wformat-signedness is reported as a -Wformat 
> > warnings (e.g "warning: format ‘%u’ expects argument of type ‘unsigned 
> > int’, but argument 2 has type ‘int’ [-Wformat=]"
> > 
> > 7. Warnings produced by -Wformat-signedness can be suppressed by "#pragma 
> > GCC diagnostic ignored -Wformat"
>
> I agree, 1, 2, 4 (same idea as 2, basically), and 7 are the critical things 
> we'd need for compatibility. I personally find 3, 5, and 6 to be kind of 
> strange behavior though I can see how it would arise.

Good, then I know what the implementation have to adhere too. I agree that 
there are some strange behavior in the gcc implementation.

I think the first commit in my warn_format_signedness branch adhered to the 
important 1, 2, 4 and 7 points, but it implemented -Wformat-signedness as a 
simple clang option.

However when defining the option config in DiagnosticSemaKinds.td it will be a 
bit harder to implement. Too be able to handle 7) I simply have to add 
-Wformat-signedness to the -Wformat group, but then the implementation will 
violate 2). As far as I understand this can't be configured with the current 
framework. I need to extend the tablegen backend ClangDiagnosticsEmitter with 
some kind of new option to handle this, right?


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Alternatively, you could probably use `DiagnosticsEngine::isIgnored` to check 
> if the `-Wformat-signedness` is enabled or not, and control whether 
> `MatchSignedNess` is `NoMatch` or `Match`, as your first implementation did. 
> This way we can achieve GCC compatibility for 1, 2, 3, 4, 6, 7, while 
> benefitting from a real warning flag. However, in this implementation 
> `-Wformat-signedness` would be an _dummy warning_ which never gets emitted. 
> As far as I know, there isn't anything similar in the codebase, so it might 
> not be the ideal way.

A bit ugly with a _dummy warning_, but it simplifies the implementation. What 
do you other think? Is this an acceptable solution or not?

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/6] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef60..c267a32be4d6f 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc12..a9562e7d8dcb0 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..04fdf9a7eb92d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a2..670cde017d3ac 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 break;
  

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-18 Thread Karl-Johan Karlsson via cfe-commits


@@ -11881,6 +11896,8 @@ CheckPrintfHandler::checkFormatExpr(const 
analyze_printf::PrintfSpecifier &FS,
   ICE->getType() == S.Context.UnsignedIntTy) {
 // All further checking is done on the subexpression
 ImplicitMatch = AT.matchesType(S.Context, ExprTy);

karka228 wrote:

After more testing I have found out that this call to AT.matchesTypes (row 
11898) can introduce new normal -Wformat warnings that should not occur. This 
happens if the above call to AT.matchesTypes (row 11875) return 
ArgType::NoMatchSignedness that is not returned at this call to AT.matchesTypes 
(row 11898) as we are looking through the promoted int type, but instead we get 
ArgType::NoMatch returned.
This mean that if the original AT.matchesTypes at row 11875 return a signedness 
match then this this call to AT.matchesTypes (row 11898) also must return a 
signedness match for us to report a new warning, otherwise we might introduce 
unwanted warnings. I will update the code to fix this ...

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-18 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From a80bf9d03f19d48c0aca4af7758dc49516da8825 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/7] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index 5c4ad9baaef608..c267a32be4d6f4 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -264,6 +264,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d9..04fdf9a7eb92d6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -918,6 +918,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a24..670cde017d3ac2 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -409,7 +409,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -419,44 +419,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-01-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

Ping. Lets pickup the discussion from before Christmas. Is the solution with 
the dummy warning (that @hazohelet wrote about in a previous comment) an 
acceptable solution?


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Sorry for the delayed response, this fell off my radar (thanks @Endilll for 
> mentioning this after meeting with @hazohelet!).

No problem. As I wrote above I work in an out of tree backend and I have 
already implemented this in our downstream repo. Our customer that requested 
this already have this feature. To me this is not at all urgent.

> This would be novel but might not be a terrible approach. I'm not convinced 
> that #3 is a particularly good design (and #6 doesn't seem critical to me 
> either), but I think modifying tablegen to improve support here would be a 
> heavy lift for little benefit. I'd say let's try that approach and see how we 
> like it, and go from there. WDYT?

Sounds good. I think what is currently implemented in this pull request use 
@hazohelet  idea with the dummy warning. As this was started in December I 
think I have to rebase this onto a more recent main branch.

I will look through the code in the pull request (as it was a while ago since I 
looked at this) and do the rebase ...


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/7] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-25 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Can you also add a test showing the difference between `-Wformat 
> -Wformat-signedness` and `-Wformat-signedness` by itself (which does nothing)?

With the current implementation `-Wformat-signedness` by itself actually turn 
on the signedness warnings. This is not compatible with how gcc do it. I guess 
I have thought that it was not that important to be compatible with gcc in this 
respect. However if it is I guess this could be implemented.

> I'd also like to see a test demonstrating that `#pragma GCC diagnostic 
> ignored -Wformat` disables the signedness warnings.

There is a single test in the end of 
clang/test/Sema/format-strings-signedness.c that demonstrate this.


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-25 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/8] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/9] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> > With the current implementation `-Wformat-signedness` by itself actually 
> > turn on the signedness warnings. This is not compatible with how gcc do it. 
> > I guess I have thought that it was not that important to be compatible with 
> > gcc in this respect. However if it is I guess this could be implemented.
> 
> Personally, I find GCC's behavior a bit surprising, so I'm okay with a 
> divergence there.

Sorry, I'm confused. Ignore what I said above. What is not compatible with gcc 
is only that -Wformat is turned on default by clang and not by gcc. The 
handling of `-Wformat-signedness` is as far as I can tell compatible with gcc.

> But we should have tests for this just the same:
> 
> * `-Wformat-signedness`
> 
> * `-Wformat-signedness -Wno-format`
> 
> * `-Wno-format -Wformat-signedness`

I agree, it is good to have tests of those combinations. I have now added them 
to clang/test/Sema/format-strings-signedness.c


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s

karka228 wrote:

Ohh, I didn't know that you could supply a prefix to `-verify`.  I will fix 
this.

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,223 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat -Wformat-signedness %s
+
+// Verify that -Wformat-signedness alone (without -Wformat) trigger the
+// warnings. Note in gcc this will not trigger the signedness warnings as
+// -Wformat is default off in gcc.
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -std=c11 -fsyntax-only -verify 
-Wformat-signedness %s
+
+// Verify that -Wformat-signedness warnings are not reported with only -Wformat
+// (gcc compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-Werror %s
+
+// Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -Werror %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -Werror %s
+
+#include 

karka228 wrote:

Sure I remove the include and use the expanded macro instead.


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-26 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 01/10] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-31 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> LGTM!

Thanks. I will rebase and then "squash and merge" this to the main branch.


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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-31 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From 1dd6c32ee8e053c900e23f37d50f8c3f4868858a Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 01/10] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 04eb87f0d5d1aa..55891e85f8333e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-31 Thread Karl-Johan Karlsson via cfe-commits

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-01-29 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

Ping.

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-18 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/69521

Constant values of _BitInt have the bitwith to exactly fit the constant number. 
This patch fix a problem in Sema when building an APInt where the supplied 
bitwidth can become too small and simply truncate the value leading to a faulty 
warning.


>From a9bfc65f6d6b0953cd762f851fb6044e1c4b8ab8 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 18 Oct 2023 16:40:53 +0200
Subject: [PATCH] [Sema] Fixed faulty shift count warning

Constant values of _BitInt have the bitwith to exactly fit the constant
number. This patch fix a problem in Sema when building an APInt where the
supplied bitwidth can become too small and simply truncate the value leading to
a faulty warning.
---
 clang/lib/Sema/SemaExpr.cpp  |  7 +++
 clang/test/Sema/c2x-expr-range.c | 12 
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index aa30a3a03887558..c00178ee1835e00 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12120,8 +12120,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
   }
-  llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
-  if (Right.uge(LeftBits)) {
+  if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
 << RHS.get()->getSourceRange());
@@ -12163,7 +12162,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 
   llvm::APInt ResultBits =
   static_cast(Right) + Left.getSignificantBits();
-  if (LeftBits.uge(ResultBits))
+  if (ResultBits.ule(LeftSize))
 return;
   llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
   Result = Result.shl(Right);
@@ -12177,7 +12176,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   // bugs -- if the result is cast back to an unsigned type, it will have the
   // expected value. Thus we place this behind a different warning that can be
   // turned off separately if needed.
-  if (LeftBits == ResultBits - 1) {
+  if (ResultBits - 1 == LeftSize) {
 S.Diag(Loc, diag::warn_shift_result_sets_sign_bit)
 << HexResult << LHSType
 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
diff --git a/clang/test/Sema/c2x-expr-range.c b/clang/test/Sema/c2x-expr-range.c
index 73683e6bfe684aa..eff0b7cd4d9f546 100644
--- a/clang/test/Sema/c2x-expr-range.c
+++ b/clang/test/Sema/c2x-expr-range.c
@@ -12,3 +12,15 @@ void test1(int *a) {
 void test2(__uint128_t *a) {
   (void)(*a >> ((__uint128_t)__UINT64_MAX__ + 1) <= 0); // expected-warning 
{{shift count >= width of type}}
 }
+
+// Regression test for bug where a faulty warning was given. We don't expect to
+// see any warning in this case.
+_BitInt(128) test3(_BitInt(128) a) {
+  return a << 12wb;
+}
+
+// Similar to test3 above, but with a too large shift count. We expect to see a
+// warning in this case.
+_BitInt(128) test4(_BitInt(128) a) {
+  return a << 129wb; // expected-warning {{shift count >= width of type}}
+}

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-19 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/69521

>From a9bfc65f6d6b0953cd762f851fb6044e1c4b8ab8 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 18 Oct 2023 16:40:53 +0200
Subject: [PATCH 1/2] [Sema] Fixed faulty shift count warning

Constant values of _BitInt have the bitwith to exactly fit the constant
number. This patch fix a problem in Sema when building an APInt where the
supplied bitwidth can become too small and simply truncate the value leading to
a faulty warning.
---
 clang/lib/Sema/SemaExpr.cpp  |  7 +++
 clang/test/Sema/c2x-expr-range.c | 12 
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index aa30a3a03887558..c00178ee1835e00 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12120,8 +12120,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
   }
-  llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
-  if (Right.uge(LeftBits)) {
+  if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
 << RHS.get()->getSourceRange());
@@ -12163,7 +12162,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 
   llvm::APInt ResultBits =
   static_cast(Right) + Left.getSignificantBits();
-  if (LeftBits.uge(ResultBits))
+  if (ResultBits.ule(LeftSize))
 return;
   llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
   Result = Result.shl(Right);
@@ -12177,7 +12176,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   // bugs -- if the result is cast back to an unsigned type, it will have the
   // expected value. Thus we place this behind a different warning that can be
   // turned off separately if needed.
-  if (LeftBits == ResultBits - 1) {
+  if (ResultBits - 1 == LeftSize) {
 S.Diag(Loc, diag::warn_shift_result_sets_sign_bit)
 << HexResult << LHSType
 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
diff --git a/clang/test/Sema/c2x-expr-range.c b/clang/test/Sema/c2x-expr-range.c
index 73683e6bfe684aa..eff0b7cd4d9f546 100644
--- a/clang/test/Sema/c2x-expr-range.c
+++ b/clang/test/Sema/c2x-expr-range.c
@@ -12,3 +12,15 @@ void test1(int *a) {
 void test2(__uint128_t *a) {
   (void)(*a >> ((__uint128_t)__UINT64_MAX__ + 1) <= 0); // expected-warning 
{{shift count >= width of type}}
 }
+
+// Regression test for bug where a faulty warning was given. We don't expect to
+// see any warning in this case.
+_BitInt(128) test3(_BitInt(128) a) {
+  return a << 12wb;
+}
+
+// Similar to test3 above, but with a too large shift count. We expect to see a
+// warning in this case.
+_BitInt(128) test4(_BitInt(128) a) {
+  return a << 129wb; // expected-warning {{shift count >= width of type}}
+}

>From a57f7401a691c865bf12740dd5b85e330bb6a0ca Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Fri, 20 Oct 2023 05:57:10 +0200
Subject: [PATCH 2/2] [Sema] Fixed faulty shift count warning

Added a line about this in the release note.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81cbfd90155fe0b..0d2ac4e29f6f41e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -400,6 +400,9 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 `_)
+- Fixed an issue when a shift count specified by a small constant 
``_BitInt()``,
+  in a left shift operation, could result in a faulty warnings about
+  ``shift count >= width of type``.
 
 Bug Fixes to Compiler Builtins
 ^^

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-24 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

Ping

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-24 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/69521

>From a4a9fb73de9319acd26290ef31d1e17b127c0c3b Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 18 Oct 2023 16:40:53 +0200
Subject: [PATCH] [Sema] Fixed faulty shift count warning

Constant values of _BitInt have the bitwith to exactly fit the constant
number. This patch fix a problem in Sema when building an APInt where the
supplied bitwidth can become too small and simply truncate the value leading to
a faulty warning.
---
 clang/docs/ReleaseNotes.rst  |  3 +++
 clang/lib/Sema/SemaExpr.cpp  |  7 +++
 clang/test/Sema/c2x-expr-range.c | 12 
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cdef43f2011bc98..05bb069fe709700 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -403,6 +403,9 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 `_)
+- Fixed an issue when a shift count specified by a small constant 
``_BitInt()``,
+  in a left shift operation, could result in a faulty warnings about
+  ``shift count >= width of type``.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index aa30a3a03887558..c00178ee1835e00 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12120,8 +12120,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
   }
-  llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
-  if (Right.uge(LeftBits)) {
+  if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
 << RHS.get()->getSourceRange());
@@ -12163,7 +12162,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 
   llvm::APInt ResultBits =
   static_cast(Right) + Left.getSignificantBits();
-  if (LeftBits.uge(ResultBits))
+  if (ResultBits.ule(LeftSize))
 return;
   llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
   Result = Result.shl(Right);
@@ -12177,7 +12176,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   // bugs -- if the result is cast back to an unsigned type, it will have the
   // expected value. Thus we place this behind a different warning that can be
   // turned off separately if needed.
-  if (LeftBits == ResultBits - 1) {
+  if (ResultBits - 1 == LeftSize) {
 S.Diag(Loc, diag::warn_shift_result_sets_sign_bit)
 << HexResult << LHSType
 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
diff --git a/clang/test/Sema/c2x-expr-range.c b/clang/test/Sema/c2x-expr-range.c
index 73683e6bfe684aa..eff0b7cd4d9f546 100644
--- a/clang/test/Sema/c2x-expr-range.c
+++ b/clang/test/Sema/c2x-expr-range.c
@@ -12,3 +12,15 @@ void test1(int *a) {
 void test2(__uint128_t *a) {
   (void)(*a >> ((__uint128_t)__UINT64_MAX__ + 1) <= 0); // expected-warning 
{{shift count >= width of type}}
 }
+
+// Regression test for bug where a faulty warning was given. We don't expect to
+// see any warning in this case.
+_BitInt(128) test3(_BitInt(128) a) {
+  return a << 12wb;
+}
+
+// Similar to test3 above, but with a too large shift count. We expect to see a
+// warning in this case.
+_BitInt(128) test4(_BitInt(128) a) {
+  return a << 129wb; // expected-warning {{shift count >= width of type}}
+}

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-24 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/69521

>From db4a254b721eddacf592a647d3de4fd10a8032e0 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 18 Oct 2023 16:40:53 +0200
Subject: [PATCH] [Sema] Fixed faulty shift count warning

Constant values of _BitInt have the bitwith to exactly fit the constant
number. This patch fix a problem in Sema when building an APInt where the
supplied bitwidth can become too small and simply truncate the value leading to
a faulty warning.
---
 clang/docs/ReleaseNotes.rst  |  3 +++
 clang/lib/Sema/SemaExpr.cpp  |  7 +++
 clang/test/Sema/c2x-expr-range.c | 12 
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a063733e96cb74c..4cc148905d4e130 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -488,6 +488,9 @@ Bug Fixes in This Version
 - Clang no longer permits using the `_BitInt` types as an underlying type for 
an
   enumeration as specified in the C23 Standard.
   Fixes (`#69619 `_)
+- Fixed an issue when a shift count specified by a small constant 
``_BitInt()``,
+  in a left shift operation, could result in a faulty warnings about
+  ``shift count >= width of type``.
 - Clang now accepts anonymous members initialized with designated initializers
   inside templates.
   Fixes (`#65143 `_)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 895b22805860d98..c2772bfb71c77e9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12143,8 +12143,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
   }
-  llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
-  if (Right.uge(LeftBits)) {
+  if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
 << RHS.get()->getSourceRange());
@@ -12186,7 +12185,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
 
   llvm::APInt ResultBits =
   static_cast(Right) + Left.getSignificantBits();
-  if (LeftBits.uge(ResultBits))
+  if (ResultBits.ule(LeftSize))
 return;
   llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
   Result = Result.shl(Right);
@@ -12200,7 +12199,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   // bugs -- if the result is cast back to an unsigned type, it will have the
   // expected value. Thus we place this behind a different warning that can be
   // turned off separately if needed.
-  if (LeftBits == ResultBits - 1) {
+  if (ResultBits - 1 == LeftSize) {
 S.Diag(Loc, diag::warn_shift_result_sets_sign_bit)
 << HexResult << LHSType
 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
diff --git a/clang/test/Sema/c2x-expr-range.c b/clang/test/Sema/c2x-expr-range.c
index 73683e6bfe684aa..eff0b7cd4d9f546 100644
--- a/clang/test/Sema/c2x-expr-range.c
+++ b/clang/test/Sema/c2x-expr-range.c
@@ -12,3 +12,15 @@ void test1(int *a) {
 void test2(__uint128_t *a) {
   (void)(*a >> ((__uint128_t)__UINT64_MAX__ + 1) <= 0); // expected-warning 
{{shift count >= width of type}}
 }
+
+// Regression test for bug where a faulty warning was given. We don't expect to
+// see any warning in this case.
+_BitInt(128) test3(_BitInt(128) a) {
+  return a << 12wb;
+}
+
+// Similar to test3 above, but with a too large shift count. We expect to see a
+// warning in this case.
+_BitInt(128) test4(_BitInt(128) a) {
+  return a << 129wb; // expected-warning {{shift count >= width of type}}
+}

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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-25 Thread Karl-Johan Karlsson via cfe-commits

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


[clang-tools-extra] 7055cd4 - Remove extra ';', NFC

2020-03-26 Thread Karl-Johan Karlsson via cfe-commits

Author: Karl-Johan Karlsson
Date: 2020-03-26T11:23:59+01:00
New Revision: 7055cd42b5ffc88757eb3d12192047abe63a3714

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

LOG: Remove extra ';', NFC

Fixed gcc -Wpedantic warning about extra ';'

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 1d41f0a3e046..63fe6b1d756c 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -525,13 +525,13 @@ bool isParagraphLineBreak(llvm::StringRef Str, size_t 
LineBreakIndex) {
   return Str.substr(LineBreakIndex + 1)
   .drop_while([](auto C) { return C == ' ' || C == '\t'; })
   .startswith("\n");
-};
+}
 
 bool isPunctuationLineBreak(llvm::StringRef Str, size_t LineBreakIndex) {
   constexpr llvm::StringLiteral Punctuation = R"txt(.:,;!?)txt";
 
   return LineBreakIndex > 0 && Punctuation.contains(Str[LineBreakIndex - 1]);
-};
+}
 
 bool isFollowedByHardLineBreakIndicator(llvm::StringRef Str,
 size_t LineBreakIndex) {
@@ -556,7 +556,7 @@ bool isFollowedByHardLineBreakIndicator(llvm::StringRef Str,
Str[NextNonSpaceCharIndex + 1] == ')');
 
   return FollowedBySingleCharIndicator || FollowedByNumberedListIndicator;
-};
+}
 
 bool isHardLineBreak(llvm::StringRef Str, size_t LineBreakIndex) {
   return isPunctuationLineBreak(Str, LineBreakIndex) ||



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


[clang] e8efac4 - [clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths

2019-12-20 Thread Karl-Johan Karlsson via cfe-commits

Author: Karl-Johan Karlsson
Date: 2019-12-20T09:16:33+01:00
New Revision: e8efac4b15303932581c128dc3976f4359388338

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

LOG: [clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths

In the current implementation of clang the canonicalization of paths in
diagnostic messages (when using -fdiagnostics-absolute-paths) only works
if the symbolic link is in the directory part of the filename, not if
the file itself is a symbolic link to another file.

This patch adds support to canonicalize the complete path including the
file.

Reviewers: rsmith, hans, rnk, ikudrin

Reviewed By: rnk

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

Added: 
clang/test/Frontend/absolute-paths-symlinks.c

Modified: 
clang/include/clang/Basic/FileManager.h
clang/lib/Basic/FileManager.cpp
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 28cd05818087..fed43786d410 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -222,8 +222,8 @@ class FileManager : public RefCountedBase {
   llvm::BumpPtrAllocator>
   SeenFileEntries;
 
-  /// The canonical names of directories.
-  llvm::DenseMap CanonicalDirNames;
+  /// The canonical names of files and directories .
+  llvm::DenseMap CanonicalNames;
 
   /// Storage for canonical names that we have computed.
   llvm::BumpPtrAllocator CanonicalNameStorage;
@@ -421,6 +421,13 @@ class FileManager : public RefCountedBase {
   /// required, which is (almost) never.
   StringRef getCanonicalName(const DirectoryEntry *Dir);
 
+  /// Retrieve the canonical name for a given file.
+  ///
+  /// This is a very expensive operation, despite its results being cached,
+  /// and should only be used when the physical layout of the file system is
+  /// required, which is (almost) never.
+  StringRef getCanonicalName(const FileEntry *File);
+
   void PrintStats() const;
 };
 

diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index b4f0a35e0d09..079a4bbfc82f 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -548,10 +548,9 @@ void FileManager::GetUniqueIDMapping(
 }
 
 StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
-  // FIXME: use llvm::sys::fs::canonical() when it gets implemented
-  llvm::DenseMap::iterator Known
-= CanonicalDirNames.find(Dir);
-  if (Known != CanonicalDirNames.end())
+  llvm::DenseMap::iterator Known
+= CanonicalNames.find(Dir);
+  if (Known != CanonicalNames.end())
 return Known->second;
 
   StringRef CanonicalName(Dir->getName());
@@ -560,7 +559,23 @@ StringRef FileManager::getCanonicalName(const 
DirectoryEntry *Dir) {
   if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
 CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
 
-  CanonicalDirNames.insert({Dir, CanonicalName});
+  CanonicalNames.insert({Dir, CanonicalName});
+  return CanonicalName;
+}
+
+StringRef FileManager::getCanonicalName(const FileEntry *File) {
+  llvm::DenseMap::iterator Known
+= CanonicalNames.find(File);
+  if (Known != CanonicalNames.end())
+return Known->second;
+
+  StringRef CanonicalName(File->getName());
+
+  SmallString<4096> CanonicalNameBuf;
+  if (!FS->getRealPath(File->getName(), CanonicalNameBuf))
+CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
+
+  CanonicalNames.insert({File, CanonicalName});
   return CanonicalName;
 }
 

diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 7bb6c5b74d5f..78acaaf9f96e 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -761,11 +761,12 @@ void TextDiagnostic::printDiagnosticMessage(raw_ostream 
&OS,
 }
 
 void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) 
{
-  SmallVector AbsoluteFilename;
+#ifdef _WIN32
+  SmallString<4096> TmpFilename;
+#endif
   if (DiagOpts->AbsolutePath) {
-auto Dir = SM.getFileManager().getDirectory(
-llvm::sys::path::parent_path(Filename));
-if (Dir) {
+auto File = SM.getFileManager().getFile(Filename);
+if (File) {
   // We want to print a simplified absolute path, i. e. without "dots".
   //
   // The hardest part here are the paths like "//../".
@@ -781,16 +782,14 @@ void TextDiagnostic::emitFilename(StringRef Filename, 
const SourceManager &SM) {
   // on Windows we can just use llvm::sys::path::remove_dots(), because,
   // on that system, both aforementioned paths point to the same place.
 #ifdef _WIN32
-  SmallString<4096> DirNam

[clang] 073cdb2 - [clang][test] Minor fixes in testcase absolute-paths-symlinks.c

2019-12-26 Thread Karl-Johan Karlsson via cfe-commits

Author: Karl-Johan Karlsson
Date: 2019-12-26T09:33:21+01:00
New Revision: 073cdb239044dc056a3c79b995265f640ffb40e6

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

LOG: [clang][test] Minor fixes in testcase absolute-paths-symlinks.c

This is a follow up commit to address post-commit comment in D70527.

Added: 


Modified: 
clang/test/Frontend/absolute-paths-symlinks.c

Removed: 




diff  --git a/clang/test/Frontend/absolute-paths-symlinks.c 
b/clang/test/Frontend/absolute-paths-symlinks.c
index e91a96fc0922..8170910b6f6e 100644
--- a/clang/test/Frontend/absolute-paths-symlinks.c
+++ b/clang/test/Frontend/absolute-paths-symlinks.c
@@ -1,9 +1,9 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: cd %t
-// RUN: cp "%s" "test.c"
-// RUN: ln -sf "test.c" "link.c"
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths "link.c" 
2>&1|FileCheck %s
+// RUN: cp %s test.c
+// RUN: ln -sf test.c link.c
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths link.c 2>&1 
| FileCheck %s
 
 // Verify that -fdiagnostics-absolute-paths resolve symbolic links in
 // diagnostics messages.
@@ -13,3 +13,5 @@
 This do not compile
 
 // REQUIRES: shell
+// Don't make symlinks on Windows.
+// UNSUPPORTED: system-windows



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


[clang] [test][OpenMP] Avoid writing to a potentially write-protected dir (PR #94931)

2024-06-09 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/94931

The test clang/test/OpenMP/error_unsupport_feature.c don't check the output 
written to the current directory. The current directory may be write protected 
e.g. in a sandboxed environment.

This patch replace the -emit-llvm option with -fsyntax-only as it don't care 
about the outputed llvm IR.

>From c5b2765d9f4bd2a8412c0722a052148673411f94 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 10 Jun 2024 07:45:48 +0200
Subject: [PATCH] [test][OpenMP] Avoid writing to a potentially write-protected
 dir

The test clang/test/OpenMP/error_unsupport_feature.c don't check the output
written to the current directory. The current directory may be write protected
e.g. in a sandboxed environment.

This patch replace the -emit-llvm option with -fsyntax-only as it don't care
about the outputed llvm IR.
---
 clang/test/OpenMP/error_unsupport_feature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/error_unsupport_feature.c 
b/clang/test/OpenMP/error_unsupport_feature.c
index 611a8b4639c44..2dc485e20dbb7 100644
--- a/clang/test/OpenMP/error_unsupport_feature.c
+++ b/clang/test/OpenMP/error_unsupport_feature.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -verify -fopenmp %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fopenmp %s
 
 int main () {
   int r = 0;

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


[clang] [test][OpenMP] Avoid writing to a potentially write-protected dir (PR #94931)

2024-06-09 Thread Karl-Johan Karlsson via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -verify -fopenmp %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fopenmp %s

karka228 wrote:

It seems like this was a bad idea. When I test this locally this test works for 
me, but it seems like the it fail in the tests by 
buildkite/github-pull-requests. I will change this to `-emit-llvm-only` instead 
an see if that works better.



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


[clang] [test][OpenMP] Avoid writing to a potentially write-protected dir (PR #94931)

2024-06-09 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/94931

>From c5b2765d9f4bd2a8412c0722a052148673411f94 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 10 Jun 2024 07:45:48 +0200
Subject: [PATCH 1/2] [test][OpenMP] Avoid writing to a potentially
 write-protected dir

The test clang/test/OpenMP/error_unsupport_feature.c don't check the output
written to the current directory. The current directory may be write protected
e.g. in a sandboxed environment.

This patch replace the -emit-llvm option with -fsyntax-only as it don't care
about the outputed llvm IR.
---
 clang/test/OpenMP/error_unsupport_feature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/error_unsupport_feature.c 
b/clang/test/OpenMP/error_unsupport_feature.c
index 611a8b4639c44..2dc485e20dbb7 100644
--- a/clang/test/OpenMP/error_unsupport_feature.c
+++ b/clang/test/OpenMP/error_unsupport_feature.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -verify -fopenmp %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fopenmp %s
 
 int main () {
   int r = 0;

>From 306ada79b6202d838736ac7aca9922d4a8b7624b Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 10 Jun 2024 08:46:17 +0200
Subject: [PATCH 2/2] [test][OpenMP] Avoid writing to a potentially
 write-protected dir

Changed -fsyntax-only to -emit-llvm-only
---
 clang/test/OpenMP/error_unsupport_feature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/error_unsupport_feature.c 
b/clang/test/OpenMP/error_unsupport_feature.c
index 2dc485e20dbb7..eb381b3bea1e1 100644
--- a/clang/test/OpenMP/error_unsupport_feature.c
+++ b/clang/test/OpenMP/error_unsupport_feature.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fopenmp %s
+// RUN: %clang_cc1 -emit-llvm-only -verify -fopenmp %s
 
 int main () {
   int r = 0;

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


[clang] [test][OpenMP] Avoid writing to a potentially write-protected dir (PR #94931)

2024-06-09 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [test][OpenMP] Avoid writing to a potentially write-protected dir (PR #94931)

2024-06-10 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] Carving out -Wformat warning about scoped enums into a subwarning (PR #88595)

2024-04-14 Thread Karl-Johan Karlsson via cfe-commits


@@ -12,8 +12,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-verify=okay %s
 
 // Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).

karka228 wrote:

The -Wformat-signedness warning was implemented to work the same way as the 
same warning do in gcc. This patch seems to remove that gcc compatibility. With 
this patch `-Wformat-signedness` is now controlled by `-Wformat-pedantic` 
instead of `-Wformat` (as in gcc). I don't know how important it is for clang 
to be gcc compatible in this way (@AaronBallman  what do you think?).  At least 
this comment need to be updated as it no longer match the test below.


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


[clang] Carving out -Wformat warning about scoped enums into a subwarning (PR #88595)

2024-04-14 Thread Karl-Johan Karlsson via cfe-commits


@@ -218,5 +218,5 @@ void test_printf_unsigned_priX16(uint16_t x) {
 void test_suppress(int x)

karka228 wrote:

Same as above about gcc compatibility. The comment need at least to be updated.

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


[clang] Carving out -Wformat warning about scoped enums into a subwarning (PR #88595)

2024-04-15 Thread Karl-Johan Karlsson via cfe-commits


@@ -12,8 +12,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-verify=okay %s
 
 // Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).

karka228 wrote:

That discussion is only about -Wformat scoped enums warnings, but this patch 
currently move all the -Wformat warnings regarding type mismatch into a 
subwarning, that a lot more warnings than only scoped enums. Is that intended?

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


[clang] [llvm] [test] Avoid writing to a potentially write-protected dir (PR #89242)

2024-04-18 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/89242

These tests just don't check the output written to the current directory. The 
current directory may be write protected e.g. in a sandboxed environment. 
Typically one would write `clang -o %t.o` for a writeable dir, but since we 
only care about stdout/stderr, throw away the output file and just write to 
/dev/null instead.

>From 4cc801e00e80f9727ade71213193e8d5cc5610f8 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Thu, 18 Apr 2024 16:24:13 +0200
Subject: [PATCH] [test] Avoid writing to a potentially write-protected dir

These tests just don't check the output written to the current directory. The
current directory may be write protected e.g. in a sandboxed environment.
Typically one would write `clang -o %t.o` for a writeable dir, but since we only
care about stdout/stderr, throw away the output file and just write to /dev/null
instead.
---
 clang/test/CodeGen/PowerPC/builtins-ppc-htm.c |  2 +-
 .../PowerPC/builtins-ppc-vec-ins-error.c  | 12 +-
 .../RISCV/riscv-func-attr-target-err.c|  2 +-
 clang/test/Sema/ppc-attr-target-inline.c  |  2 +-
 clang/test/SemaHLSL/BuiltIns/any-errors.hlsl  |  2 +-
 .../test/SemaHLSL/BuiltIns/clamp-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl  |  4 ++--
 clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl |  2 +-
 .../BuiltIns/half-float-only-errors.hlsl  | 24 +--
 .../test/SemaHLSL/BuiltIns/isinf-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl |  2 +-
 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/pow-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl  |  2 +-
 .../SemaHLSL/BuiltIns/reversebits-errors.hlsl |  2 +-
 .../test/SemaHLSL/BuiltIns/round-errors.hlsl  |  2 +-
 .../test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl  |  2 +-
 .../MachineVerifier/verify-inlineasmbr.mir|  2 +-
 19 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
index 51585f27e0bc70..1cdd8c0f40d4c3 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
@@ -1,6 +1,6 @@
 // REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -target-feature +altivec -target-feature +htm -triple 
powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
-// RUN: not %clang_cc1 -target-feature +altivec -target-feature -htm -triple 
powerpc64-unknown-unknown -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature -htm -triple 
powerpc64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=ERROR
 
 void test1(long int *r, int code, long int *a, long int *b) {
 // CHECK-LABEL: define{{.*}} void @test1
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
index f5149bf4ce8fda..1194e51ad44542 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
@@ -1,17 +1,17 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SI
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_ELT_SI
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_F
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s -o 
/dev/null -verify -D __TEST_ELT_F
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SLL
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_ELT_SLL
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_D
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s -o 
/dev/null -verify -D __TEST_ELT_D
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_UNALIGNED_UI
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_UNALIGNED_UI
 // RUN: %clang_cc1 -flax-vector-conv

[clang] [llvm] [test] Avoid writing to a potentially write-protected dir (PR #89242)

2024-04-18 Thread Karl-Johan Karlsson via cfe-commits


@@ -1,5 +1,5 @@
 
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected -o /dev/null

karka228 wrote:

Removing `-emit-llvm` will expose more of the compiler pipeline to the 
testcases and some testcases seems not to be designed to work with that. 
Instead I found out that there is another option `-emit-llvm-only` that seems 
to be designed to be used together with `-verify` as it to the same thing as 
`-emit-llvm` except that it don't produce any output.

Is that an acceptable solution?

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


[clang] [llvm] [test] Avoid writing to a potentially write-protected dir (PR #89242)

2024-04-18 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/89242

>From 4cc801e00e80f9727ade71213193e8d5cc5610f8 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Thu, 18 Apr 2024 16:24:13 +0200
Subject: [PATCH 1/2] [test] Avoid writing to a potentially write-protected dir

These tests just don't check the output written to the current directory. The
current directory may be write protected e.g. in a sandboxed environment.
Typically one would write `clang -o %t.o` for a writeable dir, but since we only
care about stdout/stderr, throw away the output file and just write to /dev/null
instead.
---
 clang/test/CodeGen/PowerPC/builtins-ppc-htm.c |  2 +-
 .../PowerPC/builtins-ppc-vec-ins-error.c  | 12 +-
 .../RISCV/riscv-func-attr-target-err.c|  2 +-
 clang/test/Sema/ppc-attr-target-inline.c  |  2 +-
 clang/test/SemaHLSL/BuiltIns/any-errors.hlsl  |  2 +-
 .../test/SemaHLSL/BuiltIns/clamp-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl  |  4 ++--
 clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl |  2 +-
 .../BuiltIns/half-float-only-errors.hlsl  | 24 +--
 .../test/SemaHLSL/BuiltIns/isinf-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl |  2 +-
 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/pow-errors.hlsl  |  2 +-
 clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl  |  2 +-
 .../SemaHLSL/BuiltIns/reversebits-errors.hlsl |  2 +-
 .../test/SemaHLSL/BuiltIns/round-errors.hlsl  |  2 +-
 .../test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl  |  2 +-
 .../MachineVerifier/verify-inlineasmbr.mir|  2 +-
 19 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
index 51585f27e0bc70..1cdd8c0f40d4c3 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-htm.c
@@ -1,6 +1,6 @@
 // REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -target-feature +altivec -target-feature +htm -triple 
powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
-// RUN: not %clang_cc1 -target-feature +altivec -target-feature -htm -triple 
powerpc64-unknown-unknown -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature -htm -triple 
powerpc64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=ERROR
 
 void test1(long int *r, int code, long int *a, long int *b) {
 // CHECK-LABEL: define{{.*}} void @test1
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
index f5149bf4ce8fda..1194e51ad44542 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c
@@ -1,17 +1,17 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SI
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_ELT_SI
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_F
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s -o 
/dev/null -verify -D __TEST_ELT_F
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_SLL
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_ELT_SLL
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_ELT_D
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s -o 
/dev/null -verify -D __TEST_ELT_D
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify -D __TEST_UNALIGNED_UI
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-o /dev/null -verify -D __TEST_UNALIGNED_UI
 // RUN: %clang_cc1 -flax-vector-conversions=none -target-feature +vsx 
-target-cpu pwr10 -fsyntax-only \
-// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s 
-verify
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm -ferror-limit 10 %s -o 
/dev/null -verify
 
 #include 
 
diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-tar

[clang] [llvm] [test] Avoid writing to a potentially write-protected dir (PR #89242)

2024-04-20 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-04-27 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/90377

This is a fix for the issue #87758 where fast-math flags are not propagated all 
builtins.

It seems like pragmas with fast math flags was only propagated to calls of 
unary floating point builtins. This patch propagate them also for binary and 
ternary floating point builtins.


>From 80836f51573c8ba474a0b5d5890a489d5f0c7034 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:04:11 +0200
Subject: [PATCH 1/2] Pre-commit reproducer for fast-math flags on calls

Adding test case related to issue #87758

The testcase show the faulty behavior where the calls to llvm.pow.f32
and llvm.fma.f32 are not attributed with the "fast" flag.
---
 clang/test/CodeGen/pr87758.c | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 clang/test/CodeGen/pr87758.c

diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
new file mode 100644
index 00..5c5a6de442c2ac
--- /dev/null
+++ b/clang/test/CodeGen/pr87758.c
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// FIXME: Reproducer for issue #87758
+// The testcase below show the faulty behavior where the calls to
+// llvm.pow.f32 and llvm.fma.f32 are not attributed with the "fast" flag.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call float @llvm.pow.f32(float [[TMP0]], 
float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call float @llvm.fma.f32(float [[TMP1]], 
float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

>From 4af840da9ec863f6372083f5e96998fb07db6b9c Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:37:34 +0200
Subject: [PATCH 2/2] [clang][CodeGen] Propagate pragma set fast-math flags to
 floating point builtins

This is a fix for the issue #87758 where fast-math flags are not propagated
all builtins.

It seems like pragmas with fast math flags was only propagated to calls of
unary floating point builtins. This patch propagate them also for binary and
ternary floating point builtins.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 6 +++---
 clang/test/CodeGen/pr87758.c| 9 -
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..d61a63ac61572d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -513,8 +513,8 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -530,8 +530,8 @@ static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{Src0->getType(), Src1->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
@@ -551,8 +551,8 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
index 5c5a6de442c2ac..05b3232986e0a6 100644
--- a/clang/test/CodeGen/pr87758.c
+

[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-04-30 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/90377

>From 80836f51573c8ba474a0b5d5890a489d5f0c7034 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:04:11 +0200
Subject: [PATCH 1/3] Pre-commit reproducer for fast-math flags on calls

Adding test case related to issue #87758

The testcase show the faulty behavior where the calls to llvm.pow.f32
and llvm.fma.f32 are not attributed with the "fast" flag.
---
 clang/test/CodeGen/pr87758.c | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 clang/test/CodeGen/pr87758.c

diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
new file mode 100644
index 00..5c5a6de442c2ac
--- /dev/null
+++ b/clang/test/CodeGen/pr87758.c
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// FIXME: Reproducer for issue #87758
+// The testcase below show the faulty behavior where the calls to
+// llvm.pow.f32 and llvm.fma.f32 are not attributed with the "fast" flag.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call float @llvm.pow.f32(float [[TMP0]], 
float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call float @llvm.fma.f32(float [[TMP1]], 
float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

>From 4af840da9ec863f6372083f5e96998fb07db6b9c Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:37:34 +0200
Subject: [PATCH 2/3] [clang][CodeGen] Propagate pragma set fast-math flags to
 floating point builtins

This is a fix for the issue #87758 where fast-math flags are not propagated
all builtins.

It seems like pragmas with fast math flags was only propagated to calls of
unary floating point builtins. This patch propagate them also for binary and
ternary floating point builtins.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 6 +++---
 clang/test/CodeGen/pr87758.c| 9 -
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..d61a63ac61572d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -513,8 +513,8 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -530,8 +530,8 @@ static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{Src0->getType(), Src1->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
@@ -551,8 +551,8 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
index 5c5a6de442c2ac..05b3232986e0a6 100644
--- a/clang/test/CodeGen/pr87758.c
+++ b/clang/test/CodeGen/pr87758.c
@@ -2,9 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
 // RUN: | FileCheck -check-prefix=CHECK %s
 
-// FIXME: Reproducer for issue #87758
-// The testcase below show the faulty behavior where the calls to
-// llvm.

[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-04-30 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// Reproducer for issue #87758
+// The testcase below verifies that the "fast" flag are set on the calls.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call fast float @llvm.pow.f32(float 
[[TMP0]], float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call fast float @llvm.fma.f32(float 
[[TMP1]], float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

karka228 wrote:

By combining `#pragma float_control(precise,on)` and `-ffast-math` to the 
testcase it revealed additional bugs, as the "fast" flag was still set. I tried 
to fix this by changing the function emitLibraryCall() but I'm a bit unsure if 
this is a correct fix.


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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-04-30 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \

karka228 wrote:

The only reason for using `-O3`  was to get rid of all the allocas, loads and 
stores in the output that didn't contributed to the test.

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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-04-30 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+

karka228 wrote:

Sure, I will add that.


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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-02 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/90377

>From 80836f51573c8ba474a0b5d5890a489d5f0c7034 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:04:11 +0200
Subject: [PATCH 1/4] Pre-commit reproducer for fast-math flags on calls

Adding test case related to issue #87758

The testcase show the faulty behavior where the calls to llvm.pow.f32
and llvm.fma.f32 are not attributed with the "fast" flag.
---
 clang/test/CodeGen/pr87758.c | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 clang/test/CodeGen/pr87758.c

diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
new file mode 100644
index 00..5c5a6de442c2ac
--- /dev/null
+++ b/clang/test/CodeGen/pr87758.c
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// FIXME: Reproducer for issue #87758
+// The testcase below show the faulty behavior where the calls to
+// llvm.pow.f32 and llvm.fma.f32 are not attributed with the "fast" flag.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call float @llvm.pow.f32(float [[TMP0]], 
float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call float @llvm.fma.f32(float [[TMP1]], 
float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

>From 4af840da9ec863f6372083f5e96998fb07db6b9c Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:37:34 +0200
Subject: [PATCH 2/4] [clang][CodeGen] Propagate pragma set fast-math flags to
 floating point builtins

This is a fix for the issue #87758 where fast-math flags are not propagated
all builtins.

It seems like pragmas with fast math flags was only propagated to calls of
unary floating point builtins. This patch propagate them also for binary and
ternary floating point builtins.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 6 +++---
 clang/test/CodeGen/pr87758.c| 9 -
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..d61a63ac61572d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -513,8 +513,8 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -530,8 +530,8 @@ static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{Src0->getType(), Src1->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
@@ -551,8 +551,8 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
index 5c5a6de442c2ac..05b3232986e0a6 100644
--- a/clang/test/CodeGen/pr87758.c
+++ b/clang/test/CodeGen/pr87758.c
@@ -2,9 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
 // RUN: | FileCheck -check-prefix=CHECK %s
 
-// FIXME: Reproducer for issue #87758
-// The testcase below show the faulty behavior where the calls to
-// llvm.

[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-02 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// Reproducer for issue #87758
+// The testcase below verifies that the "fast" flag are set on the calls.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call fast float @llvm.pow.f32(float 
[[TMP0]], float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call fast float @llvm.fma.f32(float 
[[TMP1]], float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

karka228 wrote:

I updated the testcase with more RUN: lines and also added a libc call to 
rindex that have nothing to do with floats to verify that it never get the 
"fast" flag.


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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-03 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/90377

>From 80836f51573c8ba474a0b5d5890a489d5f0c7034 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:04:11 +0200
Subject: [PATCH 1/5] Pre-commit reproducer for fast-math flags on calls

Adding test case related to issue #87758

The testcase show the faulty behavior where the calls to llvm.pow.f32
and llvm.fma.f32 are not attributed with the "fast" flag.
---
 clang/test/CodeGen/pr87758.c | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 clang/test/CodeGen/pr87758.c

diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
new file mode 100644
index 00..5c5a6de442c2ac
--- /dev/null
+++ b/clang/test/CodeGen/pr87758.c
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// FIXME: Reproducer for issue #87758
+// The testcase below show the faulty behavior where the calls to
+// llvm.pow.f32 and llvm.fma.f32 are not attributed with the "fast" flag.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call float @llvm.pow.f32(float [[TMP0]], 
float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call float @llvm.fma.f32(float [[TMP1]], 
float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

>From 4af840da9ec863f6372083f5e96998fb07db6b9c Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:37:34 +0200
Subject: [PATCH 2/5] [clang][CodeGen] Propagate pragma set fast-math flags to
 floating point builtins

This is a fix for the issue #87758 where fast-math flags are not propagated
all builtins.

It seems like pragmas with fast math flags was only propagated to calls of
unary floating point builtins. This patch propagate them also for binary and
ternary floating point builtins.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 6 +++---
 clang/test/CodeGen/pr87758.c| 9 -
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..d61a63ac61572d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -513,8 +513,8 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -530,8 +530,8 @@ static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{Src0->getType(), Src1->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
@@ -551,8 +551,8 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
index 5c5a6de442c2ac..05b3232986e0a6 100644
--- a/clang/test/CodeGen/pr87758.c
+++ b/clang/test/CodeGen/pr87758.c
@@ -2,9 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
 // RUN: | FileCheck -check-prefix=CHECK %s
 
-// FIXME: Reproducer for issue #87758
-// The testcase below show the faulty behavior where the calls to
-// llvm.

[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-03 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -fmath-errno -ffp-contract=on 
-fno-rounding-math -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffp-contract=fast 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -O3 -S -emit-llvm -Xclang -disable-llvm-passes %s -o - | 
FileCheck %s
+// RUN: %clang -O3 -ffp-model=fast -S -emit-llvm -Xclang -disable-llvm-passes 
%s -o - | FileCheck %s
+// RUN: %clang -O3 -ffp-model=precise -S -emit-llvm -Xclang 
-disable-llvm-passes %s -o - | FileCheck %s
+
+// Reproducer for issue #87758
+// The testcase below verifies that the "fast" flag are set on the calls.
+

karka228 wrote:

Sure, I update the testcase with only those run lines.


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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-03 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+// precise mode
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fmath-errno -ffp-contract=on \
+// RUN: -fno-rounding-math -emit-llvm  -o - %s | FileCheck \
+// RUN: --check-prefix=CHECK-PRECISE %s
+
+// fast mode
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffp-contract=fast \
+// RUN: -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-FAST %s
+
+// Reproducer for issue #87758
+// The testcase below verifies that the "fast" flag are set on the calls.
+
+float sqrtf(float x); // unary fp builtin
+float powf(float x, float y); // binary fp builtin
+float fmaf(float x, float y, float z); // ternary fp builtin
+char *rindex(const char *s, int c); // not a fp builtin
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK: define dso_local float @fp_precise_off_libm_calls(
+// CHECK: %{{.*}} = call fast float @llvm.sqrt.f32(

karka228 wrote:

I guess not any longer. I'll change the testcase.


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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-03 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/90377

>From 80836f51573c8ba474a0b5d5890a489d5f0c7034 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:04:11 +0200
Subject: [PATCH 1/6] Pre-commit reproducer for fast-math flags on calls

Adding test case related to issue #87758

The testcase show the faulty behavior where the calls to llvm.pow.f32
and llvm.fma.f32 are not attributed with the "fast" flag.
---
 clang/test/CodeGen/pr87758.c | 29 +
 1 file changed, 29 insertions(+)
 create mode 100644 clang/test/CodeGen/pr87758.c

diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
new file mode 100644
index 00..5c5a6de442c2ac
--- /dev/null
+++ b/clang/test/CodeGen/pr87758.c
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK %s
+
+// FIXME: Reproducer for issue #87758
+// The testcase below show the faulty behavior where the calls to
+// llvm.pow.f32 and llvm.fma.f32 are not attributed with the "fast" flag.
+
+float sqrtf(float x);
+float powf(float x, float y);
+float fmaf(float x, float y, float z);
+
+#pragma float_control(push)
+#pragma float_control(precise, off)
+// CHECK-LABEL: define dso_local float @fp_precise_libm_calls(
+// CHECK-SAME: float noundef [[A:%.*]], float noundef [[B:%.*]], float noundef 
[[C:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call fast float @llvm.sqrt.f32(float 
[[A]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call float @llvm.pow.f32(float [[TMP0]], 
float [[B]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call float @llvm.fma.f32(float [[TMP1]], 
float [[B]], float [[C]])
+// CHECK-NEXT:ret float [[TMP2]]
+//
+float fp_precise_libm_calls(float a, float b, float c) {
+  a = sqrtf(a);
+  a = powf(a,b);
+  a = fmaf(a,b,c);
+  return a;
+}
+#pragma float_control(pop)

>From 4af840da9ec863f6372083f5e96998fb07db6b9c Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Sat, 27 Apr 2024 22:37:34 +0200
Subject: [PATCH 2/6] [clang][CodeGen] Propagate pragma set fast-math flags to
 floating point builtins

This is a fix for the issue #87758 where fast-math flags are not propagated
all builtins.

It seems like pragmas with fast math flags was only propagated to calls of
unary floating point builtins. This patch propagate them also for binary and
ternary floating point builtins.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 6 +++---
 clang/test/CodeGen/pr87758.c| 9 -
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..d61a63ac61572d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -513,8 +513,8 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -530,8 +530,8 @@ static Value *emitBinaryExpMaybeConstrainedFPBuiltin(
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{Src0->getType(), Src1->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
@@ -551,8 +551,8 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
diff --git a/clang/test/CodeGen/pr87758.c b/clang/test/CodeGen/pr87758.c
index 5c5a6de442c2ac..05b3232986e0a6 100644
--- a/clang/test/CodeGen/pr87758.c
+++ b/clang/test/CodeGen/pr87758.c
@@ -2,9 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -O3 -emit-llvm -o - %s \
 // RUN: | FileCheck -check-prefix=CHECK %s
 
-// FIXME: Reproducer for issue #87758
-// The testcase below show the faulty behavior where the calls to
-// llvm.

[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-04 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [clang][CodeGen] Propagate pragma set fast-math flags to floating point builtins (PR #90377)

2024-05-05 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> LGTM. Thanks.

I will close the issue #87758.

Thanks @andykaylor and @zahiraam for reviewing.


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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/102073

>From e2c9089537bfa0fad10f7873ca5cb4191eed7fa5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 5 Aug 2024 23:43:39 +0200
Subject: [PATCH 1/3] [test] Avoid writing to a potentially write-protected dir

The tests avx10_2_512minmax-error.c and length-errors.hlsl don't check the
output written to the current directory. The current directory may be write
protected e.g. in a sandboxed environment.

This patch replace the -emit-llvm option with -emit-llvm-only as these testcases
don't care about the outputed llvm IR.
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 4 ++--
 clang/test/SemaHLSL/BuiltIns/length-errors.hlsl  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 15ed7a0b35d82..7a5f6b5b2345c 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm -verify
+// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm -verify
+// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 
 #include 
 
diff --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
index fe0046a2ab5a1..8153726367637 100644
--- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify -verify-ignore-unexpected
 
 void test_too_few_arg()
 {

>From 8fd55443eb910406eeadfd6e9fdcfeb6bfb64cc3 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 6 Aug 2024 08:27:33 +0200
Subject: [PATCH 2/3] Update clang/test/CodeGen/X86/avx10_2_512minmax-error.c

Co-authored-by: Chris B 
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 7a5f6b5b2345c..29fe33471e2a9 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
+// RUN: -Wno-invalid-feature-combination -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
 // RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 

>From 8a236f0a8e4bd35bae2d8257483f92d22de41905 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 6 Aug 2024 08:28:14 +0200
Subject: [PATCH 3/3] Update clang/test/CodeGen/X86/avx10_2_512minmax-error.c

Co-authored-by: Chris B 
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 29fe33471e2a9..99fa53bd4e7a5 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
 // RUN: -Wno-invalid-feature-combination -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
+// RUN: -Wno-invalid-feature-combination -verify
 
 #include 
 

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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/102073

>From e2c9089537bfa0fad10f7873ca5cb4191eed7fa5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 5 Aug 2024 23:43:39 +0200
Subject: [PATCH 1/4] [test] Avoid writing to a potentially write-protected dir

The tests avx10_2_512minmax-error.c and length-errors.hlsl don't check the
output written to the current directory. The current directory may be write
protected e.g. in a sandboxed environment.

This patch replace the -emit-llvm option with -emit-llvm-only as these testcases
don't care about the outputed llvm IR.
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 4 ++--
 clang/test/SemaHLSL/BuiltIns/length-errors.hlsl  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 15ed7a0b35d82..7a5f6b5b2345c 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm -verify
+// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm -verify
+// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 
 #include 
 
diff --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
index fe0046a2ab5a1..8153726367637 100644
--- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify -verify-ignore-unexpected
 
 void test_too_few_arg()
 {

>From 8fd55443eb910406eeadfd6e9fdcfeb6bfb64cc3 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 6 Aug 2024 08:27:33 +0200
Subject: [PATCH 2/4] Update clang/test/CodeGen/X86/avx10_2_512minmax-error.c

Co-authored-by: Chris B 
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 7a5f6b5b2345c..29fe33471e2a9 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
+// RUN: -Wno-invalid-feature-combination -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
 // RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
 

>From 8a236f0a8e4bd35bae2d8257483f92d22de41905 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 6 Aug 2024 08:28:14 +0200
Subject: [PATCH 3/4] Update clang/test/CodeGen/X86/avx10_2_512minmax-error.c

Co-authored-by: Chris B 
---
 clang/test/CodeGen/X86/avx10_2_512minmax-error.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c 
b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
index 29fe33471e2a9..99fa53bd4e7a5 100644
--- a/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
+++ b/clang/test/CodeGen/X86/avx10_2_512minmax-error.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64 -target-feature +avx10.2-512 \
 // RUN: -Wno-invalid-feature-combination -verify
 // RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=i386 -target-feature +avx10.2-512 \
-// RUN: -Wno-invalid-feature-combination -emit-llvm-only -verify
+// RUN: -Wno-invalid-feature-combination -verify
 
 #include 
 

>From 42feb6157c027668a76f78c472beac8ae1cb5cff Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 6 Aug 2024 08:28:26 +0200
Subject: [PATCH 4/4] Update clang/test/SemaHLSL/BuiltIns/length-errors.hlsl

Co-authored-by: Chris B 
---
 clang/test/SemaHLSL/BuiltIns/length-errors.hlsl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
index 8153726367637..281faada6f5e9 100644
--- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-

[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/102073

>From a9401265f397108dbbb8c99cb4478801c39448e9 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 5 Aug 2024 23:43:39 +0200
Subject: [PATCH] [test] Avoid writing to a potentially write-protected dir

The test length-errors.hlsl don't check the output written to the current
directory. The current directory may be write protected e.g. in a sandboxed
environment.

This patch remove the -emit-llvm option as these testcases don't care about the
outputed llvm IR.

Co-authored-by: Chris B 
---
 clang/test/SemaHLSL/BuiltIns/length-errors.hlsl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
index fe0046a2ab5a1..281faada6f5e9 100644
--- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes 
-verify -verify-ignore-unexpected
+
 
 void test_too_few_arg()
 {

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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

When rebasing the patch I removed the fix in avx10_2_512minmax-error.c as it 
was already fixed in:

```
commit 1b9d7dd9eb31974077b64d66404193bd7c4ad65e
Author: Augie Fackler 
Date:   Mon Aug 5 17:08:06 2024 -0400

tests: fix clang flags in avx10_2_512minmax-error test

Introduced in 3d5cc7e1e632b74119af13824dabc346bd248c93, caught by a
sandboxed test run.
```


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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-05 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [test] Avoid writing to a potentially write-protected dir (PR #102073)

2024-08-06 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)

2024-06-24 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/96457

The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the 
Inputs dir in the llvm-project repo instead of the temporary directory. The 
llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch create a separate temporary directory where the the null_byte.bin 
file is created along with the rest of copies of the other embed-files needed 
for the testcase.

>From abf92edafdaae4b8e39cd11f21c366b8c5afc0d0 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Mon, 24 Jun 2024 08:49:12 +0200
Subject: [PATCH] [clang][test] Avoid writing to a potentially write-protected
 dir

The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the
Inputs dir in the llvm-project repo instead of the temporary directory. The
llvm-project repo may be write protected e.g. in a sandboxed environment.

This patch create a separate temporary directory where the the null_byte.bin
file is created along with the rest of copies of the other embed-files needed
for the testcase.
---
 clang/test/Preprocessor/embed_weird.cpp | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/test/Preprocessor/embed_weird.cpp 
b/clang/test/Preprocessor/embed_weird.cpp
index a90d3bc330538..31b622c848d6a 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -1,7 +1,9 @@
-// RUN: printf "\0" > %S/Inputs/null_byte.bin
-// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,cxx 
-Wno-c23-extensions
-// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%S/Inputs 
-verify=expected,c
-// RUN: rm %S/Inputs/null_byte.bin
+// RUN: rm -rf %t && mkdir -p %t/media
+// RUN: cp %S/Inputs/single_byte.txt %S/Inputs/jk.txt %S/Inputs/numbers.txt %t/
+// RUN: cp %S/Inputs/media/empty %t/media/
+// RUN: printf "\0" > %t/null_byte.bin
+// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx 
-Wno-c23-extensions
+// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t 
-verify=expected,c
 #embed 
 ;
 

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


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)

2024-06-24 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)

2024-06-25 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)

2024-06-25 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Whoops, sorry about that mistake in the test. The patch is LGTM. Thanks!

Thanks for the fast review :-)


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


[clang] [clang][analyzer] PointerSubChecker should not warn on pointers converted to numerical type (PR #111846)

2024-10-11 Thread Karl-Johan Karlsson via cfe-commits
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


karka228 wrote:

> The change LGTM, I think we can merge it.

I guess the testcase pointer-sub.c have to be fixed to work on the windows 
buildbot, also. Right?


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


[clang] [Sema] Fix warning in SemaOpenACC.cpp (PR #112481)

2024-10-15 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/112481

Fix gcc warning:

clang/lib/Sema/SemaOpenACC.cpp:2208:5: warning: this statement may fall through 
[-Wimplicit-fallthrough=]

>From 1015e28263bdfafd62c061200163899d0f8a7f69 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 16 Oct 2024 07:48:11 +0200
Subject: [PATCH] [Sema] Fix warning in SemaOpenACC.cpp

Fix gcc warning:

clang/lib/Sema/SemaOpenACC.cpp:2208:5: warning: this statement may fall through 
[-Wimplicit-fallthrough=]
---
 clang/lib/Sema/SemaOpenACC.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 22aedbc70df8cc..d33b0d0c1c3018 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -2216,7 +2216,7 @@ ExprResult SemaOpenACC::CheckGangExpr(OpenACCGangKind GK, 
Expr *E) {
 case OpenACCGangKind::Static:
   return CheckGangStaticExpr(*this, E);
 }
-  }
+  } break;
   default:
 llvm_unreachable("Non compute construct in active compute construct?");
   }

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


[clang] [Sema] Fix warning in SemaOpenACC.cpp (PR #112481)

2024-10-16 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [Sema] Fix warnings in SemaFunctionEffects.cpp (PR #112857)

2024-10-18 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 created 
https://github.com/llvm/llvm-project/pull/112857

Fix gcc warnings like:
SemaFunctionEffects.cpp:1531:5: warning: this statement may fall through 
[-Wimplicit-fallthrough=]

>From ba5358f12c84266c4527d0e045055b10eabe4a0f Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Fri, 18 Oct 2024 10:39:09 +0200
Subject: [PATCH] [Sema] Fix warnings in SemaFunctionEffects.cpp

Fix gcc warnings like:
SemaFunctionEffects.cpp:1531:5: warning: this statement may fall through 
[-Wimplicit-fallthrough=]
---
 clang/lib/Sema/SemaFunctionEffects.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp 
b/clang/lib/Sema/SemaFunctionEffects.cpp
index 70e5d78661a835..c3e2a2d856a283 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -1540,6 +1540,7 @@ bool Sema::FunctionEffectDiff::shouldDiagnoseConversion(
   // matching is better.
   return true;
 }
+break;
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:
 return false;
@@ -1563,6 +1564,7 @@ bool 
Sema::FunctionEffectDiff::shouldDiagnoseRedeclaration(
   // All these forms of mismatches are diagnosed.
   return true;
 }
+break;
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:
 return false;
@@ -1592,6 +1594,7 @@ Sema::FunctionEffectDiff::shouldDiagnoseMethodOverride(
 case Kind::ConditionMismatch:
   return OverrideResult::Warn;
 }
+break;
 
   case FunctionEffect::Kind::Blocking:
   case FunctionEffect::Kind::Allocating:

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-11-12 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> I think this diagnostic should not be firing on `%x` format specifiers:

In the C-standard (7.21.6.1 The fprintf function) when reading about the 
o,u,x,X format specifiers it say "The unsigned int argument is converted to 
unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal notation (x 
or X) in the style ; the letters abcdef are used for x conversion and the 
letters ABCDEF for X conversion.". That's the reason why this diagnostic give a 
warning in this case. When this was implemented in clang we also said that we 
should follow the gcc behavior (as much as possible) as this warning have been 
available in gcc for a long time and gcc give a warning in this case.


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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-07 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/120321

>From 1ad62a9a136a5ae80c880459472a88517afe75a4 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 17 Dec 2024 22:48:04 +0100
Subject: [PATCH 1/2] [diagtool] Make the BuiltinDiagnosticsByID table sorted

When building with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON with a recent
libstdc++ (e.g. from gcc 13.3.0) the testcase
clang/test/Misc/warning-flags-tree.c fail with the message:

+ diagtool tree --internal
.../include/c++/13.3.0/bits/stl_algo.h:2013:
In function:
_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator,
const _Tp &, _Compare) [_ForwardIterator = const
diagtool::DiagnosticRecord *, _Tp = diagtool::DiagnosticRecord, _Compare
= bool (*)(const diagtool::DiagnosticRecord &, const
diagtool::DiagnosticRecord &)]

Error: elements in iterator range [first, last) are not partitioned by the
predicate __comp and value __val.

Objects involved in the operation:
iterator "first" @ 0x7ffea8ef2fd8 {
}
iterator "last" @ 0x7ffea8ef2fd0 {
}

The reason for this error is that std::lower_bound is called on
BuiltinDiagnosticsByID without it being entirely sorted. Calling
std::lower_bound If the range is not sorted, the behavior of this
function is undefined. This is detected when building with expensive
checks.

To make BuiltinDiagnosticsByID sorted we need to slightly change the
order the inc-files are included.
---
 clang/tools/diagtool/DiagnosticNames.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/tools/diagtool/DiagnosticNames.cpp 
b/clang/tools/diagtool/DiagnosticNames.cpp
index eb90f082437b33..215087b9004959 100644
--- a/clang/tools/diagtool/DiagnosticNames.cpp
+++ b/clang/tools/diagtool/DiagnosticNames.cpp
@@ -23,15 +23,14 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
@@ -39,12 +38,14 @@ static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
 #include "clang/Basic/DiagnosticInstallAPIKinds.inc"
 #undef DIAG
 };
+// clang-format on
 
 static bool orderByID(const DiagnosticRecord &Left,
   const DiagnosticRecord &Right) {

>From 4cedc90e9b26e5d48d53df463e8650d8a726e1d5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 7 Jan 2025 15:59:16 +0100
Subject: [PATCH 2/2] [diagtool] Make the BuiltinDiagnosticsByID table sorted

Extracted the includes into a wrapper header file DiagnosticIDs.inc.
Added is_sorted assert.
---
 clang/include/clang/Basic/DiagnosticIDs.inc | 31 +
 clang/lib/Basic/DiagnosticIDs.cpp   | 48 ++---
 clang/tools/diagtool/DiagnosticNames.cpp| 23 --
 3 files changed, 42 insertions(+), 60 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticIDs.inc

diff --git a/clang/include/clang/Basic/DiagnosticIDs.inc 
b/clang/include/clang/Basic/DiagnosticIDs.inc
new file mode 100644
index 00..69a7c03d39dff0
--- /dev/null
+++ b/clang/include/clang/Basic/DiagnosticIDs.inc
@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make
+// sure the table is sorted.
+
+// clang-format off
+#include "clang/Basic/DiagnosticCommonKinds.inc"
+#include "clang/Basic/DiagnosticDriverKinds.inc"
+#include "clang/Basic/DiagnosticFrontendKinds.inc"
+#include "clang/Basic/DiagnosticSerializationKinds.inc"
+#include "cla

[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-07 Thread Karl-Johan Karlsson via cfe-commits


@@ -23,28 +23,29 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
 #include "clang/Basic/DiagnosticLexKinds.inc"
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"

karka228 wrote:

> This seems brittle - Maybe we should call `std::sort` somewhere instead?

I agree that it is a bit brittle, but it is hard to find a good place where to 
insert a `std::sort`. As @kadircet  wrote it is probably better in the future 
to solve this in a better way in tablegen.

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2024-12-29 Thread Karl-Johan Karlsson via cfe-commits


@@ -23,28 +23,29 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
 #include "clang/Basic/DiagnosticLexKinds.inc"
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"

karka228 wrote:

Verify the changed include order by adding an assert in getDiagnosticForID 
below:
```
  // The requirement for lower_bound to produce a valid result it is
  // enough if the BuiltinDiagnosticsByID is partitioned (by DiagID),
  // but as we want this function to work for all possible values of
  // DiagID sent in as argument it is better to right away check if
  // BuiltinDiagnosticsByID is sorted.
  assert(llvm::is_sorted(BuiltinDiagnosticsByID, orderByID) &&
 "IDs in BuiltinDiagnosticsByID must be sorted.");
```

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2024-12-29 Thread Karl-Johan Karlsson via cfe-commits


@@ -23,28 +23,29 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off

karka228 wrote:

Add a comment about why we turn off clang-format:
```
// Turn off clang-format, as the order of the includes are important
// to make sure the table is sorted.
```

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-15 Thread Karl-Johan Karlsson via cfe-commits


@@ -23,28 +23,29 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off

karka228 wrote:

"since this order needs to be preserved in multiple places, can you put 
together a wrapper header, which includes individual diagnostic kinds in the 
specific order and explain the relationship between these pieces?"
@kadircet I added a new file DiagnosticsID.inc as a "wrapper header".

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/120321

>From 1ad62a9a136a5ae80c880459472a88517afe75a4 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 17 Dec 2024 22:48:04 +0100
Subject: [PATCH 1/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

When building with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON with a recent
libstdc++ (e.g. from gcc 13.3.0) the testcase
clang/test/Misc/warning-flags-tree.c fail with the message:

+ diagtool tree --internal
.../include/c++/13.3.0/bits/stl_algo.h:2013:
In function:
_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator,
const _Tp &, _Compare) [_ForwardIterator = const
diagtool::DiagnosticRecord *, _Tp = diagtool::DiagnosticRecord, _Compare
= bool (*)(const diagtool::DiagnosticRecord &, const
diagtool::DiagnosticRecord &)]

Error: elements in iterator range [first, last) are not partitioned by the
predicate __comp and value __val.

Objects involved in the operation:
iterator "first" @ 0x7ffea8ef2fd8 {
}
iterator "last" @ 0x7ffea8ef2fd0 {
}

The reason for this error is that std::lower_bound is called on
BuiltinDiagnosticsByID without it being entirely sorted. Calling
std::lower_bound If the range is not sorted, the behavior of this
function is undefined. This is detected when building with expensive
checks.

To make BuiltinDiagnosticsByID sorted we need to slightly change the
order the inc-files are included.
---
 clang/tools/diagtool/DiagnosticNames.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/tools/diagtool/DiagnosticNames.cpp 
b/clang/tools/diagtool/DiagnosticNames.cpp
index eb90f082437b33..215087b9004959 100644
--- a/clang/tools/diagtool/DiagnosticNames.cpp
+++ b/clang/tools/diagtool/DiagnosticNames.cpp
@@ -23,15 +23,14 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
@@ -39,12 +38,14 @@ static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
 #include "clang/Basic/DiagnosticInstallAPIKinds.inc"
 #undef DIAG
 };
+// clang-format on
 
 static bool orderByID(const DiagnosticRecord &Left,
   const DiagnosticRecord &Right) {

>From 4cedc90e9b26e5d48d53df463e8650d8a726e1d5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 7 Jan 2025 15:59:16 +0100
Subject: [PATCH 2/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

Extracted the includes into a wrapper header file DiagnosticIDs.inc.
Added is_sorted assert.
---
 clang/include/clang/Basic/DiagnosticIDs.inc | 31 +
 clang/lib/Basic/DiagnosticIDs.cpp   | 48 ++---
 clang/tools/diagtool/DiagnosticNames.cpp| 23 --
 3 files changed, 42 insertions(+), 60 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticIDs.inc

diff --git a/clang/include/clang/Basic/DiagnosticIDs.inc 
b/clang/include/clang/Basic/DiagnosticIDs.inc
new file mode 100644
index 00..69a7c03d39dff0
--- /dev/null
+++ b/clang/include/clang/Basic/DiagnosticIDs.inc
@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make
+// sure the table is sorted.
+
+// clang-format off
+#include "clang/Basic/DiagnosticCommonKinds.inc"
+#include "clang/Basic/DiagnosticDriverKinds.inc"
+#include "clang/Basic/DiagnosticFrontendKinds.inc"
+#include "clang/Basic/DiagnosticSerializationKinds.inc"
+#include "cla

[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/120321

>From 1ad62a9a136a5ae80c880459472a88517afe75a4 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 17 Dec 2024 22:48:04 +0100
Subject: [PATCH 1/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

When building with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON with a recent
libstdc++ (e.g. from gcc 13.3.0) the testcase
clang/test/Misc/warning-flags-tree.c fail with the message:

+ diagtool tree --internal
.../include/c++/13.3.0/bits/stl_algo.h:2013:
In function:
_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator,
const _Tp &, _Compare) [_ForwardIterator = const
diagtool::DiagnosticRecord *, _Tp = diagtool::DiagnosticRecord, _Compare
= bool (*)(const diagtool::DiagnosticRecord &, const
diagtool::DiagnosticRecord &)]

Error: elements in iterator range [first, last) are not partitioned by the
predicate __comp and value __val.

Objects involved in the operation:
iterator "first" @ 0x7ffea8ef2fd8 {
}
iterator "last" @ 0x7ffea8ef2fd0 {
}

The reason for this error is that std::lower_bound is called on
BuiltinDiagnosticsByID without it being entirely sorted. Calling
std::lower_bound If the range is not sorted, the behavior of this
function is undefined. This is detected when building with expensive
checks.

To make BuiltinDiagnosticsByID sorted we need to slightly change the
order the inc-files are included.
---
 clang/tools/diagtool/DiagnosticNames.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/tools/diagtool/DiagnosticNames.cpp 
b/clang/tools/diagtool/DiagnosticNames.cpp
index eb90f082437b33..215087b9004959 100644
--- a/clang/tools/diagtool/DiagnosticNames.cpp
+++ b/clang/tools/diagtool/DiagnosticNames.cpp
@@ -23,15 +23,14 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
@@ -39,12 +38,14 @@ static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
 #include "clang/Basic/DiagnosticInstallAPIKinds.inc"
 #undef DIAG
 };
+// clang-format on
 
 static bool orderByID(const DiagnosticRecord &Left,
   const DiagnosticRecord &Right) {

>From 4cedc90e9b26e5d48d53df463e8650d8a726e1d5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 7 Jan 2025 15:59:16 +0100
Subject: [PATCH 2/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

Extracted the includes into a wrapper header file DiagnosticIDs.inc.
Added is_sorted assert.
---
 clang/include/clang/Basic/DiagnosticIDs.inc | 31 +
 clang/lib/Basic/DiagnosticIDs.cpp   | 48 ++---
 clang/tools/diagtool/DiagnosticNames.cpp| 23 --
 3 files changed, 42 insertions(+), 60 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticIDs.inc

diff --git a/clang/include/clang/Basic/DiagnosticIDs.inc 
b/clang/include/clang/Basic/DiagnosticIDs.inc
new file mode 100644
index 00..69a7c03d39dff0
--- /dev/null
+++ b/clang/include/clang/Basic/DiagnosticIDs.inc
@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make
+// sure the table is sorted.
+
+// clang-format off
+#include "clang/Basic/DiagnosticCommonKinds.inc"
+#include "clang/Basic/DiagnosticDriverKinds.inc"
+#include "clang/Basic/DiagnosticFrontendKinds.inc"
+#include "clang/Basic/DiagnosticSerializationKinds.inc"
+#include "cla

[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Karl-Johan Karlsson via cfe-commits


@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make

karka228 wrote:

I added a comment about that in the file header.

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Karl-Johan Karlsson via cfe-commits




karka228 wrote:

I have now renamed the file to AllDiagnosticKinds.inc

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-17 Thread Karl-Johan Karlsson via cfe-commits

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-17 Thread Karl-Johan Karlsson via cfe-commits

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