[clang] abd05eb - [clang] Init fields added by #87357

2024-04-03 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2024-04-03T17:48:25-07:00
New Revision: abd05eb4a53e6c7760496620da417733f52d4bf9

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

LOG: [clang] Init fields added by #87357

Added: 


Modified: 
clang/include/clang/Frontend/FrontendOptions.h

Removed: 




diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 864af66b337069..5ee4d471670f48 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,7 +580,9 @@ class FrontendOptions {
 BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false),
 IncludeTimestamps(true), UseTemporary(true),
 AllowPCMWithCompilerErrors(false), ModulesShareFileManager(true),
-TimeTraceGranularity(500) {}
+EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
+EmitSymbolGraphSymbolLabelsForTesting(false),
+EmitPrettySymbolGraphs(false), TimeTraceGranularity(500) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.



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


[clang] 7508438 - [BoundsSafety] Minor fixes on counted_by (#87559)

2024-04-03 Thread via cfe-commits

Author: Yeoul Na
Date: 2024-04-03T16:35:11-07:00
New Revision: 750843875254b1d493f4d7c3d3921c1bced55b7c

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

LOG: [BoundsSafety] Minor fixes on counted_by (#87559)

DeclRef to field must be marked as LValue to be consistent with how the
field decl will be evaluated.

T->desugar() is unnecessary to call ->isArrayType().

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index d0771eb55e2785..075c8aba11fcb9 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1763,14 +1763,14 @@ static void printCountAttributedImpl(const 
CountAttributedType *T,
 void TypePrinter::printCountAttributedBefore(const CountAttributedType *T,
  raw_ostream ) {
   printBefore(T->desugar(), OS);
-  if (!T->desugar()->isArrayType())
+  if (!T->isArrayType())
 printCountAttributedImpl(T, OS, Policy);
 }
 
 void TypePrinter::printCountAttributedAfter(const CountAttributedType *T,
 raw_ostream ) {
   printAfter(T->desugar(), OS);
-  if (T->desugar()->isArrayType())
+  if (T->isArrayType())
 printCountAttributedImpl(T, OS, Policy);
 }
 

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 80b4257d9d83ed..6b2eb245d58263 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2751,7 +2751,7 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec ,
 QualType type = VD->getType().getNonReferenceType();
 // This will eventually be translated into MemberExpr upon
 // the use of instantiated struct fields.
-return BuildDeclRefExpr(VD, type, VK_PRValue, NameLoc);
+return BuildDeclRefExpr(VD, type, VK_LValue, NameLoc);
   }
 }
   }



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


[clang] 5e3da75 - [Bounds-Safety][NFC] Clean up leading space emission for CountAttributedType (#87582)

2024-04-03 Thread via cfe-commits

Author: Dan Liew
Date: 2024-04-03T16:28:54-07:00
New Revision: 5e3da75c80db749b3000c4a9e930da4784bcfc6f

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

LOG: [Bounds-Safety][NFC] Clean up leading space emission for 
CountAttributedType (#87582)

Previously the leading space was added in each string constant. This
patch moves the leading space out of the string constants and is instead
explicitly added to add clarity to the code.

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 9d551ff83151fd..d0771eb55e2785 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1746,14 +1746,15 @@ void TypePrinter::printPackExpansionAfter(const 
PackExpansionType *T,
 static void printCountAttributedImpl(const CountAttributedType *T,
  raw_ostream ,
  const PrintingPolicy ) {
+  OS << ' ';
   if (T->isCountInBytes() && T->isOrNull())
-OS << " __sized_by_or_null(";
+OS << "__sized_by_or_null(";
   else if (T->isCountInBytes())
-OS << " __sized_by(";
+OS << "__sized_by(";
   else if (T->isOrNull())
-OS << " __counted_by_or_null(";
+OS << "__counted_by_or_null(";
   else
-OS << " __counted_by(";
+OS << "__counted_by(";
   if (T->getCountExpr())
 T->getCountExpr()->printPretty(OS, nullptr, Policy);
   OS << ')';



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


[clang] 029e1d7 - Revert "Revert "Revert "[clang][UBSan] Add implicit conversion check for bitfields""" (#87562)

2024-04-03 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-04-03T15:19:03-07:00
New Revision: 029e1d751503268e3d8b01db769e710835c3010d

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

LOG: Revert "Revert "Revert "[clang][UBSan] Add implicit conversion check for 
bitfields""" (#87562)

Reverts llvm/llvm-project#87529

Reverts #87518

https://lab.llvm.org/buildbot/#/builders/37/builds/33262 is still broken

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Driver/fsanitize.c
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h

Removed: 
clang/test/CodeGen/ubsan-bitfield-conversion.c
clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4c0e49ed6fc1c..8fc925350849cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,10 +198,6 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
-- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
-  sign change.
-- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
-  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -215,9 +211,6 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
-- ``-fsanitize=implicit-conversion`` is now a group for both
-  ``-fsanitize=implicit-integer-conversion`` and
-  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 531d56e313826c..8f58c92bd2a163 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,11 +148,6 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
-  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
- integer of larger bit width to smaller bitfield, if that results in data
- loss. This includes unsigned/signed truncations and sign changes, 
similarly
- to how the ``-fsanitize=implicit-integer-conversion`` group works, but
- explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -198,8 +193,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
- by ``-fsanitize=implicit-integer-conversion`` group of checks.
+ ``-fsanitize=implicit-conversion``). Both of these two issues are handled
+ by ``-fsanitize=implicit-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -207,7 +202,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-integer-conversion``).
+ (see ``-fsanitize=implicit-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -229,15 +224,11 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  conversions that change the arithmetic value of the integer. Enables
  ``implicit-signed-integer-truncation`` and 
``implicit-integer-sign-change``.
-  -  

[clang] 5bbce06 - [PseudoProbe] Mix block and call probe ID in lexical order (#75092)

2024-04-03 Thread via cfe-commits

Author: Lei Wang
Date: 2024-04-03T11:18:29-07:00
New Revision: 5bbce06ac642bedcb93158ed04253cf6deedf5e6

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

LOG: [PseudoProbe] Mix block and call probe ID in lexical order (#75092)

Before all the call probe ids are after block ids, in this change, it
mixed the call probe and block probe by reordering them in
lexical(line-number) order. For example:
```
main():
BB1
if(...) 
  BB2 foo(..);   
else 
  BB3 bar(...);
BB4
```
Before the profile is
```
main
 1: ..
 2: ..
 3: ...
 4: ...
 5: foo ...
 6: bar ...
 ```
 Now the new order is
```
 main
 1: ..
 2: ..
 3: foo ...
 4: ...
 5: bar ...
 6: ...
```
This can potentially make it more tolerant of profile mismatch, either from 
stale profile or frontend change. e.g. before if we add one block, even the 
block is the last one, all the call probes are shifted and mismatched. 
Moreover, this makes better use of call-anchor based stale profile matching. 
Blocks are matched based on the closest anchor, there would be more anchors 
used for the matching, reduce the mismatch scope.

Added: 


Modified: 
clang/test/CodeGen/pseudo-probe-emit.c
llvm/include/llvm/ProfileData/SampleProf.h
llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-profile.prof
llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-discriminator.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-invoke.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-profile-metadata-2.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Removed: 




diff  --git a/clang/test/CodeGen/pseudo-probe-emit.c 
b/clang/test/CodeGen/pseudo-probe-emit.c
index c7a3f7e6d5b02b..360f831e842945 100644
--- a/clang/test/CodeGen/pseudo-probe-emit.c
+++ b/clang/test/CodeGen/pseudo-probe-emit.c
@@ -10,9 +10,9 @@ void foo(int x) {
   // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
   if (x == 0)
 // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2, i32 0, i64 -1)
-bar();
+bar();  // probe id : 3
   else
-// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3, i32 0, i64 -1)
-go();
-  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0, i64 -1)
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0, i64 -1)
+go(); // probe id : 5
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 6, i32 0, i64 -1)
 }

diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h 
b/llvm/include/llvm/ProfileData/SampleProf.h
index 8ac84d4b933f20..51d590be124f10 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -466,7 +466,7 @@ struct SampleContextFrame {
   LineLocation Location;
 
   SampleContextFrame() : Location(0, 0) {}
-  
+
   SampleContextFrame(FunctionId Func, LineLocation Location)
   : Func(Func), Location(Location) {}
 
@@ -527,7 +527,7 @@ class SampleContext {
   : Func(Name), State(UnknownContext), Attributes(ContextNone) {
 assert(!Name.empty() && "Name is empty");
   }
-  
+
   SampleContext(FunctionId Func)
   : Func(Func), State(UnknownContext), Attributes(ContextNone) {}
 

diff  --git a/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h 
b/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
index 03aa93ce6bd387..7f2cc0ebbc07cb 100644
--- a/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
+++ b/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
@@ -85,14 +85,12 @@ class SampleProfileProber {
   void findInvokeNormalDests(DenseSet );
   void computeBlocksToIgnore(DenseSet ,
  DenseSet );
-  void computeProbeIdForCallsites(
-  const DenseSet );
   const Instruction *
   getOriginalTerminator(const BasicBlock *Head,
 const DenseSet );
   void computeCFGHash(const DenseSet );
-  void computeProbeIdForBlocks(const DenseSet );
-  void computeProbeIdForCallsites();
+  void computeProbeId(const DenseSet ,
+  const DenseSet );
 
   Function *F;
 

diff  --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp 
b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index 4d0fa24bd57ca4..9a191b0e38bea1 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -178,8 +178,7 @@ SampleProfileProber::SampleProfileProber(Function ,
   DenseSet BlocksAndCallsToIgnore;
   

[clang] 8a5a1b7 - Revert "Revert "[clang][UBSan] Add implicit conversion check for bitfields"" (#87529)

2024-04-03 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-04-03T10:58:39-07:00
New Revision: 8a5a1b770413bb62ff27cd8c2aea3d04b3a95bbe

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

LOG: Revert "Revert "[clang][UBSan] Add implicit conversion check for 
bitfields"" (#87529)

Reverts llvm/llvm-project#87518

Revert is not needed as the regression was fixed with
1189e87951e59a81ee097eae847c06008276fef1.

I assumed the crash and warning are different issues, but according to
https://lab.llvm.org/buildbot/#/builders/240/builds/26629
fixing warning resolves the crash.

Added: 
clang/test/CodeGen/ubsan-bitfield-conversion.c
clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Driver/fsanitize.c
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8fc925350849cd..e4c0e49ed6fc1c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -211,6 +215,9 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 8f58c92bd2a163..531d56e313826c 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,6 +148,11 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
+  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
+ integer of larger bit width to smaller bitfield, if that results in data
+ loss. This includes unsigned/signed truncations and sign changes, 
similarly
+ to how the ``-fsanitize=implicit-integer-conversion`` group works, but
+ explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -193,8 +198,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-conversion``). Both of these two issues are handled
- by ``-fsanitize=implicit-conversion`` group of checks.
+ ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
+ by ``-fsanitize=implicit-integer-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -202,7 +207,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-conversion``).
+ (see ``-fsanitize=implicit-integer-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -224,11 +229,15 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  conversions 

[clang] fff2690 - [C23] Remove WG14 N2416 from the C status page

2024-04-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-04-03T13:28:28-04:00
New Revision: fff2690eba58f3a548865b5246b09233663c680d

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

LOG: [C23] Remove WG14 N2416 from the C status page

This paper did not add any normative changes for us to check
conformance against. It added a note describing a potential behavioral
difference between compile-time and runtime evaluation of negative
floating-point values in the presence of rounding modes.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 370d99b55b1312..bc27b20ce6487e 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -750,11 +750,6 @@ C23 implementation status
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2379.htm;>N2379
   Unknown
 
-
-  Floating-point negation and conversion
-  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2416.pdf;>N2416
-  Unknown
-
 
   Annex F.8 update for implementation extensions and rounding
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2384.pdf;>N2384



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


[clang] 6099639 - [clang] Precommit test for `llvm.allow.ubsan.check()` (#87435)

2024-04-03 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-04-03T10:28:07-07:00
New Revision: 6099639846c14991806290524b77cc25f6eb39bc

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

LOG: [clang] Precommit test for `llvm.allow.ubsan.check()` (#87435)

Added: 
clang/test/CodeGen/allow-ubsan-check.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/allow-ubsan-check.c 
b/clang/test/CodeGen/allow-ubsan-check.c
new file mode 100644
index 00..bc425230c8ec75
--- /dev/null
+++ b/clang/test/CodeGen/allow-ubsan-check.c
@@ -0,0 +1,207 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null 
-fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,null | FileCheck 
%s --check-prefixes=TRAP
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null 
-fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,null | 
FileCheck %s --check-prefixes=RECOVER
+
+
+// CHECK-LABEL: define dso_local i32 @div(
+// CHECK-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] 
{
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT:store i32 [[Y]], ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0, !nosanitize 
[[META2:![0-9]+]]
+// CHECK-NEXT:[[TMP3:%.*]] = icmp ne i32 [[TMP0]], -2147483648, 
!nosanitize [[META2]]
+// CHECK-NEXT:[[TMP4:%.*]] = icmp ne i32 [[TMP1]], -1, !nosanitize 
[[META2]]
+// CHECK-NEXT:[[OR:%.*]] = or i1 [[TMP3]], [[TMP4]], !nosanitize [[META2]]
+// CHECK-NEXT:[[TMP5:%.*]] = and i1 [[TMP2]], [[OR]], !nosanitize [[META2]]
+// CHECK-NEXT:br i1 [[TMP5]], label [[CONT:%.*]], label 
[[HANDLER_DIVREM_OVERFLOW:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize [[META2]]
+// CHECK:   handler.divrem_overflow:
+// CHECK-NEXT:[[TMP6:%.*]] = zext i32 [[TMP0]] to i64, !nosanitize 
[[META2]]
+// CHECK-NEXT:[[TMP7:%.*]] = zext i32 [[TMP1]] to i64, !nosanitize 
[[META2]]
+// CHECK-NEXT:call void @__ubsan_handle_divrem_overflow_abort(ptr 
@[[GLOB1:[0-9]+]], i64 [[TMP6]], i64 [[TMP7]]) #[[ATTR3:[0-9]+]], !nosanitize 
[[META2]]
+// CHECK-NEXT:unreachable, !nosanitize [[META2]]
+// CHECK:   cont:
+// CHECK-NEXT:[[DIV:%.*]] = sdiv i32 [[TMP0]], [[TMP1]]
+// CHECK-NEXT:ret i32 [[DIV]]
+//
+// TRAP-LABEL: define dso_local i32 @div(
+// TRAP-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
+// TRAP-NEXT:  entry:
+// TRAP-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// TRAP-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// TRAP-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// TRAP-NEXT:store i32 [[Y]], ptr [[Y_ADDR]], align 4
+// TRAP-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// TRAP-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// TRAP-NEXT:[[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0, !nosanitize 
[[META2:![0-9]+]]
+// TRAP-NEXT:[[TMP3:%.*]] = icmp ne i32 [[TMP0]], -2147483648, !nosanitize 
[[META2]]
+// TRAP-NEXT:[[TMP4:%.*]] = icmp ne i32 [[TMP1]], -1, !nosanitize [[META2]]
+// TRAP-NEXT:[[OR:%.*]] = or i1 [[TMP3]], [[TMP4]], !nosanitize [[META2]]
+// TRAP-NEXT:[[TMP5:%.*]] = and i1 [[TMP2]], [[OR]], !nosanitize [[META2]]
+// TRAP-NEXT:br i1 [[TMP5]], label [[CONT:%.*]], label [[TRAP:%.*]], 
!nosanitize [[META2]]
+// TRAP:   trap:
+// TRAP-NEXT:call void @llvm.ubsantrap(i8 3) #[[ATTR3:[0-9]+]], 
!nosanitize [[META2]]
+// TRAP-NEXT:unreachable, !nosanitize [[META2]]
+// TRAP:   cont:
+// TRAP-NEXT:[[DIV:%.*]] = sdiv i32 [[TMP0]], [[TMP1]]
+// TRAP-NEXT:ret i32 [[DIV]]
+//
+// RECOVER-LABEL: define dso_local i32 @div(
+// RECOVER-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// RECOVER-NEXT:  entry:
+// RECOVER-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// RECOVER-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// RECOVER-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// RECOVER-NEXT:store i32 [[Y]], ptr [[Y_ADDR]], align 4
+// RECOVER-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// RECOVER-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// RECOVER-NEXT: 

[clang] 5822ca5 - Revert "[clang][UBSan] Add implicit conversion check for bitfields" (#87518)

2024-04-03 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-04-03T10:27:09-07:00
New Revision: 5822ca5a013256bbca33fbbae56f49caa2e37fe3

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

LOG: Revert "[clang][UBSan] Add implicit conversion check for bitfields" 
(#87518)

Reverts llvm/llvm-project#75481

Breaks multiple bots, see #75481

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Driver/fsanitize.c
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h

Removed: 
clang/test/CodeGen/ubsan-bitfield-conversion.c
clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4c0e49ed6fc1c..8fc925350849cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,10 +198,6 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
-- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
-  sign change.
-- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
-  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -215,9 +211,6 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
-- ``-fsanitize=implicit-conversion`` is now a group for both
-  ``-fsanitize=implicit-integer-conversion`` and
-  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 531d56e313826c..8f58c92bd2a163 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,11 +148,6 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
-  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
- integer of larger bit width to smaller bitfield, if that results in data
- loss. This includes unsigned/signed truncations and sign changes, 
similarly
- to how the ``-fsanitize=implicit-integer-conversion`` group works, but
- explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -198,8 +193,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
- by ``-fsanitize=implicit-integer-conversion`` group of checks.
+ ``-fsanitize=implicit-conversion``). Both of these two issues are handled
+ by ``-fsanitize=implicit-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -207,7 +202,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-integer-conversion``).
+ (see ``-fsanitize=implicit-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -229,15 +224,11 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  conversions that change the arithmetic value of the integer. Enables
  ``implicit-signed-integer-truncation`` and 
``implicit-integer-sign-change``.
-  -  ``-fsanitize=implicit-integer-conversion``: Checks for suspicious
- behavior of 

[clang] 1189e87 - [CodeGen] Fix a warning

2024-04-03 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-04-03T09:55:45-07:00
New Revision: 1189e87951e59a81ee097eae847c06008276fef1

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

LOG: [CodeGen] Fix a warning

This patch fixes:

  clang/lib/CodeGen/CGExpr.cpp:5607:11: error: variable 'Result' is
  used uninitialized whenever 'if' condition is false
  [-Werror,-Wsometimes-uninitialized]

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index f70324d11a7562..0c7f48fe00603d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5601,7 +5601,7 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
   EmitNullabilityCheck(LV, RV.getScalarVal(), E->getExprLoc());
 
 if (LV.isBitField()) {
-  llvm::Value *Result;
+  llvm::Value *Result = nullptr;
   // If bitfield sanitizers are enabled we want to use the result
   // to check whether a truncation or sign change has occurred.
   if (SanOpts.has(SanitizerKind::ImplicitBitfieldConversion))



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


[clang] cc308f6 - [clang] Support __typeof_unqual__ in all C modes (#87392)

2024-04-03 Thread via cfe-commits

Author: Nathan Chancellor
Date: 2024-04-03T18:39:53+02:00
New Revision: cc308f60d41744b5920ec2e2e5b25e1273c8704b

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

LOG: [clang] Support __typeof_unqual__ in all C modes (#87392)

GCC has added __typeof_unqual__ to allow typeof_unqual to be used in all
C modes (not just C23 and newer), similar to __typeof__ and typeof.

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=607d9d50ee44163cee621cd991600acaf78c2fee

The Linux kernel would like to start using __typeof_unqual__ to strip
type qualifiers such as address spaces from inputs to macros but cannot
switch to C23 due to compiler version requirements.

Match GCC and allow __typeof_unqual__ in all C modes.

Closes: https://github.com/llvm/llvm-project/issues/76423
Link: 
https://lore.kernel.org/CAFULd4YG21NdF_qNVBGDtXO6xnaYFeRPvKicB=gpgUUqYE=4...@mail.gmail.com/

Added: 
clang/test/SemaCXX/typeof_unqual.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/TokenKinds.def
clang/test/Parser/c2x-typeof-ext-warns.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 096376af17acbb..e4c0e49ed6fc1c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -193,6 +193,9 @@ Non-comprehensive list of changes in this release
   with support for any unsigned integer type. Like the previous builtins, these
   new builtins are constexpr and may be used in constant expressions.
 
+- ``__typeof_unqual__`` is available in all C modes as an extension, which 
behaves
+  like ``typeof_unqual`` from C23, similar to ``__typeof__`` and ``typeof``.
+
 New Compiler Flags
 --
 - ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3a96f8a4d22bd1..800af0e6d04480 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -665,28 +665,30 @@ KEYWORD(__kindof , KEYOBJC)
 
 // Alternate spelling for various tokens.  There are GCC extensions in all
 // languages, but should not be disabled in strict conformance mode.
-ALIAS("__alignof__"  , __alignof  , KEYALL)
-ALIAS("__asm", asm, KEYALL)
-ALIAS("__asm__"  , asm, KEYALL)
-ALIAS("__attribute__", __attribute, KEYALL)
-ALIAS("__complex", _Complex   , KEYALL)
-ALIAS("__complex__"  , _Complex   , KEYALL)
-ALIAS("__const"  , const  , KEYALL)
-ALIAS("__const__", const  , KEYALL)
-ALIAS("__decltype"   , decltype   , KEYCXX)
-ALIAS("__imag__" , __imag , KEYALL)
-ALIAS("__inline" , inline , KEYALL)
-ALIAS("__inline__"   , inline , KEYALL)
-ALIAS("__nullptr", nullptr, KEYCXX)
-ALIAS("__real__" , __real , KEYALL)
-ALIAS("__restrict"   , restrict   , KEYALL)
-ALIAS("__restrict__" , restrict   , KEYALL)
-ALIAS("__signed" , signed , KEYALL)
-ALIAS("__signed__"   , signed , KEYALL)
-ALIAS("__typeof" , typeof , KEYALL)
-ALIAS("__typeof__"   , typeof , KEYALL)
-ALIAS("__volatile"   , volatile   , KEYALL)
-ALIAS("__volatile__" , volatile   , KEYALL)
+ALIAS("__alignof__"  , __alignof, KEYALL)
+ALIAS("__asm", asm  , KEYALL)
+ALIAS("__asm__"  , asm  , KEYALL)
+ALIAS("__attribute__", __attribute  , KEYALL)
+ALIAS("__complex", _Complex , KEYALL)
+ALIAS("__complex__"  , _Complex , KEYALL)
+ALIAS("__const"  , const, KEYALL)
+ALIAS("__const__", const, KEYALL)
+ALIAS("__decltype"   , decltype , KEYCXX)
+ALIAS("__imag__" , __imag   , KEYALL)
+ALIAS("__inline" , inline   , KEYALL)
+ALIAS("__inline__"   , inline   , KEYALL)
+ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__real__" , __real   , KEYALL)
+ALIAS("__restrict"   , restrict , KEYALL)
+ALIAS("__restrict__" , restrict , KEYALL)
+ALIAS("__signed" , signed   , KEYALL)
+ALIAS("__signed__"   , signed   , KEYALL)
+ALIAS("__typeof" , typeof   , KEYALL)
+ALIAS("__typeof__"   , typeof   , KEYALL)
+ALIAS("__typeof_unqual"  , typeof_unqual, KEYALL)
+ALIAS("__typeof_unqual__", typeof_unqual, KEYALL)
+ALIAS("__volatile"   , volatile , KEYALL)
+ALIAS("__volatile__" , volatile , KEYALL)
 
 // Type nullability.
 KEYWORD(_Nonnull , KEYALL)

diff  --git a/clang/test/Parser/c2x-typeof-ext-warns.c 
b/clang/test/Parser/c2x-typeof-ext-warns.c
index 387184497bd2eb..7a1f673827adeb 100644
--- a/clang/test/Parser/c2x-typeof-ext-warns.c
+++ b/clang/test/Parser/c2x-typeof-ext-warns.c
@@ -12,9 +12,12 @@
 // standards before 

[clang] 5b95931 - [NFC] Delete unintentionally added file

2024-04-03 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-04-03T11:24:48-05:00
New Revision: 5b959310b0fae723bd119ed8815bf1cb1a8c67d4

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

LOG: [NFC] Delete unintentionally added file

Added: 


Modified: 


Removed: 
clang/test/SemaHLSL/ArrayTemporary.ll



diff  --git a/clang/test/SemaHLSL/ArrayTemporary.ll 
b/clang/test/SemaHLSL/ArrayTemporary.ll
deleted file mode 100644
index 5eec0094865bae..00
--- a/clang/test/SemaHLSL/ArrayTemporary.ll
+++ /dev/null
@@ -1,76 +0,0 @@
-; ModuleID = 
'/Users/cbieneman/dev/llvm-project/clang/test/SemaHLSL/ArrayTemporary.hlsl'
-source_filename = 
"/Users/cbieneman/dev/llvm-project/clang/test/SemaHLSL/ArrayTemporary.hlsl"
-target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-pc-shadermodel6.3-library"
-
-%struct.Obj = type { float, i32 }
-
-@"__const.?call3@@YAXXZ.Arr" = private unnamed_addr constant [2 x [2 x float]] 
[[2 x float] zeroinitializer, [2 x float] [float 1.00e+00, float 
1.00e+00]], align 4
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn@@YAXY01M@Z"(ptr noundef byval([2 x float]) align 4 %x) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [2 x float], align 4
-  %agg.tmp = alloca [2 x float], align 4
-  call void @llvm.memset.p0.i32(ptr align 4 %Arr, i8 0, i32 8, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
8, i1 false)
-  call void @"?fn@@YAXY01M@Z"(ptr noundef byval([2 x float]) align 4 %agg.tmp)
-  ret void
-}
-
-; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
-declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) 
#1
-
-; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: 
readwrite)
-declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr 
noalias nocapture readonly, i32, i1 immarg) #2
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn2@@YAXY03UObj@@@Z"(ptr noundef byval([4 x %struct.Obj]) align 
4 %O) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call2@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [4 x %struct.Obj], align 4
-  %agg.tmp = alloca [4 x %struct.Obj], align 4
-  call void @llvm.memset.p0.i32(ptr align 4 %Arr, i8 0, i32 32, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
32, i1 false)
-  call void @"?fn2@@YAXY03UObj@@@Z"(ptr noundef byval([4 x %struct.Obj]) align 
4 %agg.tmp)
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn3@@YAXY111M@Z"(ptr noundef byval([2 x [2 x float]]) align 4 
%x) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call3@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [2 x [2 x float]], align 4
-  %agg.tmp = alloca [2 x [2 x float]], align 4
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Arr, ptr align 4 
@"__const.?call3@@YAXXZ.Arr", i32 16, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
16, i1 false)
-  call void @"?fn3@@YAXY111M@Z"(ptr noundef byval([2 x [2 x float]]) align 4 
%agg.tmp)
-  ret void
-}
-
-attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
-attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: 
readwrite) }
-
-!llvm.module.flags = !{!0, !1}
-!llvm.ident = !{!2}
-
-!0 = !{i32 1, !"wchar_size", i32 4}
-!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
-!2 = !{!"clang version 19.0.0git (g...@github.com:llvm/llvm-project.git 
64e1c15c520cf4ef2ddd887e76560903db2b)"}



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


[clang] 72e2e4f - [clang-format] Lambda parameter should be passed by const reference (#87306)

2024-04-03 Thread via cfe-commits

Author: Owen Pan
Date: 2024-04-03T09:00:23-07:00
New Revision: 72e2e4f7dc682fa3f6eda9f3cfbd20a8ffaac4e4

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

LOG: [clang-format] Lambda parameter should be passed by const reference 
(#87306)

Closes #87254.

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e41cf2902a6818..89e6c19b0af45c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3581,7 +3581,7 @@ cleanupAroundReplacements(StringRef Code, const 
tooling::Replacements ,
   // We need to use lambda function here since there are two versions of
   // `cleanup`.
   auto Cleanup = [](const FormatStyle , StringRef Code,
-std::vector Ranges,
+ArrayRef Ranges,
 StringRef FileName) -> tooling::Replacements {
 return cleanup(Style, Code, Ranges, FileName);
   };



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


[clang] 9808279 - [NFC] Bump DIAG_SIZE_FRONTEND (hit the limit downstream as of e05c1b46)

2024-04-03 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2024-04-03T08:12:16-07:00
New Revision: 9808279b0ec3663428fbf6294dfdd1d4f70b1cda

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

LOG: [NFC] Bump DIAG_SIZE_FRONTEND (hit the limit downstream as of e05c1b46)

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticIDs.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 5ff782c7f8c7e8..bce7605b95ba43 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -32,7 +32,7 @@ namespace clang {
 enum {
   DIAG_SIZE_COMMON=  300,
   DIAG_SIZE_DRIVER=  400,
-  DIAG_SIZE_FRONTEND  =  150,
+  DIAG_SIZE_FRONTEND  =  200,
   DIAG_SIZE_SERIALIZATION =  120,
   DIAG_SIZE_LEX   =  400,
   DIAG_SIZE_PARSE =  700,



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


[clang] 450f195 - [clang][UBSan] Add implicit conversion check for bitfields (#75481)

2024-04-03 Thread via cfe-commits

Author: Axel Lundberg
Date: 2024-04-03T08:55:03-04:00
New Revision: 450f1952aced87584a53485d1ba1c2f77c3835a1

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

LOG: [clang][UBSan] Add implicit conversion check for bitfields (#75481)

This patch implements the implicit truncation and implicit sign change
checks for bitfields using UBSan. E.g.,
`-fsanitize=implicit-bitfield-truncation` and
`-fsanitize=implicit-bitfield-sign-change`.

Added: 
clang/test/CodeGen/ubsan-bitfield-conversion.c
clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Driver/fsanitize.c
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3237842fa1ceb1..096376af17acbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -195,6 +195,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -208,6 +212,9 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 8f58c92bd2a163..531d56e313826c 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,6 +148,11 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
+  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
+ integer of larger bit width to smaller bitfield, if that results in data
+ loss. This includes unsigned/signed truncations and sign changes, 
similarly
+ to how the ``-fsanitize=implicit-integer-conversion`` group works, but
+ explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -193,8 +198,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-conversion``). Both of these two issues are handled
- by ``-fsanitize=implicit-conversion`` group of checks.
+ ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
+ by ``-fsanitize=implicit-integer-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -202,7 +207,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-conversion``).
+ (see ``-fsanitize=implicit-integer-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -224,11 +229,15 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  conversions that change the arithmetic value of the integer. Enables
  ``implicit-signed-integer-truncation`` and 

Re: [clang] 468dc32 - [NFC] Make `DeclContext::noload_lookup()` accept transparent context

2024-04-03 Thread Aaron Ballman via cfe-commits
I'm not opposed to the changes, but they do seem like functional
changes -- we used to trigger an assertion and now we're swallowing it
and changing the behavior; can you add a test case that would have
previously asserted?

~Aaron

On Wed, Apr 3, 2024 at 3:05 AM Chuanqi Xu via cfe-commits
 wrote:
>
>
> Author: Chuanqi Xu
> Date: 2024-04-03T15:03:07+08:00
> New Revision: 468dc32ff55d19f55132cbcc4d6ceb1f6d1c12cf
>
> URL: 
> https://github.com/llvm/llvm-project/commit/468dc32ff55d19f55132cbcc4d6ceb1f6d1c12cf
> DIFF: 
> https://github.com/llvm/llvm-project/commit/468dc32ff55d19f55132cbcc4d6ceb1f6d1c12cf.diff
>
> LOG: [NFC] Make `DeclContext::noload_lookup()` accept transparent context
>
> Now the `DeclContext::noload_lookup()` asserts that 'this' is not a
> transparent context. However, this is not consistent with
> `DeclContext::lookup()`, which will lookup into its parent context if
> 'this' is a transparent context.
>
> This patch makes the behavior of `DeclContext::noload_lookup()` to be
> consistent with `DeclContext::lookup()`, to lookup into the parent
> context if 'this' is a transparent context.
>
> Added:
>
>
> Modified:
> clang/lib/AST/DeclBase.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
> index 2cbb86b31b5e2e..66a727d9dd0c39 100644
> --- a/clang/lib/AST/DeclBase.cpp
> +++ b/clang/lib/AST/DeclBase.cpp
> @@ -1852,9 +1852,9 @@ DeclContext::lookup(DeclarationName Name) const {
>
>  DeclContext::lookup_result
>  DeclContext::noload_lookup(DeclarationName Name) {
> -  assert(getDeclKind() != Decl::LinkageSpec &&
> - getDeclKind() != Decl::Export &&
> - "should not perform lookups into transparent contexts");
> +  // For transparent DeclContext, we should lookup in their enclosing 
> context.
> +  if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
> +return getParent()->noload_lookup(Name);
>
>DeclContext *PrimaryContext = getPrimaryContext();
>if (PrimaryContext != this)
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 956b47b - [X86_32] Teach X86_32 va_arg to ignore empty structs. (#86075)

2024-04-03 Thread via cfe-commits

Author: Longsheng Mou
Date: 2024-04-03T19:12:12+08:00
New Revision: 956b47b48616148c15f8f95d76d5e0c215fe095c

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

LOG: [X86_32] Teach X86_32 va_arg to ignore empty structs. (#86075)

Empty structs are ignored for parameter passing purposes, but va_arg was
incrementing the pointer anyway for that the size of empty struct in c++
is 1 byte, which could lead to va_list getting out of sync. Fix #86057.

Added: 
clang/test/CodeGenCXX/x86_32-vaarg.cpp

Modified: 
clang/lib/CodeGen/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1146a851a7715d..c831777699f627 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1069,6 +1069,12 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction ,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  CCState State(*const_cast(CGF.CurFnInfo));
+  ABIArgInfo AI = classifyArgumentType(Ty, State, /*ArgIndex*/ 0);
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore())
+return CGF.CreateMemTemp(Ty);
+
   // x86-32 changes the alignment of certain arguments on the stack.
   //
   // Just messing with TypeInfo like this works because we never pass

diff  --git a/clang/test/CodeGenCXX/x86_32-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
new file mode 100644
index 00..dcc2f7f96a40f1
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+typedef struct {} empty;
+
+// CHECK-LABEL: @_Z17empty_record_testiz(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RESULT_PTR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[LIST:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_EMPTY:%.*]], align 1
+// CHECK-NEXT:store ptr [[AGG_RESULT:%.*]], ptr [[RESULT_PTR]], align 4
+// CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
+// CHECK-NEXT:call void @llvm.va_start.p0(ptr [[LIST]])
+// CHECK-NEXT:ret void
+//
+empty empty_record_test(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, empty);
+}



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


[clang] 37eb0d4 - [NFC] Check the nullness of pointer before dereference it in the assertion

2024-04-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-03T16:39:02+08:00
New Revision: 37eb0d4948dad6d2399915fde6eb5800c3fe825b

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

LOG: [NFC] Check the nullness of pointer before dereference it in the assertion

This was part of https://github.com/llvm/llvm-project/pull/85050.

It is suggested to split the unrelated change as much as possible. So
here is the patch.

Added: 


Modified: 
clang/lib/Serialization/GeneratePCH.cpp

Removed: 




diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index fa712264d54a97..2fece29f34487e 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -102,7 +102,7 @@ ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor ,
 
 Module *ReducedBMIGenerator::getEmittingModule(ASTContext ) {
   Module *M = Ctx.getCurrentNamedModule();
-  assert(M->isNamedModuleUnit() &&
+  assert(M && M->isNamedModuleUnit() &&
  "ReducedBMIGenerator should only be used with C++20 Named modules.");
   return M;
 }



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


[clang] 72c29fa - [C++20] [Modules] [Driver] Emit unused argument warning if we use '-fmodule-output' with non-module input

2024-04-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-03T16:28:05+08:00
New Revision: 72c29fa9e226a928b3d3a01d74f6b44a0b31b7d4

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

LOG: [C++20] [Modules] [Driver] Emit unused argument warning if we use 
'-fmodule-output' with non-module input

We required the file name of an 'importable module unit' should end
with .cppm (or .ccm, .cxxm, .c++m).

But the driver can accept '-fmodule-output' for files with normal
suffixes (e.g., .cpp). This is somewhat inconsistency.

In this patch, we only claim the option `-fmodule-output` is used if
the type of the input file is modules related. Then now the compiler
will emit 'unused argument' warnings if the input file is not modules
related.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/module-output.cppm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d5ce54e185600c..3237842fa1ceb1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -328,6 +328,9 @@ Improvements to Clang's diagnostics
 - New ``-Wformat-signedness`` diagnostic that warn if the format string 
requires an
   unsigned argument and the argument is signed and vice versa.
 
+- Clang now emits ``unused argument`` warning when the -fmodule-output flag is 
used
+  with an input that is not of type c++-module.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b03ac6018d2b80..7fd6ad6a47d46f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4045,9 +4045,18 @@ static bool RenderModulesOptions(Compilation , const 
Driver ,
   // module fragment.
   CmdArgs.push_back("-fskip-odr-check-in-gmf");
 
-  // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
-  Args.ClaimAllArgs(options::OPT_fmodule_output);
-  Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+  // We need to include the case the input file is a module file here.
+  // Since the default compilation model for C++ module interface unit will
+  // create temporary module file and compile the temporary module file
+  // to get the object file. Then the `-fmodule-output` flag will be
+  // brought to the second compilation process. So we have to claim it for
+  // the case too.
+  if (Input.getType() == driver::types::TY_CXXModule ||
+  Input.getType() == driver::types::TY_PP_CXXModule ||
+  Input.getType() == driver::types::TY_ModuleFile) {
+Args.ClaimAllArgs(options::OPT_fmodule_output);
+Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+  }
 
   return HaveModules;
 }

diff  --git a/clang/test/Driver/module-output.cppm 
b/clang/test/Driver/module-output.cppm
index d0cab0cbcb31c7..dea9cf998a5401 100644
--- a/clang/test/Driver/module-output.cppm
+++ b/clang/test/Driver/module-output.cppm
@@ -33,6 +33,9 @@
 // RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm 
-fmodule-output -c -fsyntax-only \
 // RUN:   -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-NOT-USED
 
+// Test that we can emit a warning if the type of the input file is not a 
module interface unit.
+// RUN: %clang -std=c++20 %t/a.cpp -fmodule-output -c -o %t/a.o -### 2>&1 | 
FileCheck %t/a.cpp
+
 //--- Hello.cppm
 export module Hello;
 
@@ -55,3 +58,8 @@ export module AnotherModule;
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" 
"{{.*}}/Hello-{{.*}}.o" "-x" "pcm" "{{.*}}/Hello.pcm"
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" 
"AnotherModule.cppm" {{.*}}"-o" "{{.*}}/AnotherModule.pcm" "-x" "c++" 
"{{.*}}/AnotherModule.cppm"
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "AnotherModule.cppm" {{.*}}"-o" 
"{{.*}}/AnotherModule-{{.*}}.o" "-x" "pcm" "{{.*}}/AnotherModule.pcm"
+
+//--- a.cpp
+export module a;
+
+// CHECK: warning: argument unused during compilation: '-fmodule-output'



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


[clang] cd75178 - Revert "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format (#87149)"

2024-04-03 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2024-04-03T16:10:19+08:00
New Revision: cd7517859eef14d8b38cec2d52c0625a58c645a2

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

LOG: Revert "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format 
(#87149)"

This reverts commit 4b25053ae47f50095371a663391baadfd2694eb0.

There're failures in some target.

Added: 


Modified: 
clang/lib/Driver/ToolChains/MSVC.h

Removed: 
clang/test/Misc/win32-elf.c



diff  --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 3950a8ed38e8b4..48369e030aade2 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,8 +61,9 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override 
{
-return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
-   : llvm::codegenoptions::DIF_DWARF;
+return getTriple().isOSBinFormatMachO()
+   ? llvm::codegenoptions::DIF_DWARF
+   : llvm::codegenoptions::DIF_CodeView;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning

diff  --git a/clang/test/Misc/win32-elf.c b/clang/test/Misc/win32-elf.c
deleted file mode 100644
index f75281dc418727..00
--- a/clang/test/Misc/win32-elf.c
+++ /dev/null
@@ -1,5 +0,0 @@
-// Check that basic use of win32-elf targets works.
-// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf %s
-
-// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf -g %s -### 2>&1 | 
FileCheck %s -check-prefix=DEBUG-INFO
-// DEBUG-INFO: -dwarf-version={{.*}}



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


[clang] 4b25053 - [Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format (#87149)

2024-04-03 Thread via cfe-commits

Author: Phoebe Wang
Date: 2024-04-03T15:21:34+08:00
New Revision: 4b25053ae47f50095371a663391baadfd2694eb0

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

LOG: [Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format (#87149)

We have many problems to use CodeView for a win32-elf target, e.g.,
#87140 and `error: .seh_* directives are not supported on this target`.

Fixes: #87140

Added: 
clang/test/Misc/win32-elf.c

Modified: 
clang/lib/Driver/ToolChains/MSVC.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 48369e030aade2..3950a8ed38e8b4 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,9 +61,8 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override 
{
-return getTriple().isOSBinFormatMachO()
-   ? llvm::codegenoptions::DIF_DWARF
-   : llvm::codegenoptions::DIF_CodeView;
+return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
+   : llvm::codegenoptions::DIF_DWARF;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning

diff  --git a/clang/test/Misc/win32-elf.c b/clang/test/Misc/win32-elf.c
new file mode 100644
index 00..f75281dc418727
--- /dev/null
+++ b/clang/test/Misc/win32-elf.c
@@ -0,0 +1,5 @@
+// Check that basic use of win32-elf targets works.
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf %s
+
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf -g %s -### 2>&1 | 
FileCheck %s -check-prefix=DEBUG-INFO
+// DEBUG-INFO: -dwarf-version={{.*}}



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


[clang] 468dc32 - [NFC] Make `DeclContext::noload_lookup()` accept transparent context

2024-04-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-03T15:03:07+08:00
New Revision: 468dc32ff55d19f55132cbcc4d6ceb1f6d1c12cf

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

LOG: [NFC] Make `DeclContext::noload_lookup()` accept transparent context

Now the `DeclContext::noload_lookup()` asserts that 'this' is not a
transparent context. However, this is not consistent with
`DeclContext::lookup()`, which will lookup into its parent context if
'this' is a transparent context.

This patch makes the behavior of `DeclContext::noload_lookup()` to be
consistent with `DeclContext::lookup()`, to lookup into the parent
context if 'this' is a transparent context.

Added: 


Modified: 
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 2cbb86b31b5e2e..66a727d9dd0c39 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1852,9 +1852,9 @@ DeclContext::lookup(DeclarationName Name) const {
 
 DeclContext::lookup_result
 DeclContext::noload_lookup(DeclarationName Name) {
-  assert(getDeclKind() != Decl::LinkageSpec &&
- getDeclKind() != Decl::Export &&
- "should not perform lookups into transparent contexts");
+  // For transparent DeclContext, we should lookup in their enclosing context.
+  if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
+return getParent()->noload_lookup(Name);
 
   DeclContext *PrimaryContext = getPrimaryContext();
   if (PrimaryContext != this)



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


[clang] a75b3e9 - [NFC] [Serialization] Extract logics to write decls and types into a standalone function

2024-04-03 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-03T14:55:20+08:00
New Revision: a75b3e949da588bafd521eff6d265f3ea2f854c2

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

LOG: [NFC] [Serialization] Extract logics to write decls and types into a 
standalone function

This patch extract logics in ASTWriter::WriteASTCore about writing decls
and types into a standalone function. The WriteASTCore function is
pretty long and hard to read. It should be helpful for readability to extract 
the common
logics into a standalone function.

This is also helpful for further changes e.g., removing unreachable
declarations.

Added: 


Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index bd310b6c7a5cdd..214eb3601148b0 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -542,6 +542,7 @@ class ASTWriter : public ASTDeserializationListener,
   void WriteReferencedSelectorsPool(Sema );
   void WriteIdentifierTable(Preprocessor , IdentifierResolver ,
 bool IsModule);
+  void WriteDeclAndTypes(ASTContext );
   void WriteDeclUpdatesBlocks(RecordDataImpl );
   void WriteDeclContextVisibleUpdate(const DeclContext *DC);
   void WriteFPPragmaOptions(const FPOptionsOverride );

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 0148eb446db6b5..ba6a8a5e16e4e7 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5107,69 +5107,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema , 
StringRef isysroot,
   for (auto *D : SemaRef.DeclsToCheckForDeferredDiags)
 DeclsToCheckForDeferredDiags.push_back(GetDeclRef(D));
 
-  {
-auto Abv = std::make_shared();
-Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE));
-Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
-Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
-UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
-  }
-
-  RecordData DeclUpdatesOffsetsRecord;
-
-  // Keep writing types, declarations, and declaration update records
-  // until we've emitted all of them.
-  Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5);
-  DeclTypesBlockStartOffset = Stream.GetCurrentBitNo();
-  WriteTypeAbbrevs();
-  WriteDeclAbbrevs();
-  do {
-WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord);
-while (!DeclTypesToEmit.empty()) {
-  DeclOrType DOT = DeclTypesToEmit.front();
-  DeclTypesToEmit.pop();
-  if (DOT.isType())
-WriteType(DOT.getType());
-  else
-WriteDecl(Context, DOT.getDecl());
-}
-  } while (!DeclUpdates.empty());
-  Stream.ExitBlock();
-
-  DoneWritingDeclsAndTypes = true;
-
-  // These things can only be done once we've written out decls and types.
-  WriteTypeDeclOffsets();
-  if (!DeclUpdatesOffsetsRecord.empty())
-Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
-
-  // Create a lexical update block containing all of the declarations in the
-  // translation unit that do not come from other AST files.
-  {
-SmallVector NewGlobalKindDeclPairs;
-for (const auto *D : TU->noload_decls()) {
-  if (!D->isFromASTFile()) {
-NewGlobalKindDeclPairs.push_back(D->getKind());
-NewGlobalKindDeclPairs.push_back(GetDeclRef(D));
-  }
-}
-
-auto Abv = std::make_shared();
-Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL));
-Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
-unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
-
-RecordData::value_type Record[] = {TU_UPDATE_LEXICAL};
-Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record,
-  bytes(NewGlobalKindDeclPairs));
-  }
-
-  // And a visible updates block for the translation unit.
-  WriteDeclContextVisibleUpdate(TU);
-
-  // If we have any extern "C" names, write out a visible update for them.
-  if (Context.ExternCContext)
-WriteDeclContextVisibleUpdate(Context.ExternCContext);
+  WriteDeclAndTypes(Context);
 
   WriteFileDeclIDsMap();
   WriteSourceManagerBlock(Context.getSourceManager(), PP);
@@ -5255,10 +5193,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema , 
StringRef isysroot,
   if (!DeleteExprsToAnalyze.empty())
 Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze);
 
-  // Write the visible updates to DeclContexts.
-  for (auto *DC : UpdatedDeclContexts)
-WriteDeclContextVisibleUpdate(DC);
-
   if (!WritingModule) {
 // Write the submodules that were imported, if any.
 struct ModuleInfo {
@@