[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-28 Thread Josh Learn via Phabricator via cfe-commits
guitard0g marked an inline comment as done.
guitard0g added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1952
 
+def Escape : Attr {
+  let Spellings = [Clang<"escape">];

NoQ wrote:
> Shouldn't both this attribute and the one above be `InheritableAttr`?
> 
> Comments in this file say:
> ```
> /// An inheritable attribute is inherited by later redeclarations.
> ```
> Which is arguably exactly what we want? Like, it should be sufficient to put 
> the attribute into the header, there's no need to duplicate it in the 
> implementation?
Oh! Good point, I totally agree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107026

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


[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-28 Thread Josh Learn via Phabricator via cfe-commits
guitard0g updated this revision to Diff 362643.
guitard0g added a comment.
Herald added a subscriber: jdoerfert.

Change Escape/NoEscape to use InheritableAttr and update an attribute test to 
fix test failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107026

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/AST/ast-dump-attr.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function)
 // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
+// CHECK-NEXT: Escape (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: ExcludeFromExplicitInstantiation (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: ExternalSourceSymbol ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
 // CHECK-NEXT: FlagEnum (SubjectMatchRule_enum)
Index: clang/test/AST/ast-dump-attr.m
===
--- clang/test/AST/ast-dump-attr.m
+++ clang/test/AST/ast-dump-attr.m
@@ -65,4 +65,8 @@
 // CHECK-NEXT: | `-NoEscapeAttr
 // CHECK-NEXT: |-ParmVarDecl{{.*}} Test14 'int'
 // CHECK-NEXT: `-NSConsumesSelfAttr
+-(void)Test15: (int *) [[clang::escape]] Test16;
+// CHECK: ObjCMethodDecl{{.*}} Test15: 'void'
+// CHECK-NEXT: -ParmVarDecl{{.*}} Test16 'int *'
+// CHECK-NEXT: `-EscapeAttr
 @end
Index: clang/test/AST/ast-dump-attr.cpp
===
--- clang/test/AST/ast-dump-attr.cpp
+++ clang/test/AST/ast-dump-attr.cpp
@@ -200,6 +200,15 @@
   // CHECK-NEXT: NoEscapeAttr
 }
 
+namespace TestEscape {
+  void escapeFunc(int *p0, __attribute__((escape)) int *p1) {}
+  // CHECK: NamespaceDecl{{.*}} TestEscape
+  // CHECK-NEXT: `-FunctionDecl{{.*}} escapeFunc 'void (int *, int *)'
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: EscapeAttr
+}
+
 namespace TestSuppress {
   [[gsl::suppress("at-namespace")]];
   // CHECK: NamespaceDecl{{.*}} TestSuppress
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1553,11 +1553,11 @@
   D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL));
 }
 
-static void handleNoEscapeAttr(Sema , Decl *D, const ParsedAttr ) {
+static void handleXEscapeAttr(Sema , Decl *D, const ParsedAttr ) {
   if (D->isInvalidDecl())
 return;
 
-  // noescape only applies to pointer types.
+  // escape/noescape only applies to pointer types.
   QualType T = cast(D)->getType();
   if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
@@ -1565,7 +1565,16 @@
 return;
   }
 
-  D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
+  switch (AL.getKind()) {
+  default:
+llvm_unreachable("invalid escape attribute");
+  case ParsedAttr::AT_NoEscape:
+handleSimpleAttribute(S, D, AL);
+return;
+  case ParsedAttr::AT_Escape:
+handleSimpleAttribute(S, D, AL);
+return;
+  }
 }
 
 static void handleAssumeAlignedAttr(Sema , Decl *D, const ParsedAttr ) {
@@ -8007,8 +8016,9 @@
   case ParsedAttr::AT_ReturnsNonNull:
 handleReturnsNonNullAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_Escape:
   case ParsedAttr::AT_NoEscape:
-handleNoEscapeAttr(S, D, AL);
+handleXEscapeAttr(S, D, AL);
 break;
   case ParsedAttr::AT_AssumeAligned:
 handleAssumeAlignedAttr(S, D, AL);
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -253,6 +253,27 @@
   }];
 }
 
+def EscapeDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+``escape`` placed on a function parameter of a pointer type is used to indicate
+that the pointer can escape the function. This means that a reference to the object
+the pointer points to that is derived from the parameter value may survive
+after the 

[PATCH] D106849: [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

2021-07-28 Thread Freddy, Ye via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58712987e56f: [NFC][X86] add missing tests in 
clang/test/CodeGen/attr-target-mv.c (authored by FreddyYe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106849

Files:
  clang/test/CodeGen/attr-target-mv.c


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5871298 - [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

2021-07-28 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2021-07-29T13:28:10+08:00
New Revision: 58712987e56fb598ac49da7fbe6e6a78c787637b

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

LOG: [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

Reviewed By: pengfei

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

Added: 


Modified: 
clang/test/CodeGen/attr-target-mv.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-target-mv.c 
b/clang/test/CodeGen/attr-target-mv.c
index a01cef58ffa83..9fa3e3b5f415e 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@ void calls_pr50025c() { pr50025c(); }
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()



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


[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 362637.
ellis added a comment.

Fix broken coro test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; CHECK: bb.1:
   ; CHECK:   successors: %bb.3(0x8000)
-  ; CHECK:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]], debug-location !DILocation(line: 8, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ADD]](s32), $noreg, !9, !DIExpression(), debug-location 

[PATCH] D67429: Improve code generation for thread_local variables:

2021-07-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D67429#2566099 , @wolfgangp wrote:

> Ping. Just wondering if there are any new insights on the issue reported in 
> PR48030 .

I confirm that https://bugs.llvm.org/show_bug.cgi?id=48030 still fails. 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67429

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


[PATCH] D103385: [clang-tidy] bugprone-forwarding-reference-overload: support non-type template parameters

2021-07-28 Thread Jesse Towner via Phabricator via cfe-commits
jwtowner marked 2 inline comments as done.
jwtowner added a comment.

> Thanks! What name and email address would you like me to use for patch 
> attribution?

The following will do:

Jesse Towner 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103385

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


[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-28 Thread Josh Learn via Phabricator via cfe-commits
guitard0g added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:260
+``escape`` placed on a function parameter of a pointer type is used to indicate
+that the pointer can escape the function. This means that a reference to the 
object
+the pointer points to that is derived from the parameter value may survive

NoQ wrote:
> Are you sure you want "can escape" instead of "will escape"? In the former 
> case it's impossible to implement the warning without false positives ("well, 
> it says it may escape, but I know for sure that if I pass these other 
> arguments then it won't escape"). In the latter case, of course, a lot of 
> places where the value escapes conditionally won't be able to wear the 
> attribute. Do I understand correctly that you want to proceed with the more 
> aggressive diagnostic?
Hmm that's an interesting question. Initially my thought was that any 
possibility of escaping should eliminate the option of passing in a temporary 
pointer, which I think is reasonable in Swift's implicit bridging use-case. In 
terms of the API contract, I was thinking that any API author who annotates 
their function parameter with 'escaping' is effectively saying you shouldn't 
pass in a pointer that you're not comfortable escaping. I think it may be a 
little restrictive to say that the pointer will always escape for certain, but 
I do think that anybody using a function that takes an escaping parameter 
should treat this as if it were always escaping (if that makes sense). I 
suppose my question then would be, do you think it's better to say "will 
escape" if that's what the client calling into an API should expect (even 
though the pointer might not always escape in the implementation)? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107026

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-07-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Regardless of the kind of pointer, sounds like we need to do something about 
that API quirk. Eg., it *must* be possible to model a destructor of a 
`std::unique_ptr` as a no-op when the tracked raw pointer value is an 
`UnknownVal`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D106924#2911145 , @mstorsjo wrote:

> @Meinersbur After landing this, can you coordinate with @tstellar to get an 
> ack for backporting this to the 13.x release branch, which also suffers from 
> the regression?

Release blocker has been created: http://llvm.org/PR51261


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

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


[PATCH] D107025: Take OptimizationLevel class out of Pass Builder

2021-07-28 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added inline comments.



Comment at: llvm/include/llvm/Passes/OptimizationLevel.h:14
+//===--===//
+
+class OptimizationLevel final {

this should be in the llvm namespace



Comment at: llvm/include/llvm/Passes/OptimizationLevel.h:15
+
+class OptimizationLevel final {
+  unsigned SpeedLevel = 2;

Make sure this has a header guard - i.e. a 
#ifndef LLVM_PASSES_OPTIMIZATIONLEVEL_H
#define LLVM_PASSES_OPTIMIZATIONLEVEL_H
... the file
#endif 



Comment at: llvm/include/llvm/Passes/OptimizationLevel.h:21
+// Check that only valid combinations are passed.
+assert(SpeedLevel <= 3 &&
+   "Optimization level for speed should be 0, 1, 2, or 3");

you're probably missing some #include; for assert, it's 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107025

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


[PATCH] D106614: [Clang] add btf_tag attribute

2021-07-28 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1835
+  let Args = [StringArgument<"BTFTag">];
+  let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;
+  let Documentation = [BTFTagDocs];

aaron.ballman wrote:
> ObjC method declarations?
> 
> Also, can this apply to *any* kind of variable declaration? e.g., does it do 
> something useful on a `constexpr` variable that never gets emitted at runtime?
The attribute named btf_tag and it is supposed to be used for bpf programs and 
kernel, and currently all our use cases are C, so hence ObjC is not considered 
and I marked it as COnly.

constexpr is not our use case so it is okay the variable (and possible 
attricute) is gone.



Comment at: clang/include/clang/Basic/AttrDocs.td:2019
+targets. This attribute may be attached to a struct/union, struct/union field,
+function or variables declaration. If -g is specified, the ARGUMENT info will
+be preserved in IR and be emitted to dwarf. For BPF target, the ARGUMENT info

aaron.ballman wrote:
> yonghong-song wrote:
> > anakryiko wrote:
> > > can it be also applied to function's argument?
> > The attribute does apply to function argument. I missed it in the 
> > documentation. Will add it.
> 
thanks! Will change.



Comment at: clang/include/clang/Basic/AttrDocs.td:2020
+function or variables declaration. If -g is specified, the ARGUMENT info will
+be preserved in IR and be emitted to dwarf. For BPF target, the ARGUMENT info
+will be emitted to .BTF ELF section too.

aaron.ballman wrote:
> 
Thanks. Will change.



Comment at: clang/test/Sema/attr-btf_tag.c:15
+  return arg->a;
+}

aaron.ballman wrote:
> There are quite a few test cases that are missing. Can you please add tests 
> for applying the attribute to something invalid (like an enumeration), not 
> given any arguments, given too many arguments.
> 
> Also missing are test cases for how this attribute merges on redeclarations, 
> especially with conflicting arguments. e.g.,
> ```
> void __attribute__((btf_tag("tag"))) bar();
> void __attribute__((btf_tag("derp"))) bar() {} // Which argument "wins" or 
> should this be an error?
> ```
> Should it be valid to apply this to an incomplete structure declaration? e.g.,
> ```
> struct __attribute__((btf_tag("tag"))) S; // Should this be valid or invalid?
> ```
Thanks. I will add more test cases about redeclaration. For redeclaration case, 
my current thinking is they should match *exactly*. Otherwise, we should fail 
the compilation. I guess some implementation may be needed here.

For forward declaration, the current intention is not allowed. the btf_tag 
should just appear in the actual type definition.

For other types like enum, we didn't find a use case for that yet and that is 
why is not supported. I will add more tests to cover such invalid cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106614

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


[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> may have other non-Swift use-cases for diagnostics.

I'm looking forward to taking advantage of this attribute in the static 
analyzer's `StackAddrEscapeChecker`!




Comment at: clang/include/clang/Basic/Attr.td:1952
 
+def Escape : Attr {
+  let Spellings = [Clang<"escape">];

Shouldn't both this attribute and the one above be `InheritableAttr`?

Comments in this file say:
```
/// An inheritable attribute is inherited by later redeclarations.
```
Which is arguably exactly what we want? Like, it should be sufficient to put 
the attribute into the header, there's no need to duplicate it in the 
implementation?



Comment at: clang/include/clang/Basic/AttrDocs.td:260
+``escape`` placed on a function parameter of a pointer type is used to indicate
+that the pointer can escape the function. This means that a reference to the 
object
+the pointer points to that is derived from the parameter value may survive

Are you sure you want "can escape" instead of "will escape"? In the former case 
it's impossible to implement the warning without false positives ("well, it 
says it may escape, but I know for sure that if I pass these other arguments 
then it won't escape"). In the latter case, of course, a lot of places where 
the value escapes conditionally won't be able to wear the attribute. Do I 
understand correctly that you want to proceed with the more aggressive 
diagnostic?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107026

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


[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

2021-07-28 Thread Anjan Kumar via Phabricator via cfe-commits
anjankgk updated this revision to Diff 362622.
anjankgk marked an inline comment as done.
anjankgk added a comment.

Change the error msg to include target information.


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

https://reviews.llvm.org/D106688

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/Xlinker-args.c


Index: clang/test/Driver/Xlinker-args.c
===
--- clang/test/Driver/Xlinker-args.c
+++ clang/test/Driver/Xlinker-args.c
@@ -11,10 +11,20 @@
 // RUN:   -e _start -T a.lds -Xlinker one -Xlinker --no-demangle \
 // RUN:   -Wl,two,--no-demangle,three -Xlinker four -z five -r %s 2> %t
 // RUN: FileCheck -check-prefix=LINUX < %t %s
-//
+
+// RUN: %clang -target powerpc-unknown-aix -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=AIX < %t %s
+
+// RUN: %clang -target powerpc-unknown-linux -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=NOT-AIX < %t %s
+
 // DARWIN-NOT: --no-demangle
 // DARWIN: "one" "two" "three" "four" "-z" "five" "-r"
 // LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" 
"-r" {{.*}} "-T" "a.lds"
+// AIX: "-b" "one" 
+// NOT-AIX: error: unsupported option '-b one'
 
 // Check that we forward '-Xlinker' and '-Wl,' on Windows.
 // RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -257,6 +257,17 @@
 // Otherwise, this is a linker input argument.
 const Arg  = II.getInputArg();
 
+if (A.getOption().matches(options::OPT_b)) {
+  const llvm::Triple  = TC.getTriple();
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
+<< A.getAsString(Args);
+  }
+  // Pass -b prefix for AIX linker.
+  A.claim();
+  A.render(Args, CmdArgs);
+}
+
 // Handle reserved library options.
 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
   TC.AddCXXStdlibLibArgs(Args, CmdArgs);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -815,7 +815,9 @@
 def bind__at__load : Flag<["-"], "bind_at_load">;
 def bundle__loader : Separate<["-"], "bundle_loader">;
 def bundle : Flag<["-"], "bundle">;
-def b : JoinedOrSeparate<["-"], "b">, Flags<[Unsupported]>;
+def b : JoinedOrSeparate<["-"], "b">, Flags<[LinkerInput, RenderAsInput]>,
+  HelpText<"Pass -b  to the linker on AIX (only).">, MetaVarName<"">,
+  Group;
 def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group, 
Flags<[CC1Option]>,
   HelpText<"OpenCL only. This option disables all optimizations. By default 
optimizations are enabled.">;
 def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, 
Group, Flags<[CC1Option]>,


Index: clang/test/Driver/Xlinker-args.c
===
--- clang/test/Driver/Xlinker-args.c
+++ clang/test/Driver/Xlinker-args.c
@@ -11,10 +11,20 @@
 // RUN:   -e _start -T a.lds -Xlinker one -Xlinker --no-demangle \
 // RUN:   -Wl,two,--no-demangle,three -Xlinker four -z five -r %s 2> %t
 // RUN: FileCheck -check-prefix=LINUX < %t %s
-//
+
+// RUN: %clang -target powerpc-unknown-aix -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=AIX < %t %s
+
+// RUN: %clang -target powerpc-unknown-linux -### \
+// RUN:   -b one %s 2> %t
+// RUN: FileCheck -check-prefix=NOT-AIX < %t %s
+
 // DARWIN-NOT: --no-demangle
 // DARWIN: "one" "two" "three" "four" "-z" "five" "-r"
 // LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" "-r" {{.*}} "-T" "a.lds"
+// AIX: "-b" "one" 
+// NOT-AIX: error: unsupported option '-b one'
 
 // Check that we forward '-Xlinker' and '-Wl,' on Windows.
 // RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -257,6 +257,17 @@
 // Otherwise, this is a linker input argument.
 const Arg  = II.getInputArg();
 
+if (A.getOption().matches(options::OPT_b)) {
+  const llvm::Triple  = TC.getTriple();
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
+<< A.getAsString(Args);
+  }
+  // Pass -b prefix for AIX linker.
+  A.claim();
+  A.render(Args, CmdArgs);
+}
+
 // Handle reserved library options.
 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
   TC.AddCXXStdlibLibArgs(Args, CmdArgs);
Index: 

[PATCH] D106974: libcang: Add missing function to libclang.map

2021-07-28 Thread Tom Stellard via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4edb2b1ba0b: libcang: Add missing function to libclang.map 
(authored by tstellar).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106974

Files:
  clang/tools/libclang/libclang.map


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources;
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources;
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a4edb2b - libcang: Add missing function to libclang.map

2021-07-28 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2021-07-28T21:06:40-07:00
New Revision: a4edb2b1ba0bda9042e87ca3f3e1b9f70598df9a

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

LOG: libcang: Add missing function to libclang.map

This function is marked with CINDEX_LINKAGE, but was never added to the
export list / linker script.

Reviewed By: jrtc27

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

Added: 


Modified: 
clang/tools/libclang/libclang.map

Removed: 




diff  --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 932903bb41409..aee46b1448457 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@ LLVM_13 {
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources;
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;



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


[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

2021-07-28 Thread Anjan Kumar via Phabricator via cfe-commits
anjankgk marked an inline comment as done.
anjankgk added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:263
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt)
+<< A.getAsString(Args);

ZarkoCA wrote:
> anjankgk wrote:
> > ZarkoCA wrote:
> > > nit, I prefer this error message but it's up to you. 
> > I intentionally chose that error msg (without target mention) since that's 
> > the one the original option threw (existing '-b' option which was defined 
> > as unsupported for all the platforms).
> I see, that makes sense.
> 
> But now with your patch this option is supported even if only for the AIX 
> target. So we could make the case to use the suggested error message. That 
> said, I am still fine with what you choose. 
I actually agree on your point. So, eventhough my intention was to leave the 
behavior on other (non-AIX) platforms unaffected, the change causes the 
behavior of the option to be more target-specific - since it's now 
valid/supported option on AIX. So, I am going to change this error message as 
suggested. Thanks!


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

https://reviews.llvm.org/D106688

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


[PATCH] D106614: [Clang] add btf_tag attribute

2021-07-28 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

> This currently has no codegen, so it only adds the attribute to the AST and 
> does nothing with it. Can you also add the codegen components to this patch?

The code patches to generate IR are below:

  https://reviews.llvm.org/D106620 (generate btf_tag annotations for func 
parameters)
  https://reviews.llvm.org/D106619 (generate btf_tag annotations for 
DIGlobalVariable)
  https://reviews.llvm.org/D106618 (generate btf_tag annotations for 
DISubprogram types)
  https://reviews.llvm.org/D106616 (generate btf_tag annotations for DIDerived 
types)
  https://reviews.llvm.org/D106615 (generate btf_tag annotations for 
DIComposite types)

The dwarf generation patch:

  https://reviews.llvm.org/D106621 (Support new TAG DW_TAG_LLVM_annotation)

In one of my early PIC patches, David Blaikie suggested to break into 
manageable pieces
for review and that is why I have multiple patches instead of one giant one. 
Please let
me know if you have better suggestions.

 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106614

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


[PATCH] D107026: [Clang] Add support for attribute 'escape'

2021-07-28 Thread Josh Learn via Phabricator via cfe-commits
guitard0g created this revision.
guitard0g added reviewers: aaron.ballman, NoQ, vsavchenko.
guitard0g requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The 'escape' attribute indicates that the annotated pointer parameter
may escape the scope of the function. This attribute is meant to be
used for compiler diagnostics/static analysis checks. The attribute
will first be used by the Swift compiler in a new implicit bridging
diagnostic, but may have other non-Swift use-cases for diagnostics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107026

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/AST/ast-dump-attr.m

Index: clang/test/AST/ast-dump-attr.m
===
--- clang/test/AST/ast-dump-attr.m
+++ clang/test/AST/ast-dump-attr.m
@@ -65,4 +65,8 @@
 // CHECK-NEXT: | `-NoEscapeAttr
 // CHECK-NEXT: |-ParmVarDecl{{.*}} Test14 'int'
 // CHECK-NEXT: `-NSConsumesSelfAttr
+-(void)Test15: (int *) [[clang::escape]] Test16;
+// CHECK: ObjCMethodDecl{{.*}} Test15: 'void'
+// CHECK-NEXT: -ParmVarDecl{{.*}} Test16 'int *'
+// CHECK-NEXT: `-EscapeAttr
 @end
Index: clang/test/AST/ast-dump-attr.cpp
===
--- clang/test/AST/ast-dump-attr.cpp
+++ clang/test/AST/ast-dump-attr.cpp
@@ -200,6 +200,15 @@
   // CHECK-NEXT: NoEscapeAttr
 }
 
+namespace TestEscape {
+  void escapeFunc(int *p0, __attribute__((escape)) int *p1) {}
+  // CHECK: NamespaceDecl{{.*}} TestEscape
+  // CHECK-NEXT: `-FunctionDecl{{.*}} escapeFunc 'void (int *, int *)'
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: EscapeAttr
+}
+
 namespace TestSuppress {
   [[gsl::suppress("at-namespace")]];
   // CHECK: NamespaceDecl{{.*}} TestSuppress
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1553,11 +1553,11 @@
   D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL));
 }
 
-static void handleNoEscapeAttr(Sema , Decl *D, const ParsedAttr ) {
+static void handleXEscapeAttr(Sema , Decl *D, const ParsedAttr ) {
   if (D->isInvalidDecl())
 return;
 
-  // noescape only applies to pointer types.
+  // escape/noescape only applies to pointer types.
   QualType T = cast(D)->getType();
   if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
@@ -1565,7 +1565,16 @@
 return;
   }
 
-  D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
+  switch (AL.getKind()) {
+  default:
+llvm_unreachable("invalid escape attribute");
+  case ParsedAttr::AT_NoEscape:
+handleSimpleAttribute(S, D, AL);
+return;
+  case ParsedAttr::AT_Escape:
+handleSimpleAttribute(S, D, AL);
+return;
+  }
 }
 
 static void handleAssumeAlignedAttr(Sema , Decl *D, const ParsedAttr ) {
@@ -8007,8 +8016,9 @@
   case ParsedAttr::AT_ReturnsNonNull:
 handleReturnsNonNullAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_Escape:
   case ParsedAttr::AT_NoEscape:
-handleNoEscapeAttr(S, D, AL);
+handleXEscapeAttr(S, D, AL);
 break;
   case ParsedAttr::AT_AssumeAligned:
 handleAssumeAlignedAttr(S, D, AL);
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -253,6 +253,27 @@
   }];
 }
 
+def EscapeDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+``escape`` placed on a function parameter of a pointer type is used to indicate
+that the pointer can escape the function. This means that a reference to the object
+the pointer points to that is derived from the parameter value may survive
+after the function returns.
+
+For example:
+
+.. code-block:: c
+
+  int *gp;
+
+  void escapingFunc(__attribute__((escape)) int *p) {
+gp = p;
+  }
+
+  }];
+}
+
 def CarriesDependencyDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1949,6 +1949,12 @@
   let Documentation = [NoEscapeDocs];
 }
 
+def Escape : Attr {
+  let Spellings = [Clang<"escape">];
+  let Subjects = SubjectList<[ParmVar]>;
+  let Documentation = [EscapeDocs];
+}
+
 def AssumeAligned : InheritableAttr {
   let Spellings = [GCC<"assume_aligned">];
   let Subjects = SubjectList<[ObjCMethod, Function]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107025: Take OptimizationLevel class out of Pass Builder

2021-07-28 Thread Tarindu Jayatilaka via Phabricator via cfe-commits
tarinduj created this revision.
tarinduj added reviewers: jdoerfert, mtrofin, uenoku.
tarinduj added a project: LLVM.
Herald added subscribers: ormris, foad, kerbowa, steven_wu, hiraditya, 
nhaehnle, jvesely, arsenm, jholewinski.
Herald added a reviewer: bollu.
tarinduj requested review of this revision.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

Pulled out the OptimizationLevel class from PassBuilder in order to be able to 
access it from within the PassManager and avoid include conflicts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107025

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/examples/Bye/Bye.cpp
  llvm/include/llvm/Passes/OptimizationLevel.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.cpp
  llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/tools/opt/NewPMDriver.cpp
  polly/include/polly/Canonicalization.h
  polly/lib/Support/RegisterPasses.cpp
  polly/lib/Transform/Canonicalization.cpp

Index: polly/lib/Transform/Canonicalization.cpp
===
--- polly/lib/Transform/Canonicalization.cpp
+++ polly/lib/Transform/Canonicalization.cpp
@@ -64,7 +64,7 @@
 
 /// Adapted from llvm::PassBuilder::buildInlinerPipeline
 static ModuleInlinerWrapperPass
-buildInlinePasses(llvm::PassBuilder::OptimizationLevel Level) {
+buildInlinePasses(llvm::OptimizationLevel Level) {
   InlineParams IP = getInlineParams(200);
   ModuleInlinerWrapperPass MIWP(IP);
 
@@ -93,7 +93,7 @@
 }
 
 FunctionPassManager polly::buildCanonicalicationPassesForNPM(
-llvm::ModulePassManager , llvm::PassBuilder::OptimizationLevel Level) {
+llvm::ModulePassManager , llvm::OptimizationLevel Level) {
   FunctionPassManager FPM;
 
   bool UseMemSSA = true;
@@ -107,7 +107,7 @@
   FPM.addPass(ReassociatePass());
   {
 LoopPassManager LPM;
-LPM.addPass(LoopRotatePass(Level != PassBuilder::OptimizationLevel::Oz));
+LPM.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
 FPM.addPass(createFunctionToLoopPassAdaptor(
 std::move(LPM), /*UseMemorySSA=*/false,
 /*UseBlockFrequencyInfo=*/false));
Index: polly/lib/Support/RegisterPasses.cpp
===
--- polly/lib/Support/RegisterPasses.cpp
+++ polly/lib/Support/RegisterPasses.cpp
@@ -474,7 +474,7 @@
 /// the analysis passes are added, skipping Polly itself.
 /// The IR may still be modified.
 static void buildCommonPollyPipeline(FunctionPassManager ,
- PassBuilder::OptimizationLevel Level,
+ OptimizationLevel Level,
  bool EnableForOpt) {
   PassBuilder PB;
   ScopPassManager SPM;
@@ -574,7 +574,7 @@
 }
 
 static void buildEarlyPollyPipeline(ModulePassManager ,
-PassBuilder::OptimizationLevel Level) {
+OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
@@ -603,7 +603,7 @@
 }
 
 static void buildLatePollyPipeline(FunctionPassManager ,
-   PassBuilder::OptimizationLevel Level) {
+   OptimizationLevel Level) {
   bool EnableForOpt =
   shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
   if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
Index: polly/include/polly/Canonicalization.h
===
--- polly/include/polly/Canonicalization.h
+++ polly/include/polly/Canonicalization.h
@@ -30,7 +30,7 @@
 
 llvm::FunctionPassManager
 buildCanonicalicationPassesForNPM(llvm::ModulePassManager ,
-  llvm::PassBuilder::OptimizationLevel Level);
+  llvm::OptimizationLevel Level);
 
 } // namespace polly
 
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -173,58 +173,58 @@
 static void registerEPCallbacks(PassBuilder ) {
   if (tryParsePipelineText(PB, PeepholeEPPipeline))
 PB.registerPeepholeEPCallback(
-[](FunctionPassManager , PassBuilder::OptimizationLevel Level) {
+[](FunctionPassManager , OptimizationLevel Level) {
   ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
   Err(PB.parsePassPipeline(PM, PeepholeEPPipeline));
 });
   if (tryParsePipelineText(PB,
 

[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Michael Kruse via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6b0b16c0f55: [Preprocessor] -E -P: Ensure newline after 8 
skipped lines. (authored by Meinersbur).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

Files:
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Preprocessor/line-directive-output-mincol.c
  clang/test/Preprocessor/minimize-whitespace.c
  clang/test/Preprocessor/skip-empty-lines.c

Index: clang/test/Preprocessor/skip-empty-lines.c
===
--- /dev/null
+++ clang/test/Preprocessor/skip-empty-lines.c
@@ -0,0 +1,45 @@
+  int  a ;
+  int  b ;
+// A single empty line
+  int  c ;
+/*
+
+more than 8 empty lines
+(forces a line marker instead of newline padding)
+
+
+
+
+*/
+  int  d ;
+
+// RUN: %clang_cc1 -E %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=LINEMARKERS
+// RUN: %clang_cc1 -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=COLSONLY
+// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
+// RUN: %clang_cc1 -E -P -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
+
+// Check behavior after varying number of lines without emitted tokens.
+
+// LINEMARKERS:   {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// LINEMARKERS-NEXT: {{^}}  int a ;
+// LINEMARKERS-NEXT: {{^}}  int b ;
+// LINEMARKERS-EMPTY:
+// LINEMARKERS-NEXT: {{^}}  int c ;
+// LINEMARKERS-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// LINEMARKERS-NEXT: {{^}}  int d ;
+
+// COLSONLY:  {{^}}  int a ;
+// COLSONLY-NEXT: {{^}}  int b ;
+// COLSONLY-NEXT: {{^}}  int c ;
+// COLSONLY-NEXT: {{^}}  int d ;
+
+// MINCOL:  {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// MINCOL-NEXT: {{^}}int a;
+// MINCOL-NEXT: {{^}}int b;
+// MINCOL-EMPTY:
+// MINCOL-NEXT: {{^}}int c;
+// MINCOL-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// MINCOL-NEXT: {{^}}int d;
+
+// MINWS: {{^}}int a;int b;int c;int d;
+
Index: clang/test/Preprocessor/minimize-whitespace.c
===
--- clang/test/Preprocessor/minimize-whitespace.c
+++ clang/test/Preprocessor/minimize-whitespace.c
@@ -2,6 +2,12 @@
 // RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCCOL
 // RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
 // RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCWS
+// The follow empty lines ensure that a #line directive is emitted instead of newline padding after the RUN comments.
+
+
+
+
+
 
 #define NOT_OMP  omp  something
 #define HASH #
@@ -16,11 +22,11 @@
 f  ;
 
 
-// MINCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCOL:  {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
 // MINCOL:  {{^}}int a;{{$}}
 // MINCOL-NEXT: {{^}}int b;{{$}}
 // MINCOL-NEXT: {{^}}#pragma omp barrier{{$}}
-// MINCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
 // MINCOL-NEXT: {{^}}x{{$}}
 // MINCOL-NEXT: {{^}}#pragma omp nothing{{$}}
 // MINCOL-NEXT: {{^ }}#pragma omp something{{$}}
@@ -28,11 +34,11 @@
 // MINCOL-NEXT: {{^}}int f;{{$}}
 
 // FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
-// MINCCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCCOL:  {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
 // MINCCOL:  {{^}}int a;/*  span-comment  */{{$}}
 // MINCCOL-NEXT: {{^}}int b;//  line-comment{{$}}
 // MINCCOL-NEXT: {{^}}#pragma omp barrier{{$}}
-// MINCCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
 // MINCCOL-NEXT: {{^}}x//  more line-comments{{$}}
 // MINCCOL-NEXT: {{^}}#pragma omp nothing{{$}}
 // MINCCOL-NEXT: {{^ }}#pragma omp something{{$}}
Index: clang/test/Preprocessor/line-directive-output-mincol.c
===
--- clang/test/Preprocessor/line-directive-output-mincol.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s -strict-whitespace
-
-// CHECK:  # 6 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int x;
-// CHECK-NEXT: int y;
-int x;
-int y;
-// CHECK-NEXT: # 10 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int z;
-int z;
-
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -276,20 +276,27 @@
   // otherwise print a #line directive.
   if (CurLine == LineNo) {
 // Nothing to do if we are already on the correct line.
-  

[clang] c6b0b16 - [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Michael Kruse via cfe-commits

Author: Michael Kruse
Date: 2021-07-28T22:50:54-05:00
New Revision: c6b0b16c0f55c34f4eaa05184815bbbe97f4b750

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

LOG: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

The implementation of -fminimize-whitespace (D104601) revised the logic
when to emit newlines. There was no case to handle when more than
8 lines were skippped in -P (DisableLineMarkers) mode and instead fell
through the case intended for -fminimize-whitespace, i.e. emit nothing.
This patch will emit one newline in this case.

The newline logic is slightly reorganized. The `-P -fminimize-whitespace`
case is handled explicitly and emitting at least one newline is the new
fallback case. The choice between emitting a line marker or up to
7 empty lines is now a choice only with enabled line markers. The up to
8 newlines likely are fewer characters than a line directive, but
in -P mode this had the paradoxic effect that it would print up to
7 empty lines, but none at all if more than 8 lines had to be skipped.
Now with DisableLineMarkers, we don't consider printing empty lines
(just start a new line) which matches gcc's behavior.

The line-directive-output-mincol.c test is replaced with a more
comprehensive test skip-empty-lines.c also testing the more than
8 skipped lines behaviour with all flag combinations.

Reviewed By: aaron.ballman

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

Added: 
clang/test/Preprocessor/skip-empty-lines.c

Modified: 
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/test/Preprocessor/minimize-whitespace.c

Removed: 
clang/test/Preprocessor/line-directive-output-mincol.c



diff  --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index b7259569595d6..1759485de24db 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -276,20 +276,27 @@ bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo,
   // otherwise print a #line directive.
   if (CurLine == LineNo) {
 // Nothing to do if we are already on the correct line.
-  } else if (!StartedNewLine && (!MinimizeWhitespace || !DisableLineMarkers) &&
- LineNo - CurLine == 1) {
+  } else if (MinimizeWhitespace && DisableLineMarkers) {
+// With -E -P -fminimize-whitespace, don't emit anything if not necessary.
+  } else if (!StartedNewLine && LineNo - CurLine == 1) {
 // Printing a single line has priority over printing a #line directive, 
even
 // when minimizing whitespace which otherwise would print #line directives
 // for every single line.
 OS << '\n';
 StartedNewLine = true;
-  } else if (!MinimizeWhitespace && LineNo - CurLine <= 8) {
-const char *NewLines = "\n\n\n\n\n\n\n\n";
-OS.write(NewLines, LineNo - CurLine);
-StartedNewLine = true;
   } else if (!DisableLineMarkers) {
-// Emit a #line or line marker.
-WriteLineInfo(LineNo, nullptr, 0);
+if (LineNo - CurLine <= 8) {
+  const char *NewLines = "\n\n\n\n\n\n\n\n";
+  OS.write(NewLines, LineNo - CurLine);
+} else {
+  // Emit a #line or line marker.
+  WriteLineInfo(LineNo, nullptr, 0);
+}
+StartedNewLine = true;
+  } else if (!StartedNewLine) {
+// If we are not on the correct line and don't need to be line-correct,
+// at least ensure we start on a new line.
+OS << '\n';
 StartedNewLine = true;
   }
 

diff  --git a/clang/test/Preprocessor/line-directive-output-mincol.c 
b/clang/test/Preprocessor/line-directive-output-mincol.c
deleted file mode 100644
index 0f2466ebee971..0
--- a/clang/test/Preprocessor/line-directive-output-mincol.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s 
-strict-whitespace
-
-// CHECK:  # 6 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int x;
-// CHECK-NEXT: int y;
-int x;
-int y;
-// CHECK-NEXT: # 10 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int z;
-int z;
-

diff  --git a/clang/test/Preprocessor/minimize-whitespace.c 
b/clang/test/Preprocessor/minimize-whitespace.c
index 3608e318dc135..137efe8393795 100644
--- a/clang/test/Preprocessor/minimize-whitespace.c
+++ b/clang/test/Preprocessor/minimize-whitespace.c
@@ -2,6 +2,12 @@
 // RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s 
--strict-whitespace --check-prefix=MINCCOL
 // RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s 
--strict-whitespace --check-prefix=MINWS
 // RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s 
--strict-whitespace --check-prefix=MINCWS
+// The follow empty lines ensure that a #line directive is emitted instead of 
newline padding after the RUN 

[PATCH] D106939: [RISCV] If the maskedoff is vundefined(), use ta, ma for vsetvli.

2021-07-28 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 362617.
HsiangKai added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106939

Files:
  clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c
  llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
  llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll


Index: llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs \
+; RUN:   --riscv-no-aliases < %s | FileCheck %s
+
+declare  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+  ,
+  ,
+  ,
+  ,
+  i64);
+
+define  @intrinsic_vadd_maskedoff_undef( %0, 
 %1,  %2, i64 %3) nounwind {
+; CHECK-LABEL: intrinsic_vadd_maskedoff_undef:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vsetvli zero, a0, e8, m1, ta, ma
+; CHECK-NEXT:vadd.vv v8, v8, v9, v0.t
+; CHECK-NEXT:jalr zero, 0(ra)
+entry:
+  %a = call  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+ undef,
+ %0,
+ %1,
+ %2,
+i64 %3)
+
+  ret  %a
+}
Index: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
===
--- llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -376,17 +376,24 @@
   // over the tail values. Some pseudo instructions force a tail agnostic 
policy
   // despite having a tied def.
   bool ForceTailAgnostic = RISCVII::doesForceTailAgnostic(TSFlags);
+  bool MaskAgnostic = true;
   bool TailAgnostic = true;
   unsigned UseOpIdx;
-  if (!ForceTailAgnostic && MI.isRegTiedToUseOperand(0, )) {
-TailAgnostic = false;
-// If the tied operand is an IMPLICIT_DEF we can keep TailAgnostic.
+  if (MI.isRegTiedToUseOperand(0, )) {
+// hasDummyMaskOp(TSFlags) == true means it is a non-masked instruction.
+MaskAgnostic = RISCVII::hasDummyMaskOp(TSFlags);
+if (!ForceTailAgnostic)
+  TailAgnostic = false;
+// If the tied operand is an IMPLICIT_DEF we can keep MaskAgnostic and
+// TailAgnostic.
 const MachineOperand  = MI.getOperand(UseOpIdx);
 MachineInstr *UseMI = MRI->getVRegDef(UseMO.getReg());
 if (UseMI) {
   UseMI = elideCopies(UseMI, MRI);
-  if (UseMI && UseMI->isImplicitDef())
+  if (UseMI && UseMI->isImplicitDef()) {
+MaskAgnostic = true;
 TailAgnostic = true;
+  }
 }
   }
 
@@ -399,7 +406,7 @@
   } else
 InstrInfo.setAVLReg(RISCV::NoRegister);
   InstrInfo.setVTYPE(VLMul, SEW, /*TailAgnostic*/ TailAgnostic,
- /*MaskAgnostic*/ false, MaskRegOp);
+ /*MaskAgnostic*/ MaskAgnostic, MaskRegOp);
 
   return InstrInfo;
 }
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c
@@ -0,0 +1,16 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +experimental-v \
+// RUN:   -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64 %s
+
+#include 
+
+// CHECK-RV64-LABEL: @test_vadd_vv_i8m1_m(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vadd.mask.nxv8i8.nxv8i8.i64( undef,  [[OP1:%.*]],  [[OP2:%.*]],  [[MASK:%.*]], 
i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vint8m1_t test_vadd_vv_i8m1_m (vbool8_t mask, vint8m1_t op1, vint8m1_t op2, 
size_t vl) {
+  return vadd_vv_i8m1_m(mask, vundefined_i8m1(), op1, op2, vl);
+}


Index: llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs \
+; RUN:   --riscv-no-aliases < %s | FileCheck %s
+
+declare  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+  ,
+  ,
+  ,
+  ,
+  i64);
+
+define  @intrinsic_vadd_maskedoff_undef( %0,  %1,  %2, i64 %3) nounwind {
+; CHECK-LABEL: intrinsic_vadd_maskedoff_undef:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vsetvli zero, a0, e8, m1, ta, ma
+; CHECK-NEXT:vadd.vv v8, v8, v9, v0.t
+; CHECK-NEXT:jalr zero, 0(ra)
+entry:
+  %a = call  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+ undef,
+ %0,
+ %1,
+ %2,
+i64 %3)
+
+  ret  %a
+}
Index: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
===
--- 

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 362614.
ellis added a comment.

Remove whitespace changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; CHECK: bb.1:
   ; CHECK:   successors: %bb.3(0x8000)
-  ; CHECK:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]], debug-location !DILocation(line: 8, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ADD]](s32), $noreg, !9, !DIExpression(), debug-location 

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
ellis added a reviewer: aprantl.
Herald added subscribers: dexonsmith, lxfind, hiraditya.
ellis requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

It looks like this array was missed in 4276d4a8d08b7640eb57cabf6988a5cf65b228b6

Fixed tests that expected `elements` to be empty or depeneded on the order of 
the empty DINode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; 

[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 362612.
Meinersbur added a comment.

- Use correct base commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

Files:
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Preprocessor/line-directive-output-mincol.c
  clang/test/Preprocessor/minimize-whitespace.c
  clang/test/Preprocessor/skip-empty-lines.c

Index: clang/test/Preprocessor/skip-empty-lines.c
===
--- /dev/null
+++ clang/test/Preprocessor/skip-empty-lines.c
@@ -0,0 +1,45 @@
+  int  a ;
+  int  b ;
+// A single empty line
+  int  c ;
+/*
+
+more than 8 empty lines
+(forces a line marker instead of newline padding)
+
+
+
+
+*/
+  int  d ;
+
+// RUN: %clang_cc1 -E %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=LINEMARKERS
+// RUN: %clang_cc1 -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=COLSONLY
+// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
+// RUN: %clang_cc1 -E -P -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
+
+// Check behavior after varying number of lines without emitted tokens.
+
+// LINEMARKERS:   {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// LINEMARKERS-NEXT: {{^}}  int a ;
+// LINEMARKERS-NEXT: {{^}}  int b ;
+// LINEMARKERS-EMPTY:
+// LINEMARKERS-NEXT: {{^}}  int c ;
+// LINEMARKERS-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// LINEMARKERS-NEXT: {{^}}  int d ;
+
+// COLSONLY:  {{^}}  int a ;
+// COLSONLY-NEXT: {{^}}  int b ;
+// COLSONLY-NEXT: {{^}}  int c ;
+// COLSONLY-NEXT: {{^}}  int d ;
+
+// MINCOL:  {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// MINCOL-NEXT: {{^}}int a;
+// MINCOL-NEXT: {{^}}int b;
+// MINCOL-EMPTY:
+// MINCOL-NEXT: {{^}}int c;
+// MINCOL-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// MINCOL-NEXT: {{^}}int d;
+
+// MINWS: {{^}}int a;int b;int c;int d;
+
Index: clang/test/Preprocessor/minimize-whitespace.c
===
--- clang/test/Preprocessor/minimize-whitespace.c
+++ clang/test/Preprocessor/minimize-whitespace.c
@@ -2,6 +2,12 @@
 // RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCCOL
 // RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
 // RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCWS
+// The follow empty lines ensure that a #line directive is emitted instead of newline padding after the RUN comments.
+
+
+
+
+
 
 #define NOT_OMP  omp  something
 #define HASH #
@@ -16,11 +22,11 @@
 f  ;
 
 
-// MINCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCOL:  {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
 // MINCOL:  {{^}}int a;{{$}}
 // MINCOL-NEXT: {{^}}int b;{{$}}
 // MINCOL-NEXT: {{^}}#pragma omp barrier{{$}}
-// MINCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
 // MINCOL-NEXT: {{^}}x{{$}}
 // MINCOL-NEXT: {{^}}#pragma omp nothing{{$}}
 // MINCOL-NEXT: {{^ }}#pragma omp something{{$}}
@@ -28,11 +34,11 @@
 // MINCOL-NEXT: {{^}}int f;{{$}}
 
 // FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
-// MINCCOL:  {{^}}# 9 "{{.*}}minimize-whitespace.c"{{$}}
+// MINCCOL:  {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
 // MINCCOL:  {{^}}int a;/*  span-comment  */{{$}}
 // MINCCOL-NEXT: {{^}}int b;//  line-comment{{$}}
 // MINCCOL-NEXT: {{^}}#pragma omp barrier{{$}}
-// MINCCOL-NEXT: # 11 "{{.*}}minimize-whitespace.c"
+// MINCCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
 // MINCCOL-NEXT: {{^}}x//  more line-comments{{$}}
 // MINCCOL-NEXT: {{^}}#pragma omp nothing{{$}}
 // MINCCOL-NEXT: {{^ }}#pragma omp something{{$}}
Index: clang/test/Preprocessor/line-directive-output-mincol.c
===
--- clang/test/Preprocessor/line-directive-output-mincol.c
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s -strict-whitespace
-
-// CHECK:  # 6 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int x;
-// CHECK-NEXT: int y;
-int x;
-int y;
-// CHECK-NEXT: # 10 "{{.*}}line-directive-output-mincol.c"
-// CHECK-NEXT: int z;
-int z;
-
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -276,20 +276,27 @@
   // otherwise print a #line directive.
   if (CurLine == LineNo) {
 // Nothing to do if we are already on the correct line.
-  } else if (!StartedNewLine && (!MinimizeWhitespace || !DisableLineMarkers) &&
- LineNo - CurLine == 1) {
+  } else if 

[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 362611.
Meinersbur added a comment.

- Fix embrassing mistakes in skip-empty-lines test (misspelled "LINEMARKES", 
MINWS<->MINCOL, absolute path)
- Skip-empty-lines now also checks leading whitespace behavior
- Fix typos in comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

Files:
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Preprocessor/minimize-whitespace.c
  clang/test/Preprocessor/skip-empty-lines.c

Index: clang/test/Preprocessor/skip-empty-lines.c
===
--- clang/test/Preprocessor/skip-empty-lines.c
+++ clang/test/Preprocessor/skip-empty-lines.c
@@ -1,44 +1,45 @@
-int  a ;
-int  b ;
+  int  a ;
+  int  b ;
 // A single empty line
-int  c ;
+  int  c ;
 /*
 
 more than 8 empty lines
-
+(forces a line marker instead of newline padding)
 
 
 
 
 */
-int  d ;
+  int  d ;
 
-// RUN: %clang_cc1 -E %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=LINEMARKES
+// RUN: %clang_cc1 -E %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=LINEMARKERS
 // RUN: %clang_cc1 -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=COLSONLY
-// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
-// RUN: %clang_cc1 -E -P -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
+// RUN: %clang_cc1 -E -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
+// RUN: %clang_cc1 -E -P -fminimize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
 
-// Check behavior after variying number of lines without emitted tokens.
+// Check behavior after varying number of lines without emitted tokens.
 
-// LINEMARKES:   # 1 "{{.*}}skip-empty-lines.c" 2
-// LINEMARKERS-NEXT: int a ;
-// LINEMARKERS-NEXT: int b ;
+// LINEMARKERS:   {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// LINEMARKERS-NEXT: {{^}}  int a ;
+// LINEMARKERS-NEXT: {{^}}  int b ;
 // LINEMARKERS-EMPTY:
-// LINEMARKERS-NEXT: int c ;
-// LINEMARKERS-NEXT: # 14 "/c/Users/meinersbur/src/llvm-project/clang/test/Preprocessor/skip-empty-lines.c"
-// LINEMARKERS-NEXT: int d ;
-
-// COLSONLY:  int a ;
-// COLSONLY-NEXT: int b ;
-// COLSONLY-NEXT: int c ;
-// COLSONLY-NEXT: int d ;
-
-// MINWS:  # 1 "{{.*}}skip-empty-lines.c" 2
-// MINWS-NEXT: int a;
-// MINWS-NEXT: int b;
-// MINWS-EMPTY:
-// MINWS-NEXT: int c;
-// MINWS-NEXT: # 14 "{{.*}}skip-empty-lines.c"
-// MINWS-NEXT: int d;
-
-// MINCOL: int a;int b;int c;int d;
+// LINEMARKERS-NEXT: {{^}}  int c ;
+// LINEMARKERS-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// LINEMARKERS-NEXT: {{^}}  int d ;
+
+// COLSONLY:  {{^}}  int a ;
+// COLSONLY-NEXT: {{^}}  int b ;
+// COLSONLY-NEXT: {{^}}  int c ;
+// COLSONLY-NEXT: {{^}}  int d ;
+
+// MINCOL:  {{^}}# 1 "{{.*}}skip-empty-lines.c" 2
+// MINCOL-NEXT: {{^}}int a;
+// MINCOL-NEXT: {{^}}int b;
+// MINCOL-EMPTY:
+// MINCOL-NEXT: {{^}}int c;
+// MINCOL-NEXT: {{^}}# 14 "{{.*}}skip-empty-lines.c"
+// MINCOL-NEXT: {{^}}int d;
+
+// MINWS: {{^}}int a;int b;int c;int d;
+
Index: clang/test/Preprocessor/minimize-whitespace.c
===
--- clang/test/Preprocessor/minimize-whitespace.c
+++ clang/test/Preprocessor/minimize-whitespace.c
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCCOL
 // RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
 // RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCWS
-// The follow empty lines ensure that a #line directive is emitted instead of newline padding after the RUN lines
+// The follow empty lines ensure that a #line directive is emitted instead of newline padding after the RUN comments.
 
 
 
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -294,8 +294,8 @@
 }
 StartedNewLine = true;
   } else if (!StartedNewLine) {
-// If we are not on the correct line and don't need to be line-correct, at
-// least ensure we start on a new line.
+// If we are not on the correct line and don't need to be line-correct,
+// at least ensure we start on a new line.
 OS << '\n';
 StartedNewLine = true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106939: [RISCV] If the maskedoff is vundefined(), use ta, ma for vsetvli.

2021-07-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:379
   bool ForceTailAgnostic = RISCVII::doesForceTailAgnostic(TSFlags);
+  // hasDummyMaskOp(TSFlags) == ture means it is a non-masked instruction.
+  // FIXME: hasDummyMaskOp() is the closest attribute to distinguish masked

ture -> true



Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:382
+  // and non-masked instructions. However, there are some exceptions for this
+  // attribute. PseudoVMV_V_[VXI] and PseudoVFMV_V_F have no need to append
+  // the dummy mask operand in MC lowering and they are non-masked 
instructions.

Wouldn't the lack of tied operand for those indicate they weren't masked.

What if we did

```
bool MaskAgnostic = true;
if (MI.isRegTiedToUseOperand(0, )) {
  MaskAgnostic = RISCVII::hasDummyMaskOp(TSFlags);
}
```



Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:384
+  // the dummy mask operand in MC lowering and they are non-masked 
instructions.
+  bool MaskAgnostic = RISCVII::hasDummyMaskOp(TSFlags) ? true : false;
   bool TailAgnostic = true;

Doesn't have hasDummyMaskOp return a bool? We shouldn't need a conditional 
operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106939

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


[PATCH] D107021: [Sema][ObjC] Allow conversions between pointers to ObjC pointers and pointers to structs

2021-07-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I don't think there is any reason conversions between `ACTC_none` and 
`ACTC_indirectRetainable` (for example, conversions between `struct S **` and 
`__strong id *x` or `int *` and `__strong id *x`) should be disallowed. I just 
made the minimal change needed to enable using ObjC ARC pointers as the libc++ 
functions' template arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107021

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


[PATCH] D107021: [Sema][ObjC] Allow conversions between pointers to ObjC pointers and pointers to structs

2021-07-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, ldionne.
ahatanak added a project: clang.
ahatanak requested review of this revision.

clang was just being conservative and trying to prevent users from messing up 
the qualifier on the inner pointer type. Lifting this restriction enables using 
some of the libc++ templates with ObjC pointer arguments, which clang currently 
rejects.

rdar://79018677


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107021

Files:
  clang/lib/Sema/SemaExprObjC.cpp
  clang/test/SemaObjC/arc-type-conversion.m


Index: clang/test/SemaObjC/arc-type-conversion.m
===
--- clang/test/SemaObjC/arc-type-conversion.m
+++ clang/test/SemaObjC/arc-type-conversion.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify 
-fblocks %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify 
-fblocks -Wno-incompatible-pointer-types %s
 
 typedef const void * CFTypeRef;
 CFTypeRef CFBridgingRetain(id X);
@@ -96,3 +96,14 @@
   id c = 1 ? a : b; // expected-error {{operands to conditional of types 'id' 
and 'void *' are incompatible in ARC mode}}
   id d = 1 ? b : a; // expected-error {{operands to conditional of types 'void 
*' and 'id' are incompatible in ARC mode}}
 }
+
+void conversion_pointer_to_id(__strong id *x) {
+  struct S {
+int a[2];
+  } s, *p;
+
+  x = (__strong id *)
+  x =  // expected-error {{implicit conversion of a non-Objective-C pointer 
type 'struct S *' to '__strong id *' is disallowed with ARC}}
+  p = (struct S *)x;
+  p = x; // expected-error {{implicit conversion of an indirect pointer to an 
Objective-C pointer to 'struct S *' is disallowed with ARC}}
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -4453,9 +4453,14 @@
   // Allow casts between pointers to lifetime types (e.g., __strong id*)
   // and pointers to void (e.g., cv void *). Casting from void* to lifetime*
   // must be explicit.
-  if (exprACTC == ACTC_indirectRetainable && castACTC == ACTC_voidPtr)
+  // Allow conversions between pointers to lifetime types and coreFoundation
+  // pointers too, but only when the conversions are explicit.
+  if (exprACTC == ACTC_indirectRetainable &&
+  (castACTC == ACTC_voidPtr ||
+   (castACTC == ACTC_coreFoundation && isCast(CCK
 return ACR_okay;
-  if (castACTC == ACTC_indirectRetainable && exprACTC == ACTC_voidPtr &&
+  if (castACTC == ACTC_indirectRetainable &&
+  (exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
   isCast(CCK))
 return ACR_okay;
 


Index: clang/test/SemaObjC/arc-type-conversion.m
===
--- clang/test/SemaObjC/arc-type-conversion.m
+++ clang/test/SemaObjC/arc-type-conversion.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -Wno-incompatible-pointer-types %s
 
 typedef const void * CFTypeRef;
 CFTypeRef CFBridgingRetain(id X);
@@ -96,3 +96,14 @@
   id c = 1 ? a : b; // expected-error {{operands to conditional of types 'id' and 'void *' are incompatible in ARC mode}}
   id d = 1 ? b : a; // expected-error {{operands to conditional of types 'void *' and 'id' are incompatible in ARC mode}}
 }
+
+void conversion_pointer_to_id(__strong id *x) {
+  struct S {
+int a[2];
+  } s, *p;
+
+  x = (__strong id *)
+  x =  // expected-error {{implicit conversion of a non-Objective-C pointer type 'struct S *' to '__strong id *' is disallowed with ARC}}
+  p = (struct S *)x;
+  p = x; // expected-error {{implicit conversion of an indirect pointer to an Objective-C pointer to 'struct S *' is disallowed with ARC}}
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -4453,9 +4453,14 @@
   // Allow casts between pointers to lifetime types (e.g., __strong id*)
   // and pointers to void (e.g., cv void *). Casting from void* to lifetime*
   // must be explicit.
-  if (exprACTC == ACTC_indirectRetainable && castACTC == ACTC_voidPtr)
+  // Allow conversions between pointers to lifetime types and coreFoundation
+  // pointers too, but only when the conversions are explicit.
+  if (exprACTC == ACTC_indirectRetainable &&
+  (castACTC == ACTC_voidPtr ||
+   (castACTC == ACTC_coreFoundation && isCast(CCK
 return ACR_okay;
-  if (castACTC == ACTC_indirectRetainable && exprACTC == ACTC_voidPtr &&
+  if (castACTC == ACTC_indirectRetainable &&
+  (exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
   isCast(CCK))
 return ACR_okay;
 

[PATCH] D106860: [clang][AArch64][SVE] Avoid going through memory for fixed/scalable predicate casts

2021-07-28 Thread JunMa via Phabricator via cfe-commits
junparser added inline comments.
Herald added a subscriber: ctetreau.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2102
+  Src = Builder.CreateBitCast(Src, SrcTy);
+}
 if (ScalableSrc->getElementType() == FixedDst->getElementType()) {

I think this may also works for casting between vectors with different element 
types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106860

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


[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-28 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 added a comment.

The problem seems to be in the conversion function expecting strings to be a 
multiple of 4 bytes, which doesn't hold up with the way ArrayRef stores things 
as char that is casted to char32_t, when using ASCII values like in the look of 
disapproval emoji, having an underscore in the middle.

But removing the assert and early return result in even more errors.

changing the input string to remove the underscore also fails, i'm out of ideas.


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

https://reviews.llvm.org/D106753

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


[PATCH] D106849: [NFC][X86] add missing tests in clang/test/CodeGen/attr-target-mv.c

2021-07-28 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 362596.
FreddyYe added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106849

Files:
  clang/test/CodeGen/attr-target-mv.c


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()


Index: clang/test/CodeGen/attr-target-mv.c
===
--- clang/test/CodeGen/attr-target-mv.c
+++ clang/test/CodeGen/attr-target-mv.c
@@ -129,6 +129,16 @@
 // WINDOWS: ret i32 6
 // WINDOWS: define dso_local i32 @foo.arch_icelake-server()
 // WINDOWS: ret i32 7
+// WINDOWS: define dso_local i32 @foo.arch_cooperlake()
+// WINDOWS: ret i32 8
+// WINDOWS: define dso_local i32 @foo.arch_tigerlake()
+// WINDOWS: ret i32 9
+// WINDOWS: define dso_local i32 @foo.arch_sapphirerapids()
+// WINDOWS: ret i32 10
+// WINDOWS: define dso_local i32 @foo.arch_alderlake()
+// WINDOWS: ret i32 11
+// WINDOWS: define dso_local i32 @foo.arch_rocketlake()
+// WINDOWS: ret i32 12
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:832
+  RD->setCompleteDefinition(false);
+  Reader.mergeDefinitionVisibility(OldDef, RD);
+} else {

vsapsai wrote:
> rsmith wrote:
> > vsapsai wrote:
> > > Here is the perfect place to compare if `RD` and `OldDef` are equivalent 
> > > and emit diagnostic if they are not. I've tried 
> > > `StructuralEquivalenceContext` for this purpose but it compares canonical 
> > > decls which doesn't work in this case. I think the best approach for this 
> > > task would be ODR hash comparison proposed in 
> > > https://reviews.llvm.org/D71734 It will need some tweaks to work with the 
> > > current patch but overall the plan is to use ODR hash instead of any 
> > > other decl comparison.
> > Just a minor note: it's not safe to emit diagnostics from here in general; 
> > in particular, emitting a diagnostic that refers to a declaration can 
> > trigger deserialization, which can reenter the AST reader in unfortunate 
> > ways and crash. But we can make a note to do the structural equivalence 
> > check here and then actually perform the check when we finish 
> > deserialization (with the other merging checks).
> Thanks for pointing it out, I didn't realize diagnostic can trigger 
> deserialization. Was planning to do something like
> 
> ```lang=c++
> if (OldDef->getODRHash() != RD->getODRHash())
>   Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
> ```
That seems reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D106994#2911903 , @vsapsai wrote:

> In D106994#2911508 , @rsmith wrote:
>
>> For what it's worth, I think the right way to handle this in C is to 
>> properly implement the "compatible types" rule instead of trying to invent 
>> something ODR-ish: in C, struct definitions in different translation units 
>> are different types, but if they're structurally equivalent then they're 
>> compatible and you can implicitly pass an object of some type to a function 
>> accepting a compatible type. This would mean that we could have multiple, 
>> different types with the same name, and we'd need name lookup to deduplicate 
>> compatible types, but we wouldn't need to do any cross-module ODR-like 
>> struct merging.
>
> I agree that implementing the "compatible types" looks better as it models 
> the language more faithfully. And in the long run we might need to do that 
> anyway. Is there any work done for "compatible types" already? Or I can start 
> by creating a new type for a new definition with the same name and see how it 
> breaks the lookup?
>
> From pragmatic perspective we are pretty invested into this ODR-ish approach 
> and it's not clear how much work switching to "compatible types" would take. 
> So I'd like to continue with the definition merging and evaluate the effort 
> for "compatible types". That's why I'm curious what work is done already.

I don't think there's been any real work done on a cross-TU implementation of 
compatible types. I also don't want that idea to get in the way of this patch, 
which seems like a clear improvement following our current approach.

>> But assuming we want to keep the current ODR-in-C approach, this looks OK. 
>> There might be some places that assume the lexical and semantic 
>> `DeclContext` for a C `FieldDecl` are the same (etc) but I don't think 
>> there's a good way to find such things other than by testing this patch 
>> broadly.
>
> Are there any known signs for mixing lexical and semantic `DeclContext`? I 
> plan to test the change on our internal codebase, hopefully it'll help to 
> catch any remaining issues.

The kinds of things I saw go wrong when we were bringing this up on the C++ 
side were generally in code that would walk the list of (say) fields of a 
record building up some information, and then attempt to look up a given 
`FieldDecl*` in that data structure. That can fail if fields get merged, 
because the lookup key may be a different redeclaration of the same field than 
the one found by walking the class's members.  The fix is usually to add 
`getCanonicalDecl` calls in the right places. The sign of this kind of bug 
happening was usually a crash or assert, usually pretty close to where the 
problem was.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-28 Thread Dave Airlie via Phabricator via cfe-commits
airlied added inline comments.



Comment at: clang/lib/Headers/opencl-c.h:13678
+uintptr_t __ovld atomic_fetch_sub_explicit(volatile __local atomic_uintptr_t 
*object, ptrdiff_t operand, memory_order order, memory_scope scope);
+#endif
+#endif

Anastasia wrote:
> airlied wrote:
> > Anastasia wrote:
> > > can we annotate `#endif` with a comment, please to improve readability? 
> > > The same applies to other places.
> > Isn't this the same problem we talked about before? how to annotate
> > 
> > #if defined(__opencl_c_generic_address_space)
> > 
> > #else 
> > 
> > #endif 
> > 
> > does it make sense to put //defined(__opencl_c_generic_address_space) on 
> > the endif?
> Yes indeed!
with the change to add elif for OPENCL_C_VERSION these now get those comments 
instead of generic address space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106778

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


[PATCH] D106778: [OpenCL] opencl-c.h: add CL 3.0 non-generic address space atomics

2021-07-28 Thread Dave Airlie via Phabricator via cfe-commits
airlied updated this revision to Diff 362587.
airlied added a comment.

added comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106778

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

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -13289,6 +13289,7 @@
 #endif
 
 // atomic_init()
+#if defined(__opencl_c_generic_address_space)
 void __ovld atomic_init(volatile atomic_int *object, int value);
 void __ovld atomic_init(volatile atomic_uint *object, uint value);
 void __ovld atomic_init(volatile atomic_float *object, float value);
@@ -13299,6 +13300,24 @@
 void __ovld atomic_init(volatile atomic_double *object, double value);
 #endif //cl_khr_fp64
 #endif
+#elif __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+void __ovld atomic_init(volatile __global atomic_int *object, int value);
+void __ovld atomic_init(volatile __local atomic_int *object, int value);
+void __ovld atomic_init(volatile __global atomic_uint *object, uint value);
+void __ovld atomic_init(volatile __local atomic_uint *object, uint value);
+void __ovld atomic_init(volatile __global atomic_float *object, float value);
+void __ovld atomic_init(volatile __local atomic_float *object, float value);
+#if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
+void __ovld atomic_init(volatile __global atomic_long *object, long value);
+void __ovld atomic_init(volatile __local atomic_long *object, long value);
+void __ovld atomic_init(volatile __global atomic_ulong *object, ulong value);
+void __ovld atomic_init(volatile __local atomic_ulong *object, ulong value);
+#ifdef cl_khr_fp64
+void __ovld atomic_init(volatile __global atomic_double *object, double value);
+void __ovld atomic_init(volatile __local atomic_double *object, double value);
+#endif //cl_khr_fp64
+#endif
+#endif //__OPENCL_C_VERSION__ >= CL_VERSION_3_0
 
 // atomic_work_item_fence()
 void __ovld atomic_work_item_fence(cl_mem_fence_flags flags, memory_order order, memory_scope scope);
@@ -13308,6 +13327,7 @@
 // add/sub: atomic type argument can be uintptr_t/intptr_t, value type argument can be ptrdiff_t.
 
 #if defined(__opencl_c_atomic_order_seq_cst) && defined(__opencl_c_atomic_scope_device)
+#if defined(__opencl_c_generic_address_space)
 int __ovld atomic_fetch_add(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_add(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_sub(volatile atomic_int *object, int operand);
@@ -13322,7 +13342,6 @@
 uint __ovld atomic_fetch_min(volatile atomic_uint *object, uint operand);
 int __ovld atomic_fetch_max(volatile atomic_int *object, int operand);
 uint __ovld atomic_fetch_max(volatile atomic_uint *object, uint operand);
-
 #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
 long __ovld atomic_fetch_add(volatile atomic_long *object, long operand);
 ulong __ovld atomic_fetch_add(volatile atomic_ulong *object, ulong operand);
@@ -13341,9 +13360,92 @@
 uintptr_t __ovld atomic_fetch_add(volatile atomic_uintptr_t *object, ptrdiff_t operand);
 uintptr_t __ovld atomic_fetch_sub(volatile atomic_uintptr_t *object, ptrdiff_t operand);
 #endif //defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics)
+#elif __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+int __ovld atomic_fetch_add(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_add(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_add(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_add(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_sub(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_sub(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_sub(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_sub(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_or(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_or(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_or(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_or(volatile __local atomic_uint *object, uint operand);
+int __ovld atomic_fetch_xor(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_xor(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_xor(volatile __global atomic_uint *object, uint operand);
+uint __ovld atomic_fetch_xor(volatile __local atomic_uint *object, uint operand);i
+int __ovld atomic_fetch_and(volatile __global atomic_int *object, int operand);
+int __ovld atomic_fetch_and(volatile __local atomic_int *object, int operand);
+uint __ovld atomic_fetch_and(volatile __global atomic_uint 

[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D106994#2911508 , @rsmith wrote:

> For what it's worth, I think the right way to handle this in C is to properly 
> implement the "compatible types" rule instead of trying to invent something 
> ODR-ish: in C, struct definitions in different translation units are 
> different types, but if they're structurally equivalent then they're 
> compatible and you can implicitly pass an object of some type to a function 
> accepting a compatible type. This would mean that we could have multiple, 
> different types with the same name, and we'd need name lookup to deduplicate 
> compatible types, but we wouldn't need to do any cross-module ODR-like struct 
> merging.

I agree that implementing the "compatible types" looks better as it models the 
language more faithfully. And in the long run we might need to do that anyway. 
Is there any work done for "compatible types" already? Or I can start by 
creating a new type for a new definition with the same name and see how it 
breaks the lookup?

From pragmatic perspective we are pretty invested into this ODR-ish approach 
and it's not clear how much work switching to "compatible types" would take. So 
I'd like to continue with the definition merging and evaluate the effort for 
"compatible types". That's why I'm curious what work is done already.

> But assuming we want to keep the current ODR-in-C approach, this looks OK. 
> There might be some places that assume the lexical and semantic `DeclContext` 
> for a C `FieldDecl` are the same (etc) but I don't think there's a good way 
> to find such things other than by testing this patch broadly.

Are there any known signs for mixing lexical and semantic `DeclContext`? I plan 
to test the change on our internal codebase, hopefully it'll help to catch any 
remaining issues.




Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:832
+  RD->setCompleteDefinition(false);
+  Reader.mergeDefinitionVisibility(OldDef, RD);
+} else {

rsmith wrote:
> vsapsai wrote:
> > Here is the perfect place to compare if `RD` and `OldDef` are equivalent 
> > and emit diagnostic if they are not. I've tried 
> > `StructuralEquivalenceContext` for this purpose but it compares canonical 
> > decls which doesn't work in this case. I think the best approach for this 
> > task would be ODR hash comparison proposed in 
> > https://reviews.llvm.org/D71734 It will need some tweaks to work with the 
> > current patch but overall the plan is to use ODR hash instead of any other 
> > decl comparison.
> Just a minor note: it's not safe to emit diagnostics from here in general; in 
> particular, emitting a diagnostic that refers to a declaration can trigger 
> deserialization, which can reenter the AST reader in unfortunate ways and 
> crash. But we can make a note to do the structural equivalence check here and 
> then actually perform the check when we finish deserialization (with the 
> other merging checks).
Thanks for pointing it out, I didn't realize diagnostic can trigger 
deserialization. Was planning to do something like

```lang=c++
if (OldDef->getODRHash() != RD->getODRHash())
  Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-28 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362574.
beanz added a comment.

Moving the warning emission later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
+
+// Test that we diagnose on #elif
+#if 0
+#elif foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+// Test that we diagnose on #elifndef.
+#ifdef baz
+#elifndef foo
+#endif
+// expected-warning@-2{{macro 'foo' has been marked as deprecated}}
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1413,6 +1413,18 @@
   return true;
 }
 
+void Preprocessor::emitMacroExpansionWarnings(Token ) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {
+auto DepMsg = getMacroDeprecationMsg(Identifier.getIdentifierInfo());
+if (!DepMsg)
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 0;
+else
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 1 << *DepMsg;
+  }
+}
+
 ModuleLoader::~ModuleLoader() = default;
 
 CommentHandler::~CommentHandler() = default;
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecated(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor , PragmaIntroducer Introducer,
+Token ) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+
+if (!II->hasMacroDefinition()) {
+  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II->getName();
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;

[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D99381#2911459 , @vitalybuka wrote:

> In D99381#2911057 , @eugenis wrote:
>
>> They are used here:
>> https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/malloc_common.h;l=54;drc=f3968e89cb72400951f93a2a8237ac1428d2627c
>
> Thanks, it's preprocessor generated, so I can't find it :)
>
> If so I guess LGTM.
> But now they are in the same file, so instead of declarations, maybe just 
> place SANITIZER_INTERFACE_ATTRIBUTE next to to the definition?

Done. I'll take this as a review LGTM and submit tomorrow unless others have 
comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 362571.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

Files:
  compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
  compiler-rt/lib/hwasan/hwasan_interface_internal.h

Index: compiler-rt/lib/hwasan/hwasan_interface_internal.h
===
--- compiler-rt/lib/hwasan/hwasan_interface_internal.h
+++ compiler-rt/lib/hwasan/hwasan_interface_internal.h
@@ -168,54 +168,6 @@
 SANITIZER_INTERFACE_ATTRIBUTE
 void __hwasan_print_memory_usage();
 
-SANITIZER_INTERFACE_ATTRIBUTE
-int __sanitizer_posix_memalign(void **memptr, uptr alignment, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_memalign(uptr alignment, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_aligned_alloc(uptr alignment, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer___libc_memalign(uptr alignment, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_valloc(uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_pvalloc(uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_free(void *ptr);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_cfree(void *ptr);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-uptr __sanitizer_malloc_usable_size(const void *ptr);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-__hwasan::__sanitizer_struct_mallinfo __sanitizer_mallinfo();
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __sanitizer_mallopt(int cmd, int value);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_malloc_stats(void);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_calloc(uptr nmemb, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_realloc(void *ptr, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_reallocarray(void *ptr, uptr nmemb, uptr size);
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void * __sanitizer_malloc(uptr size);
-
 SANITIZER_INTERFACE_ATTRIBUTE
 void *__hwasan_memcpy(void *dst, const void *src, uptr size);
 SANITIZER_INTERFACE_ATTRIBUTE
Index: compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
===
--- compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
+++ compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp
@@ -17,6 +17,8 @@
 #include "sanitizer_common/sanitizer_allocator_interface.h"
 #include "sanitizer_common/sanitizer_tls_get_addr.h"
 
+#if !SANITIZER_FUCHSIA
+
 using namespace __hwasan;
 
 static uptr allocated_for_dlsym;
@@ -36,6 +38,9 @@
   return mem;
 }
 
+extern "C" {
+
+SANITIZER_INTERFACE_ATTRIBUTE
 int __sanitizer_posix_memalign(void **memptr, uptr alignment, uptr size) {
   GET_MALLOC_STACK_TRACE;
   CHECK_NE(memptr, 0);
@@ -43,16 +48,19 @@
   return res;
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_memalign(uptr alignment, uptr size) {
   GET_MALLOC_STACK_TRACE;
   return hwasan_memalign(alignment, size, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_aligned_alloc(uptr alignment, uptr size) {
   GET_MALLOC_STACK_TRACE;
   return hwasan_aligned_alloc(alignment, size, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer___libc_memalign(uptr alignment, uptr size) {
   GET_MALLOC_STACK_TRACE;
   void *ptr = hwasan_memalign(alignment, size, );
@@ -61,16 +69,19 @@
   return ptr;
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_valloc(uptr size) {
   GET_MALLOC_STACK_TRACE;
   return hwasan_valloc(size, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_pvalloc(uptr size) {
   GET_MALLOC_STACK_TRACE;
   return hwasan_pvalloc(size, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void __sanitizer_free(void *ptr) {
   GET_MALLOC_STACK_TRACE;
   if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr)))
@@ -78,6 +89,7 @@
   hwasan_free(ptr, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void __sanitizer_cfree(void *ptr) {
   GET_MALLOC_STACK_TRACE;
   if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr)))
@@ -85,22 +97,27 @@
   hwasan_free(ptr, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 uptr __sanitizer_malloc_usable_size(const void *ptr) {
   return __sanitizer_get_allocated_size(ptr);
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 struct __sanitizer_struct_mallinfo __sanitizer_mallinfo() {
   __sanitizer_struct_mallinfo sret;
   internal_memset(, 0, sizeof(sret));
   return sret;
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 int __sanitizer_mallopt(int cmd, int value) { return 0; }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void __sanitizer_malloc_stats(void) {
   // FIXME: implement, but don't call REAL(malloc_stats)!
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_calloc(uptr nmemb, uptr size) {
   GET_MALLOC_STACK_TRACE;
   if (UNLIKELY(!hwasan_inited))
@@ -109,6 +126,7 @@
   return hwasan_calloc(nmemb, size, );
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
 void *__sanitizer_realloc(void *ptr, uptr size) {
   GET_MALLOC_STACK_TRACE;
   if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
@@ -127,11 +145,13 @@
   return 

[PATCH] D107004: Turn off fp reassociation in IA intrinsic header files.

2021-07-28 Thread Kevin B. Smith via Phabricator via cfe-commits
kbsmith1 added a comment.

In D107004#2911654 , @lebedev.ri 
wrote:

> Patch description states what the change is, but not why the change is what 
> it is.
> I don't think this is a good direction to second-guess the user's intentions.

I added the reason for the change to the description.  I think when a user 
programs
t = _mm_add_ps(a, b);
t = _mm_sub_ps(t, b);

that they truly did want those intrinsics evaluated like they were written, 
even with
fast math flags.  This change to the intrinsic headers makes programming with 
intrinsics
more accurately reflect what the user wrote, even when fast math flags are used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107004

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


[PATCH] D106674: Runtime for Interop directive

2021-07-28 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: openmp/libomptarget/plugins/cuda/src/rtl.cpp:1150-1156
+  CUresult Err = cuDeviceGet(, DeviceId);
+  if (Err == CUDA_SUCCESS) {
+DeviceInfo->Device = reinterpret_cast(Dev);
+  } else {
+cuGetErrorString(Err, errStr);
+return OFFLOAD_FAIL;
+  }





Comment at: openmp/libomptarget/src/interop.cpp:43
+const char *getVendorIdToStr(intptr_t vendor_id) {
+  switch (vendor_id) {
+  case 1:

Does it make sense to use enum here?



Comment at: openmp/libomptarget/src/interop.cpp:13
+static omp_interop_rc_t
+__kmpc_interop_get_property_err_type(omp_interop_property_t property) {
+  switch (property) {

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > There are some conventions in current `libomptarget`.
> > 1. If a function is internal, use LLVM code style.
> > 2. If a function is exported and exposed to compiler, it should be `extern 
> > "C"` and use code style similar to existing functions whose name prefix 
> > with `__tgt`.
> > 
> > So basically, if these functions are only visible to this file, please 
> > format it with LLVM code style, and use anonymous name space.
> I mean, this function doesn't have to start with `__tgt` because it is 
> internal. Functions starting with `__tgt` are usually interface functions. 
> From my perspective, it is better to name it as `getPropertyErrorType`, 
> a.k.a. to use LLVM code style.
Looks better. Can you check https://llvm.org/docs/CodingStandards.html for the 
code style?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106674

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


[PATCH] D106959: [PowerPC] swdiv builtins for XL compatibility

2021-07-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/LowerCheckedFPArith.ll:36
+; CHECK-NEXT:  %2 = fdiv fast float %0, %1
+; CHECK-NEXT:  %3 = fcmp une float %2, %2
+; CHECK-NEXT:  br i1 %3, label %swdiv_HWDIV, label %swdiv_MERGE

A "fast" fdiv never produces NaN, per LangRef.  Using fcmp like this is fragile 
at best.

(Maybe you want "fdiv arcp"?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106959

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


[PATCH] D106907: [clang] fix concepts crash on substitution failure during normalization

2021-07-28 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG87aa31827b29: [clang] fix concepts crash on substitution 
failure during normalization (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106907

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp


Index: clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
===
--- clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
+++ clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
@@ -67,3 +67,18 @@
 
   static_assert((foo<1>(), true));
 }
+
+namespace PR47174 {
+// This checks that we don't crash with a failed substitution on the first 
constrained argument when
+// performing normalization.
+template 
+requires true struct S3; // expected-note {{template is declared here}}
+template 
+requires true struct S3; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+
+// Same as above, for the second position (but this was already working).
+template 
+requires true struct S4; // expected-note {{template is declared here}}
+template 
+requires true struct S4; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+} // namespace PR47174
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -742,22 +742,15 @@
 NormalizedConstraint::fromConstraintExprs(Sema , NamedDecl *D,
   ArrayRef E) {
   assert(E.size() != 0);
-  auto First = fromConstraintExpr(S, D, E[0]);
-  if (E.size() == 1)
-return First;
-  auto Second = fromConstraintExpr(S, D, E[1]);
-  if (!Second)
+  auto Conjunction = fromConstraintExpr(S, D, E[0]);
+  if (!Conjunction)
 return None;
-  llvm::Optional Conjunction;
-  Conjunction.emplace(S.Context, std::move(*First), std::move(*Second),
-  CCK_Conjunction);
-  for (unsigned I = 2; I < E.size(); ++I) {
+  for (unsigned I = 1; I < E.size(); ++I) {
 auto Next = fromConstraintExpr(S, D, E[I]);
 if (!Next)
-  return llvm::Optional{};
-NormalizedConstraint NewConjunction(S.Context, std::move(*Conjunction),
+  return None;
+*Conjunction = NormalizedConstraint(S.Context, std::move(*Conjunction),
 std::move(*Next), CCK_Conjunction);
-*Conjunction = std::move(NewConjunction);
   }
   return Conjunction;
 }


Index: clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
===
--- clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
+++ clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
@@ -67,3 +67,18 @@
 
   static_assert((foo<1>(), true));
 }
+
+namespace PR47174 {
+// This checks that we don't crash with a failed substitution on the first constrained argument when
+// performing normalization.
+template 
+requires true struct S3; // expected-note {{template is declared here}}
+template 
+requires true struct S3; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+// Same as above, for the second position (but this was already working).
+template 
+requires true struct S4; // expected-note {{template is declared here}}
+template 
+requires true struct S4; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+} // namespace PR47174
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -742,22 +742,15 @@
 NormalizedConstraint::fromConstraintExprs(Sema , NamedDecl *D,
   ArrayRef E) {
   assert(E.size() != 0);
-  auto First = fromConstraintExpr(S, D, E[0]);
-  if (E.size() == 1)
-return First;
-  auto Second = fromConstraintExpr(S, D, E[1]);
-  if (!Second)
+  auto Conjunction = fromConstraintExpr(S, D, E[0]);
+  if (!Conjunction)
 return None;
-  llvm::Optional Conjunction;
-  Conjunction.emplace(S.Context, std::move(*First), std::move(*Second),
-  CCK_Conjunction);
-  for (unsigned I = 2; I < E.size(); ++I) {
+  for (unsigned I = 1; I < E.size(); ++I) {
 auto Next = fromConstraintExpr(S, D, E[I]);
 if (!Next)
-  return llvm::Optional{};
-NormalizedConstraint NewConjunction(S.Context, std::move(*Conjunction),
+  return None;
+*Conjunction = NormalizedConstraint(S.Context, std::move(*Conjunction),
 std::move(*Next), CCK_Conjunction);
-*Conjunction = std::move(NewConjunction);
  

[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr

2021-07-28 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mizvekov marked an inline comment as done.
Closed by commit rG0c7cd4a87313: [clang] NFC: refactor multiple implementations 
of… (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100713

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -73,26 +73,7 @@
   const Expr *E = getOriginExpr();
   if (!E)
 return Ctx.VoidTy;
-  assert(E);
-
-  QualType ResultTy = E->getType();
-
-  // A function that returns a reference to 'int' will have a result type
-  // of simply 'int'. Check the origin expr's value kind to recover the
-  // proper type.
-  switch (E->getValueKind()) {
-  case VK_LValue:
-ResultTy = Ctx.getLValueReferenceType(ResultTy);
-break;
-  case VK_XValue:
-ResultTy = Ctx.getRValueReferenceType(ResultTy);
-break;
-  case VK_PRValue:
-// No adjustment is necessary.
-break;
-  }
-
-  return ResultTy;
+  return Ctx.getReferenceQualifiedType(E);
 }
 
 static bool isCallback(QualType T) {
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8891,29 +8891,6 @@
   return Context.getTypeOfExprType(E);
 }
 
-/// getDecltypeForParenthesizedExpr - Given an expr, will return the type for
-/// that expression, as in [dcl.type.simple]p4 but without taking id-expressions
-/// and class member access into account.
-QualType Sema::getDecltypeForParenthesizedExpr(Expr *E) {
-  // C++11 [dcl.type.simple]p4:
-  //   [...]
-  QualType T = E->getType();
-  switch (E->getValueKind()) {
-  // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the
-  //   type of e;
-  case VK_XValue:
-return Context.getRValueReferenceType(T);
-  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
-  //   type of e;
-  case VK_LValue:
-return Context.getLValueReferenceType(T);
-  //  - otherwise, decltype(e) is the type of e.
-  case VK_PRValue:
-return T;
-  }
-  llvm_unreachable("Unknown value kind");
-}
-
 /// getDecltypeForExpr - Given an expr, will return the decltype for
 /// that expression, according to the rules in C++11
 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
@@ -8983,7 +8960,7 @@
 }
   }
 
-  return S.getDecltypeForParenthesizedExpr(E);
+  return S.Context.getReferenceQualifiedType(E);
 }
 
 QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5891,10 +5891,8 @@
   //   -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
   //  implicitly converted to the type "rvalue reference to R2", subject to
   //  the constraint that the reference must bind directly.
-  if (To->isLValue() || To->isXValue()) {
-QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType)
-: Self.Context.getRValueReferenceType(ToType);
-
+  if (To->isGLValue()) {
+QualType T = Self.Context.getReferenceQualifiedType(To);
 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
 
 InitializationSequence InitSeq(Self, Entity, Kind, From);
@@ -8743,7 +8741,7 @@
 TemplateParameterList *TPL =
 ReturnTypeRequirement.getTypeConstraintTemplateParameterList();
 QualType MatchedType =
-getDecltypeForParenthesizedExpr(E).getCanonicalType();
+Context.getReferenceQualifiedType(E).getCanonicalType();
 llvm::SmallVector Args;
 Args.push_back(TemplateArgument(MatchedType));
 TemplateArgumentList TAL(TemplateArgumentList::OnStack, Args);
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19402,14 +19402,7 @@
 if (ParamTypes.empty() && Proto->isVariadic()) { // the special case
   ArgTypes.reserve(E->getNumArgs());
   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
-Expr *Arg = E->getArg(i);
-QualType ArgType = Arg->getType();
-if (E->isLValue()) {
-  ArgType = S.Context.getLValueReferenceType(ArgType);
-} else if (E->isXValue()) {
-  ArgType = S.Context.getRValueReferenceType(ArgType);
-}
- 

[clang] 87aa318 - [clang] fix concepts crash on substitution failure during normalization

2021-07-28 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-28T23:28:45+02:00
New Revision: 87aa31827b293127619e2ef96e80baf709eae338

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

LOG: [clang] fix concepts crash on substitution failure during normalization

When substitution failed on the first constrained template argument (but
only the first), we would assert / crash. Checking for failure was only
being performed from the second constraint on.

This changes it so the checking is performed in that case,
and the code is also now simplified a little bit to hopefully
avoid this confusion.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 30f0730671c0a..82443be09c062 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -742,22 +742,15 @@ Optional
 NormalizedConstraint::fromConstraintExprs(Sema , NamedDecl *D,
   ArrayRef E) {
   assert(E.size() != 0);
-  auto First = fromConstraintExpr(S, D, E[0]);
-  if (E.size() == 1)
-return First;
-  auto Second = fromConstraintExpr(S, D, E[1]);
-  if (!Second)
+  auto Conjunction = fromConstraintExpr(S, D, E[0]);
+  if (!Conjunction)
 return None;
-  llvm::Optional Conjunction;
-  Conjunction.emplace(S.Context, std::move(*First), std::move(*Second),
-  CCK_Conjunction);
-  for (unsigned I = 2; I < E.size(); ++I) {
+  for (unsigned I = 1; I < E.size(); ++I) {
 auto Next = fromConstraintExpr(S, D, E[I]);
 if (!Next)
-  return llvm::Optional{};
-NormalizedConstraint NewConjunction(S.Context, std::move(*Conjunction),
+  return None;
+*Conjunction = NormalizedConstraint(S.Context, std::move(*Conjunction),
 std::move(*Next), CCK_Conjunction);
-*Conjunction = std::move(NewConjunction);
   }
   return Conjunction;
 }

diff  --git a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp 
b/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
index 153d4a56bea31..2134968101470 100644
--- a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
+++ b/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
@@ -67,3 +67,18 @@ namespace non_type_pack {
 
   static_assert((foo<1>(), true));
 }
+
+namespace PR47174 {
+// This checks that we don't crash with a failed substitution on the first 
constrained argument when
+// performing normalization.
+template 
+requires true struct S3; // expected-note {{template is declared here}}
+template 
+requires true struct S3; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+
+// Same as above, for the second position (but this was already working).
+template 
+requires true struct S4; // expected-note {{template is declared here}}
+template 
+requires true struct S4; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+} // namespace PR47174



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


[clang] 0c7cd4a - [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr

2021-07-28 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-28T23:27:43+02:00
New Revision: 0c7cd4a873138f2116403a733274c8cb7dbf925f

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

LOG: [clang] NFC: refactor multiple implementations of 
getDecltypeForParenthesizedExpr

This cleanup patch refactors a bunch of functional duplicates of
getDecltypeForParenthesizedExpr into a common implementation.

Signed-off-by: Matheus Izvekov 

Reviewed By: aaronpuchert

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ExprObjC.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 34299581d89d4..da372e854700b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1631,6 +1631,8 @@ class ASTContext : public RefCountedBase {
   QualType getTypeOfExprType(Expr *e) const;
   QualType getTypeOfType(QualType t) const;
 
+  QualType getReferenceQualifiedType(const Expr *e) const;
+
   /// C++11 decltype.
   QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 375b650b8ecb3..1a696b4938061 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2330,7 +2330,6 @@ class Sema final {
  const CXXScopeSpec , QualType T,
  TagDecl *OwnedTagDecl = nullptr);
 
-  QualType getDecltypeForParenthesizedExpr(Expr *E);
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
   /// context, such as when building a type for decltype(auto).

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e102a3ba508d4..4c16ddc782fa9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5454,6 +5454,29 @@ QualType ASTContext::getTypeOfType(QualType tofType) 
const {
   return QualType(tot, 0);
 }
 
+/// getReferenceQualifiedType - Given an expr, will return the type for
+/// that expression, as in [dcl.type.simple]p4 but without taking 
id-expressions
+/// and class member access into account.
+QualType ASTContext::getReferenceQualifiedType(const Expr *E) const {
+  // C++11 [dcl.type.simple]p4:
+  //   [...]
+  QualType T = E->getType();
+  switch (E->getValueKind()) {
+  // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the
+  //   type of e;
+  case VK_XValue:
+return getRValueReferenceType(T);
+  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
+  //   type of e;
+  case VK_LValue:
+return getLValueReferenceType(T);
+  //  - otherwise, decltype(e) is the type of e.
+  case VK_PRValue:
+return T;
+  }
+  llvm_unreachable("Unknown value kind");
+}
+
 /// Unlike many "get" functions, we don't unique DecltypeType
 /// nodes. This would never be helpful, since each such type has its own
 /// expression, and would not give a significant memory saving, since there

diff  --git a/clang/lib/AST/ExprObjC.cpp b/clang/lib/AST/ExprObjC.cpp
index 7d932c8b059da..a3222c2da24fd 100644
--- a/clang/lib/AST/ExprObjC.cpp
+++ b/clang/lib/AST/ExprObjC.cpp
@@ -271,20 +271,7 @@ QualType ObjCMessageExpr::getCallReturnType(ASTContext 
) const {
 }
 return QT;
   }
-
-  // Expression type might be 
diff erent from an expected call return type,
-  // as expression type would never be a reference even if call returns a
-  // reference. Reconstruct the original expression type.
-  QualType QT = getType();
-  switch (getValueKind()) {
-  case VK_LValue:
-return Ctx.getLValueReferenceType(QT);
-  case VK_XValue:
-return Ctx.getRValueReferenceType(QT);
-  case VK_PRValue:
-return QT;
-  }
-  llvm_unreachable("Unsupported ExprValueKind");
+  return Ctx.getReferenceQualifiedType(this);
 }
 
 SourceRange ObjCMessageExpr::getReceiverRange() const {

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f2c70d0a56efb..30f0730671c0a 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -461,7 +461,7 @@ static void diagnoseUnsatisfiedRequirement(Sema ,
 Expr *e = Req->getExpr();
 S.Diag(e->getBeginLoc(),
diag::note_expr_requirement_constraints_not_satisfied_simple)
-<< (int)First << S.getDecltypeForParenthesizedExpr(e)
+<< (int)First << 

[PATCH] D107004: Turn off fp reassociation in IA intrinsic header files.

2021-07-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Patch description states what the change is, but not why the change is what it 
is.
I don't think this is a good direction to second-guess the user's intentions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107004

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


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-07-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I think module maps that specify textual headers should be considered inputs if 
we entered any of those textual headers; we won't treat those as being 
imported. In addition to considering the current module and its imports, 
perhaps we should walk the preprocessor's headers list and add the module maps 
corresponding to the modules of all headers that were entered?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106876

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


[PATCH] D107004: Turn off fp reassociation in IA intrinsic header files.

2021-07-28 Thread Kevin B. Smith via Phabricator via cfe-commits
kbsmith1 created this revision.
kbsmith1 added reviewers: craig.topper, aaron.ballman, erichkeane, 
andrew.w.kaylor.
kbsmith1 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change uses #pragma float_control and
floating point fast-math reassociation flags for IA intrinsics
that happen to be implemented using LLVM IR's regular FP
operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107004

Files:
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/x86intrin.h
  clang/lib/Headers/xmmintrin.h
  clang/test/Headers/emmintrin.c
  clang/test/Headers/immintrin.c
  clang/test/Headers/x86intrin-3.c
  clang/test/Headers/xmmintrin.c

Index: clang/test/Headers/xmmintrin.c
===
--- clang/test/Headers/xmmintrin.c
+++ clang/test/Headers/xmmintrin.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-macosx10.9.0 -emit-llvm -o - | FileCheck %s
 //
+// RUN: %clang_cc1 %s -ffreestanding -ffast-math -triple x86_64-apple-macosx10.9.0 -emit-llvm -o - \
+// RUN: | FileCheck -check-prefix=CKFMATH %s
+//
 // RUN: rm -rf %t
 // RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-macosx10.9.0 -emit-llvm -o - \
 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -isystem %S/Inputs/include \
@@ -26,6 +29,21 @@
   return _mm_add_sd(__a, __b);
 }
 
+// Make sure that the llvm IR for _mm_add_ps doesn't have fast attribute and
+// doesn't have reassoc set.
+// CKFMATH: define{{.*}} <4 x float> @test_xmmintrin_no_reassoc
+// CKFMATH: fadd nnan ninf nsz arcp afn <4 x float>
+__m128 test_xmmintrin_no_reassoc(__m128 __a, __m128 __b) {
+  return _mm_add_ps(__a, __b);
+}
+
+// Make sure that all fast flags were restored outside of the include file.
+// CKFMATH: define{{.*}} double @test_fast
+// CKFMATH: fadd reassoc nnan ninf nsz arcp afn double
+double test_fast(double __a, double __b) {
+  return __a + __b;
+}
+
 #if __STDC_HOSTED__
 // Make sure stdlib.h symbols are accessible.
 void *p = NULL;
Index: clang/test/Headers/x86intrin-3.c
===
--- /dev/null
+++ clang/test/Headers/x86intrin-3.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 %s -ffreestanding -ffast-math -triple i386-unknown-unknown -emit-llvm -o - \
+// RUN: | FileCheck -check-prefix=CKFMATH %s
+//
+// RUN: %clang_cc1 %s -ffreestanding -ffast-math -triple x86_64-unknown-unknown -emit-llvm -o - \
+// RUN: | FileCheck -check-prefix=CKFMATH %s
+
+// Include the metaheader that includes all x86 intrinsic headers.
+#include 
+
+// Make sure that the llvm IR for _mm_add_ps doesn't have fast attribute and
+// doesn't have reassoc set.
+// CKFMATH: define{{.*}} <4 x float> @test_xmmintrin_no_reassoc
+// CKFMATH: fadd nnan ninf nsz arcp afn <4 x float>
+__m128 __attribute__((__target__("sse"))) test_xmmintrin_no_reassoc(__m128 __a, __m128 __b) {
+  return _mm_add_ps(__a, __b);
+}
+
+// Make sure that the llvm IR for _mm_add_pd doesn't have fast attribute and
+// doesn't have reassoc set.
+// CKFMATH: define{{.*}} <2 x double> @test_emmintrin_no_reassoc
+// CKFMATH: fadd nnan ninf nsz arcp afn <2 x double>
+__m128d __attribute__((__target__("sse2"))) test_emmintrin_no_reassoc(__m128d __a, __m128d __b) {
+  return _mm_add_pd(__a, __b);
+}
+
+// Make sure that the llvm IR for _mm256_add_ps doesn't have fast attribute and
+// doesn't have reassoc set.
+// This intrinsic comes from avxintrin.h, and so is checking that
+// changes in immintrin.h affect the files it includes as well.
+// CKFMATH: define{{.*}} <8 x float> @test_mm256intrin_no_reassoc
+// CKFMATH: fadd nnan ninf nsz arcp afn <8 x float>
+__m256 __attribute__((__target__(("avx" test_mm256intrin_no_reassoc(__m256 __a, __m256 __b) {
+  return _mm256_add_ps(__a, __b);
+}
+
+// Make sure that the llvm IR for _mm512_add_ps doesn't have fast attribute and
+// doesn't have reassoc set.
+// This intrinsic comes from avxintrin.h
+// CKFMATH: define{{.*}} <16 x float> @test_mm512intrin_no_reassoc
+// CKFMATH: fadd nnan ninf nsz arcp afn <16 x float>
+__m512 __attribute__((__target__(("avx512f" test_mm512intrin_no_reassoc(__m512 __a, __m512 __b) {
+  return _mm512_add_ps(__a, __b);
+}
+
+// Make sure that all fast flags were restored outside of the include file.
+// CKFMATH: define{{.*}} double @test_fast
+// CKFMATH: fadd reassoc nnan ninf nsz arcp afn double
+double test_fast(double __a, double __b) {
+  return __a + __b;
+}
Index: clang/test/Headers/immintrin.c
===
--- /dev/null
+++ clang/test/Headers/immintrin.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 %s -ffreestanding -ffast-math -triple i386-unknown-unknown -emit-llvm -o - \
+// RUN: | FileCheck -check-prefix=CKFMATH %s
+//
+// RUN: %clang_cc1 %s -ffreestanding -ffast-math -triple x86_64-unknown-unknown -emit-llvm -o - \
+// 

[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-07-28 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 362536.
lei added a comment.

remove extra space


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-64bit.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
@@ -29,3 +29,24 @@
   ret double %0
 }
 declare double @llvm.ppc.insert.exp(double, i64)
+
+declare i64 @llvm.ppc.addex(i64, i64, i32 immarg)
+define dso_local i64 @call_addex_0(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_0:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
+
+define dso_local i64 @call_addex_1(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1670,6 +1670,13 @@
  "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
 }
 
+let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
+def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
+  (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
+  "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
+  [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
+timm:$CY))]>;
+
 //===--===//
 // Instruction Patterns
 //
@@ -1821,6 +1828,7 @@
 let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
 def CP_COPY8   : X_RA5_RB5<31, 774, "copy"  , g8rc, IIC_LdStCOPY, []>;
 def CP_PASTE8_rec : X_L1_RA5_RB5<31, 902, "paste.", g8rc, IIC_LdStPASTE, []>,isRecordForm;
+
 }
 
 // SLB Invalidate Entry Global
@@ -1828,7 +1836,6 @@
   "slbieg $RS, $RB", IIC_SprSLBIEG, []>;
 // SLB Synchronize
 def SLBSYNC : XForm_0<31, 338, (outs), (ins), "slbsync", IIC_SprSLBSYNC, []>;
-
 } // IsISA3_0
 
 def : Pat<(int_ppc_stdcx ForceXForm:$dst, g8rc:$A),
Index: llvm/lib/Target/PowerPC/P9InstrResources.td
===
--- llvm/lib/Target/PowerPC/P9InstrResources.td
+++ llvm/lib/Target/PowerPC/P9InstrResources.td
@@ -1430,5 +1430,6 @@
   DCBI,
   DCCCI,
   ICCCI,
-  ADDEX
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1706,7 +1706,10 @@
   def int_ppc_fres
   : GCCBuiltin<"__builtin_ppc_fres">,
 Intrinsic <[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
-  
+  def int_ppc_addex
+  : GCCBuiltin<"__builtin_ppc_addex">,
+Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, ImmArg>]>;
   def int_ppc_fsel : GCCBuiltin<"__builtin_ppc_fsel">,
  Intrinsic<[llvm_double_ty], [llvm_double_ty, llvm_double_ty, 
   llvm_double_ty], [IntrNoMem]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
@@ -0,0 +1,11 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr9 \
+// RUN:   -verify %s
+
+extern unsigned long long ull;
+extern long long ll;
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 1); // expected-warning {{argument value 1 will resullt in undefined behaviour}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, 3); // expected-warning {{argument value 3 will resullt in undefined behaviour}}
+}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c

[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-07-28 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 362535.
lei added a comment.

fix minor wording and spelling mistakes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107002

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-64bit.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
@@ -29,3 +29,25 @@
   ret double %0
 }
 declare double @llvm.ppc.insert.exp(double, i64)
+
+
+declare i64 @llvm.ppc.addex(i64, i64, i32 immarg)
+define dso_local i64 @call_addex_0(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_0:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
+
+define dso_local i64 @call_addex_1(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1670,6 +1670,13 @@
  "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
 }
 
+let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
+def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
+  (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
+  "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
+  [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
+timm:$CY))]>;
+
 //===--===//
 // Instruction Patterns
 //
@@ -1821,6 +1828,7 @@
 let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
 def CP_COPY8   : X_RA5_RB5<31, 774, "copy"  , g8rc, IIC_LdStCOPY, []>;
 def CP_PASTE8_rec : X_L1_RA5_RB5<31, 902, "paste.", g8rc, IIC_LdStPASTE, []>,isRecordForm;
+
 }
 
 // SLB Invalidate Entry Global
@@ -1828,7 +1836,6 @@
   "slbieg $RS, $RB", IIC_SprSLBIEG, []>;
 // SLB Synchronize
 def SLBSYNC : XForm_0<31, 338, (outs), (ins), "slbsync", IIC_SprSLBSYNC, []>;
-
 } // IsISA3_0
 
 def : Pat<(int_ppc_stdcx ForceXForm:$dst, g8rc:$A),
Index: llvm/lib/Target/PowerPC/P9InstrResources.td
===
--- llvm/lib/Target/PowerPC/P9InstrResources.td
+++ llvm/lib/Target/PowerPC/P9InstrResources.td
@@ -1430,5 +1430,6 @@
   DCBI,
   DCCCI,
   ICCCI,
-  ADDEX
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1706,7 +1706,10 @@
   def int_ppc_fres
   : GCCBuiltin<"__builtin_ppc_fres">,
 Intrinsic <[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
-  
+  def int_ppc_addex
+  : GCCBuiltin<"__builtin_ppc_addex">,
+Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, ImmArg>]>;
   def int_ppc_fsel : GCCBuiltin<"__builtin_ppc_fsel">,
  Intrinsic<[llvm_double_ty], [llvm_double_ty, llvm_double_ty, 
   llvm_double_ty], [IntrNoMem]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
@@ -0,0 +1,11 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr9 \
+// RUN:   -verify %s
+
+extern unsigned long long ull;
+extern long long ll;
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 1); // expected-warning {{argument value 1 will resullt in undefined behaviour}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, 3); // expected-warning {{argument value 3 will resullt in undefined behaviour}}
+}
Index: 

[PATCH] D104887: [clang] Evaluate strlen of strcpy argument for -Wfortify-source.

2021-07-28 Thread George Burgess IV via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe12e02df09a9: [clang] Evaluate strlen of strcpy argument for 
-Wfortify-source. (authored by mbenfield, committed by gbiv).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104887

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/security-syntax-checks.m
  clang/test/Sema/warn-fortify-source.c

Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -58,6 +58,19 @@
   __builtin_stpncpy(s1, s2, 20); // expected-warning {{'stpncpy' size argument is too large; destination buffer has size 10, but size argument is 20}}
 }
 
+void call_strcpy() {
+  const char *const src = "abcd";
+  char dst[4];
+  __builtin_strcpy(dst, src); // expected-warning {{'strcpy' will always overflow; destination buffer has size 4, but the source string has length 5 (including NUL byte)}}
+}
+
+void call_strcpy_nowarn() {
+  const char *const src = "abcd";
+  char dst[5];
+  // We should not get a warning here.
+  __builtin_strcpy(dst, src);
+}
+
 void call_memmove() {
   char s1[10], s2[20];
   __builtin_memmove(s2, s1, 20);
Index: clang/test/Analysis/security-syntax-checks.m
===
--- clang/test/Analysis/security-syntax-checks.m
+++ clang/test/Analysis/security-syntax-checks.m
@@ -1,37 +1,37 @@
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify \
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
 
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify \
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-cloudabi %s -verify -Wno-fortify-source \
 // RUN:   -DUSE_BUILTINS -DVARIANT \
 // RUN:   -analyzer-checker=security.insecureAPI \
 // RUN:   -analyzer-checker=security.FloatLoopCounter
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -588,14 +588,8 @@
 
 } // namespace
 
-/// Check a call to BuiltinID for buffer overflows. If BuiltinID is a
-/// __builtin_*_chk function, then use the object size argument specified in the
-/// source. Otherwise, infer the object size using __builtin_object_size.
 void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
CallExpr *TheCall) {
-  // FIXME: There are some more useful checks we could be doing here:
-  //  - Evaluate strlen of strcpy arguments, use as object size.
-
   if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
   isConstantEvaluated())
 return;
@@ -607,13 +601,66 @@
   const TargetInfo  = 

[clang] e12e02d - [clang] Evaluate strlen of strcpy argument for -Wfortify-source.

2021-07-28 Thread George Burgess IV via cfe-commits

Author: Michael Benfield
Date: 2021-07-28T20:52:57Z
New Revision: e12e02df09a967f644cf28136a7361bce7a5bb91

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

LOG: [clang] Evaluate strlen of strcpy argument for -Wfortify-source.

Also introduce Expr::tryEvaluateStrLen.

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

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/Analysis/security-syntax-checks.m
clang/test/Sema/warn-fortify-source.c

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 06164411cc2d4..991abef733637 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -740,6 +740,12 @@ class Expr : public ValueStmt {
   bool tryEvaluateObjectSize(uint64_t , ASTContext ,
  unsigned Type) const;
 
+  /// If the current Expr is a pointer, this will try to statically
+  /// determine the strlen of the string pointed to.
+  /// Returns true if all of the above holds and we were able to figure out the
+  /// strlen, false otherwise.
+  bool tryEvaluateStrLen(uint64_t , ASTContext ) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 00b443b45f132..a777f08de8909 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -816,6 +816,11 @@ def warn_fortify_source_size_mismatch : Warning<
   "'%0' size argument is too large; destination buffer has size %1,"
   " but size argument is %2">, InGroup;
 
+def warn_fortify_strlen_overflow: Warning<
+  "'%0' will always overflow; destination buffer has size %1,"
+  " but the source string has length %2 (including NUL byte)">,
+  InGroup;
+
 def warn_fortify_source_format_overflow : Warning<
   "'%0' will always overflow; destination buffer has size %1,"
   " but format string expands to at least %2">,

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 01c0168d61a40..f49a144879b3e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1826,6 +1826,8 @@ static bool EvaluateComplex(const Expr *E, ComplexValue 
, EvalInfo );
 static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue ,
EvalInfo );
 static bool EvaluateAsRValue(EvalInfo , const Expr *E, APValue );
+static bool EvaluateBuiltinStrLen(const Expr *E, uint64_t ,
+  EvalInfo );
 
 /// Evaluate an integer or fixed point expression into an APResult.
 static bool EvaluateFixedPointOrInteger(const Expr *E, APFixedPoint ,
@@ -11836,46 +11838,10 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_wcslen: {
 // As an extension, we support __builtin_strlen() as a constant expression,
 // and support folding strlen() to a constant.
-LValue String;
-if (!EvaluatePointer(E->getArg(0), String, Info))
-  return false;
-
-QualType CharTy = E->getArg(0)->getType()->getPointeeType();
-
-// Fast path: if it's a string literal, search the string value.
-if (const StringLiteral *S = dyn_cast_or_null(
-String.getLValueBase().dyn_cast())) {
-  // The string literal may have embedded null characters. Find the first
-  // one and truncate there.
-  StringRef Str = S->getBytes();
-  int64_t Off = String.Offset.getQuantity();
-  if (Off >= 0 && (uint64_t)Off <= (uint64_t)Str.size() &&
-  S->getCharByteWidth() == 1 &&
-  // FIXME: Add fast-path for wchar_t too.
-  Info.Ctx.hasSameUnqualifiedType(CharTy, Info.Ctx.CharTy)) {
-Str = Str.substr(Off);
-
-StringRef::size_type Pos = Str.find(0);
-if (Pos != StringRef::npos)
-  Str = Str.substr(0, Pos);
-
-return Success(Str.size(), E);
-  }
-
-  // Fall through to slow path to issue appropriate diagnostic.
-}
-
-// Slow path: scan the bytes of the string looking for the terminating 0.
-for (uint64_t Strlen = 0; /**/; ++Strlen) {
-  APValue Char;
-  if (!handleLValueToRValueConversion(Info, E, CharTy, String, Char) ||
-  !Char.isInt())
-return false;
-  if (!Char.getInt())
-return Success(Strlen, E);
-  if (!HandleLValueArrayAdjustment(Info, E, String, CharTy, 1))
-return false;
-}
+uint64_t StrLen;
+if (EvaluateBuiltinStrLen(E->getArg(0), StrLen, 

[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-28 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 362528.
beanz added a comment.

Covered taken #elif* directives per @aaron.ballmon's feedback.

Handling non-taken #elif directives is non-trivial because clang skips parsing 
the conditionals for non-taken directives. At present clang won't even error on 
malformed #elif directives if an earlier branch is taken.

Also with this update I refactored the error emitting code out to a function on 
the Preprocessor, since it is just getting copy and pasted over and over again, 
and this change would have added another copy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/deprecate-macro.c

Index: clang/test/Lexer/deprecate-macro.c
===
--- /dev/null
+++ clang/test/Lexer/deprecate-macro.c
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -Wdeprecated %s -fsyntax-only -verify
+
+// expected-error@+1{{expected (}}
+#pragma clang deprecated
+
+// expected-error@+1{{expected identifier}}
+#pragma clang deprecated(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang deprecated(foo)
+
+#define bar 1
+#pragma clang deprecated(bar, "bar is deprecated use 1")
+
+// expected-warning@+1{{macro 'bar' has been marked as deprecated: bar is deprecated use 1}}
+#if bar
+#endif
+
+#define foo 1
+#pragma clang deprecated(foo)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(foo
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#if defined(foo)
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif
+
+int main(int argc, char** argv) {
+  // expected-error@+1{{no macro named main}}
+#pragma clang deprecated(main)
+
+  // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+  return foo;
+}
+
+#define frobble 1
+#pragma clang deprecated(frobble)
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#undef frobble // Expect no diagnostics here
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#define frobble 1 // How about here given that this was undefined?
+
+// not-expected-warning@+1{{macro 'frobble' has been marked as deprecated}}
+#if defined(frobble)
+#endif
+
+// Test that we diagnose on #elif
+#if 0
+#elif foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef foo
+// expected-warning@-1{{macro 'foo' has been marked as deprecated}}
+#endif
+
+// Test that we diagnose on #elifndef.
+#ifdef baz
+#elifndef foo
+#endif
+// expected-warning@-2{{macro 'foo' has been marked as deprecated}}
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1413,6 +1413,18 @@
   return true;
 }
 
+void Preprocessor::emitMacroExpansionWarnings(Token ) {
+  if (Identifier.getIdentifierInfo()->isDeprecatedMacro()) {
+auto DepMsg = getMacroDeprecationMsg(Identifier.getIdentifierInfo());
+if (!DepMsg)
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 0;
+else
+  Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
+  << Identifier.getIdentifierInfo() << 1 << *DepMsg;
+  }
+}
+
 ModuleLoader::~ModuleLoader() = default;
 
 CommentHandler::~CommentHandler() = default;
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1911,6 +1911,57 @@
   }
 };
 
+/// "\#pragma clang deprecated(...)"
+///
+/// The syntax is
+/// \code
+///   #pragma clang deprecate(MACRO_NAME [, Message])
+/// \endcode
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor , PragmaIntroducer Introducer,
+Token ) override {
+std::string Macro, MessageString;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Tok, diag::err_expected) << "(";
+  return;
+}
+
+PP.LexUnexpandedToken(Tok);
+if (!Tok.is(tok::identifier)) {
+  PP.Diag(Tok, diag::err_expected) << tok::identifier;
+  return;
+}
+

[PATCH] D107002: [PowerPC] Implement XL compatibility builtin __addex

2021-07-28 Thread Lei Huang via Phabricator via cfe-commits
lei created this revision.
lei added reviewers: stefanp, nemanjai, NeHuang, power-llvm-team.
Herald added subscribers: shchenz, hiraditya.
lei requested review of this revision.
Herald added projects: clang, LLVM.

Add builtin and intrinsic for `__addex`.

This patch is part of a series of patches to provide builtins for
compatibility with the XL compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107002

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-64bit.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-pwr9-64bit.ll
@@ -29,3 +29,25 @@
   ret double %0
 }
 declare double @llvm.ppc.insert.exp(double, i64)
+
+
+declare i64 @llvm.ppc.addex(i64, i64, i32 immarg)
+define dso_local i64 @call_addex_0(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_0:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
+
+define dso_local i64 @call_addex_1(i64 %a, i64 %b) {
+; CHECK-LABEL: call_addex_1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addex 3, 3, 4, 0
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i64 @llvm.ppc.addex(i64 %a, i64 %b, i32 0)
+  ret i64 %0
+}
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1670,6 +1670,13 @@
  "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
 }
 
+let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
+def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
+  (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
+  "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
+  [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
+timm:$CY))]>;
+
 //===--===//
 // Instruction Patterns
 //
@@ -1828,7 +1835,6 @@
   "slbieg $RS, $RB", IIC_SprSLBIEG, []>;
 // SLB Synchronize
 def SLBSYNC : XForm_0<31, 338, (outs), (ins), "slbsync", IIC_SprSLBSYNC, []>;
-
 } // IsISA3_0
 
 def : Pat<(int_ppc_stdcx ForceXForm:$dst, g8rc:$A),
Index: llvm/lib/Target/PowerPC/P9InstrResources.td
===
--- llvm/lib/Target/PowerPC/P9InstrResources.td
+++ llvm/lib/Target/PowerPC/P9InstrResources.td
@@ -1430,5 +1430,6 @@
   DCBI,
   DCCCI,
   ICCCI,
-  ADDEX
+  ADDEX,
+  ADDEX8
 )> { let Unsupported = 1; }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1706,7 +1706,10 @@
   def int_ppc_fres
   : GCCBuiltin<"__builtin_ppc_fres">,
 Intrinsic <[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
-  
+  def int_ppc_addex
+  : GCCBuiltin<"__builtin_ppc_addex">,
+Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, ImmArg>]>;
   def int_ppc_fsel : GCCBuiltin<"__builtin_ppc_fsel">,
  Intrinsic<[llvm_double_ty], [llvm_double_ty, llvm_double_ty, 
   llvm_double_ty], [IntrNoMem]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-warning.c
@@ -0,0 +1,11 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -target-cpu pwr9 \
+// RUN:   -verify %s
+
+extern unsigned long long ull;
+extern long long ll;
+
+void test_builtin_ppc_addex() {
+  long long res = __builtin_ppc_addex(ll, ll, 1); // expected-warning {{argument value 1 will resullt in undefined behaviour}}
+  unsigned long long res2 = __builtin_ppc_addex(ull, ull, 3); // expected-warning {{argument value 3 will resullt in undefined behaviour}}
+}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
===
--- 

[PATCH] D106674: Runtime for Interop directive

2021-07-28 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362524.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,120 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties")))
+return (*fptr)(interop);
+  return 0;
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int")))
+return (*fptr)(interop, property_id, err);
+  return 0;
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_NAME(
+const omp_interop_t interop, omp_interop_property_t property_id) {
+  const 

[PATCH] D105527: libclang.so: Make SONAME independent from LLVM version

2021-07-28 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

As this is a big deal for packager, maybe it should be part of the release 
notes ? (maybe it is and I just missed it :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105527

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


[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

For what it's worth, I think the right way to handle this in C is to properly 
implement the "compatible types" rule instead of trying to invent something 
ODR-ish: in C, struct definitions in different translation units are different 
types, but if they're structurally equivalent then they're compatible and you 
can implicitly pass an object of some type to a function accepting a compatible 
type. This would mean that we could have multiple, different types with the 
same name, and we'd need name lookup to deduplicate compatible types, but we 
wouldn't need to do any cross-module ODR-like struct merging.

But assuming we want to keep the current ODR-in-C approach, this looks OK. 
There might be some places that assume the lexical and semantic `DeclContext` 
for a C `FieldDecl` are the same (etc) but I don't think there's a good way to 
find such things other than by testing this patch broadly.




Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:832
+  RD->setCompleteDefinition(false);
+  Reader.mergeDefinitionVisibility(OldDef, RD);
+} else {

vsapsai wrote:
> Here is the perfect place to compare if `RD` and `OldDef` are equivalent and 
> emit diagnostic if they are not. I've tried `StructuralEquivalenceContext` 
> for this purpose but it compares canonical decls which doesn't work in this 
> case. I think the best approach for this task would be ODR hash comparison 
> proposed in https://reviews.llvm.org/D71734 It will need some tweaks to work 
> with the current patch but overall the plan is to use ODR hash instead of any 
> other decl comparison.
Just a minor note: it's not safe to emit diagnostics from here in general; in 
particular, emitting a diagnostic that refers to a declaration can trigger 
deserialization, which can reenter the AST reader in unfortunate ways and 
crash. But we can make a note to do the structural equivalence check here and 
then actually perform the check when we finish deserialization (with the other 
merging checks).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D103395: PR45879: Keep evaluated expression in LValue object

2021-07-28 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

Gentle ping. I can't review this, but if someone can, it would be awesome. 
https://bugs.llvm.org/show_bug.cgi?id=45879 is breaking some libc++ tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103395

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


[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:20
 
+#if !SANITIZER_FUCHSIA
+extern "C" {

vitalybuka wrote:
> isn't HWASAN_WITH_INTERCEPTORS enough?
Ignore this. !SANITIZER_FUCHSIA is OK here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:20
 
+#if !SANITIZER_FUCHSIA
+extern "C" {

isn't HWASAN_WITH_INTERCEPTORS enough?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D99381#2911057 , @eugenis wrote:

> They are used here:
> https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/malloc_common.h;l=54;drc=f3968e89cb72400951f93a2a8237ac1428d2627c

Thanks, it's preprocessor generated, so I can't find it :)

If so I guess LGTM.
But now they are in the same file, so instead of declarations, maybe just place 
SANITIZER_INTERFACE_ATTRIBUTE next to to the definition?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:832
+  RD->setCompleteDefinition(false);
+  Reader.mergeDefinitionVisibility(OldDef, RD);
+} else {

Here is the perfect place to compare if `RD` and `OldDef` are equivalent and 
emit diagnostic if they are not. I've tried `StructuralEquivalenceContext` for 
this purpose but it compares canonical decls which doesn't work in this case. I 
think the best approach for this task would be ODR hash comparison proposed in 
https://reviews.llvm.org/D71734 It will need some tweaks to work with the 
current patch but overall the plan is to use ODR hash instead of any other decl 
comparison.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-28 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 362511.

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

https://reviews.llvm.org/D106753

Files:
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTFWrapper.cpp
  llvm/unittests/Support/ConvertUTFTest.cpp

Index: llvm/unittests/Support/ConvertUTFTest.cpp
===
--- llvm/unittests/Support/ConvertUTFTest.cpp
+++ llvm/unittests/Support/ConvertUTFTest.cpp
@@ -36,6 +36,28 @@
   EXPECT_EQ(Expected, Result);
 }
 
+TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xA0\x0C\x00\x00_\xA0\x0C\x00\x00";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\x00\x00\x0C\xA0_\x00\x00\x0C\xA0";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
   // Src is the look of disapproval.
   static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0";
@@ -78,6 +100,17 @@
   EXPECT_FALSE(HasBOM);
 }
 
+TEST(ConvertUTFTest, UTF32WrappersForConvertUTF32ToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef SrcRef = makeArrayRef((const UTF32 *)Src, 4);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(SrcRef, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) {
   // Src is the look of disapproval.
   alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
Index: llvm/lib/Support/ConvertUTFWrapper.cpp
===
--- llvm/lib/Support/ConvertUTFWrapper.cpp
+++ llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -141,6 +141,64 @@
   Src.size() * sizeof(UTF16)), Out);
 }
 
+bool convertUTF32ToUTF8String(ArrayRef SrcBytes, std::string ) {
+  assert(Out.empty());
+
+  // Error out on an uneven byte count.
+  if (SrcBytes.size() % 4)
+return false;
+
+  // Avoid OOB by returning early on empty input.
+  if (SrcBytes.empty())
+return true;
+
+  const UTF32 *Src = reinterpret_cast(SrcBytes.begin());
+  const UTF32 *SrcEnd = reinterpret_cast(SrcBytes.end());
+
+  assert((uintptr_t)Src % sizeof(UTF32) == 0);
+
+  // Byteswap if necessary.
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
+for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
+  ByteSwapped[I] = llvm::ByteSwap_32(ByteSwapped[I]);
+Src = [0];
+SrcEnd = [ByteSwapped.size() - 1] + 1;
+  }
+
+  // Skip the BOM for conversion.
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_NATIVE)
+Src++;
+
+  // Just allocate enough space up front.  We'll shrink it later.  Allocate
+  // enough that we can fit a null terminator without reallocating.
+  Out.resize(SrcBytes.size() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
+  UTF8 *Dst = reinterpret_cast([0]);
+  UTF8 *DstEnd = Dst + Out.size();
+
+  ConversionResult CR =
+  ConvertUTF32toUTF8(, SrcEnd, , DstEnd, strictConversion);
+  assert(CR != targetExhausted);
+
+  if (CR != conversionOK) {
+Out.clear();
+return false;
+  }
+
+  Out.resize(reinterpret_cast(Dst) - [0]);
+  Out.push_back(0);
+  Out.pop_back();
+  return true;
+}
+
+bool convertUTF32ToUTF8String(ArrayRef Src, std::string ) {
+  return convertUTF32ToUTF8String(
+  llvm::ArrayRef(reinterpret_cast(Src.data()),
+   Src.size() * sizeof(UTF32)),
+  Out);
+}
+
 bool convertUTF8ToUTF16String(StringRef SrcUTF8,
   SmallVectorImpl ) {
   assert(DstUTF16.empty());
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -123,6 +123,9 @@
 #define UNI_UTF16_BYTE_ORDER_MARK_NATIVE  0xFEFF
 #define UNI_UTF16_BYTE_ORDER_MARK_SWAPPED 0xFFFE
 
+#define UNI_UTF32_BYTE_ORDER_MARK_NATIVE 0xFEFF
+#define UNI_UTF32_BYTE_ORDER_MARK_SWAPPED 0xFFFE
+
 typedef enum {
   conversionOK,   /* conversion successful */
   sourceExhausted,/* partial character in source, but hit end */
@@ -278,6 +281,24 @@
 */
 bool convertUTF16ToUTF8String(ArrayRef Src, std::string );
 
+/**
+ * 

[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Added John McCall in case I'm missing some CodeGen pieces.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106994

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


[PATCH] D106994: [modules] Fix miscompilation when using two RecordDecl definitions with the same name.

2021-07-28 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, bruno, teemperor.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

When deserializing a RecordDecl we don't enforce that redeclaration
chain contains only a single definition. So if the canonical decl is not
a definition itself, `RecordType::getDecl` can return different objects
before and after an include. It means we can build CGRecordLayout for
one RecordDecl with its set of FieldDecl but try to use it with
FieldDecl belonging to a different RecordDecl. With assertions enabled
it results in

> Assertion failed: (FieldInfo.count(FD) && "Invalid field for record!"),
> function getLLVMFieldNo, file 
> llvm-project/clang/lib/CodeGen/CGRecordLayout.h, line 199.

and with assertions disabled a bunch of fields are treated as their
memory is located at offset 0.

Fix by keeping the first encountered RecordDecl definition and marking
the subsequent ones as non-definitions. Also need to merge FieldDecl
properly, so that `getPrimaryMergedDecl` works correctly and during name
lookup we don't treat fields from same-name RecordDecl as ambiguous.

rdar://80184238


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106994

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  
clang/test/Modules/Inputs/merge-record-definition/RecordDef.framework/Headers/RecordDef.h
  
clang/test/Modules/Inputs/merge-record-definition/RecordDef.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefCopy.framework/Headers/RecordDefCopy.h
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefCopy.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Headers/Hidden.h
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Headers/Visible.h
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefIncluder.framework/Headers/RecordDefIncluder.h
  
clang/test/Modules/Inputs/merge-record-definition/RecordDefIncluder.framework/Modules/module.modulemap
  clang/test/Modules/merge-record-definition-nonmodular.m
  clang/test/Modules/merge-record-definition-visibility.m
  clang/test/Modules/merge-record-definition.m

Index: clang/test/Modules/merge-record-definition.m
===
--- /dev/null
+++ clang/test/Modules/merge-record-definition.m
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test a case when struct `Buffer` definition is present in two different modules.
+
+#import 
+
+void bibi(void) {
+  Buffer buf;
+  buf.b = 1;
+}
+
+#import 
+
+void mbap(void) {
+  Buffer buf;
+  buf.c = 2;
+}
Index: clang/test/Modules/merge-record-definition-visibility.m
===
--- /dev/null
+++ clang/test/Modules/merge-record-definition-visibility.m
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test a case when struct `Buffer` definition is first imported as invisible and then as visible.
+
+#import 
+#import 
+
+void bibi(void) {
+  Buffer buf;
+  buf.b = 1;
+}
Index: clang/test/Modules/merge-record-definition-nonmodular.m
===
--- /dev/null
+++ clang/test/Modules/merge-record-definition-nonmodular.m
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=RecordDef
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s -DMODULAR_BEFORE_TEXTUAL \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=RecordDef
+
+// Test a case when struct `Buffer` definition once is included from a textual header and once from a module.
+
+#ifdef MODULAR_BEFORE_TEXTUAL
+  #import 
+#else
+  #import 
+#endif
+
+void bibi(void) {
+  Buffer buf;
+  buf.b = 1;
+}
+
+#ifdef MODULAR_BEFORE_TEXTUAL
+  #import 
+#else
+  #import 
+#endif
+
+void mbap(void) {
+  Buffer buf;
+  buf.c = 2;
+}
Index: clang/test/Modules/Inputs/merge-record-definition/RecordDefIncluder.framework/Modules/module.modulemap
===
--- /dev/null
+++ 

[PATCH] D100713: [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr

2021-07-28 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert accepted this revision.
aaronpuchert added a comment.
This revision is now accepted and ready to land.

It is a good name!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100713

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


[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

2021-07-28 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:263
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt)
+<< A.getAsString(Args);

anjankgk wrote:
> ZarkoCA wrote:
> > nit, I prefer this error message but it's up to you. 
> I intentionally chose that error msg (without target mention) since that's 
> the one the original option threw (existing '-b' option which was defined as 
> unsupported for all the platforms).
I see, that makes sense.

But now with your patch this option is supported even if only for the AIX 
target. So we could make the case to use the suggested error message. That 
said, I am still fine with what you choose. 


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

https://reviews.llvm.org/D106688

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


[PATCH] D106790: prfchwintrin.h: Make _m_prefetchw take a pointer to volatile (PR49124)

2021-07-28 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

In D106790#2909567 , @hans wrote:

> I don't think that should cause any problems. Passing a less qualified 
> pointer to a more cv-qualified parameter should be fine, e.g.

OK, I'm happy then.




Comment at: clang/lib/Headers/prfchwintrin.h:54
+#pragma clang diagnostic ignored "-Wcast-qual"
+  __builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
+#pragma clang diagnostic pop

hans wrote:
> pengfei wrote:
> > Can we declare `__builtin_prefetch` to volatile one in Builtins.def:
> > ```
> > BUILTIN(__builtin_prefetch, "vvCD*.", "nc")
> > ```
> We could, and that would remove the need for the cast, but I'm not sure it 
> would make sense in itself. Since _m_prefetchw is the odd one here, I think 
> it makes sense to do the fix in its implementation.
I agree with @hans, I think leaving the prototype of `__builtin_prefetch` as it 
is seems reasonable, since it is used elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106790

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


[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

2021-07-28 Thread Anjan Kumar via Phabricator via cfe-commits
anjankgk added a comment.

Thank you reviewing Zarko!




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:263
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt)
+<< A.getAsString(Args);

ZarkoCA wrote:
> nit, I prefer this error message but it's up to you. 
I intentionally chose that error msg (without target mention) since that's the 
one the original option threw (existing '-b' option which was defined as 
unsupported for all the platforms).


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

https://reviews.llvm.org/D106688

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


[PATCH] D106688: [AIX] Pass the -b option to linker on AIX

2021-07-28 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA accepted this revision.
ZarkoCA added a comment.
This revision is now accepted and ready to land.

LGTM with small nit, thanks.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:263
+  if (!T.isOSAIX()) {
+TC.getDriver().Diag(diag::err_drv_unsupported_opt)
+<< A.getAsString(Args);

nit, I prefer this error message but it's up to you. 


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

https://reviews.llvm.org/D106688

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-07-28 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/CodeGen/X86/x86-fpclass.ll:173
+
+define <1 x i1> @isnan_double_vec1(<1 x double> %x) {
+; CHECK-32-LABEL: isnan_double_vec1:

add nounwind to reduce cfi noise (other tests would benefit as well)?



Comment at: llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll:1
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+

Use update_test_checks.py?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

2021-07-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a subscriber: tstellar.
mstorsjo added a comment.

@Meinersbur After landing this, can you coordinate with @tstellar to get an ack 
for backporting this to the 13.x release branch, which also suffers from the 
regression?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

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


[PATCH] D106732: Support macro deprecation #pragma clang deprecated

2021-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Lexer/deprecate-macro.c:34-39
+#ifdef foo
+#endif
+
+// expected-warning@+1{{macro 'foo' has been marked as deprecated}}
+#ifndef foo
+#endif

Some more test cases to add:
```
// Test that we diagnose on #elifdef.
#ifdef baz
#elifdef foo // expected-warning
#endif

// Test that we diagnose on #elifndef.
#ifdef baz
#elifndef foo // expected-warning
#endif

// Test that we diagnose both the taken branch and the skipped branch.
#ifdef foo // expected-warning
#elifdef bar // expected-warning
#endif
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106732

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


[PATCH] D106925: COFF/ELF: Place llvm.global_ctors elements in llvm.used if comdat is used

2021-07-28 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG828767f325b5: COFF/ELF: Place llvm.global_ctors elements in 
llvm.used if comdat is used (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106925

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
  clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp


Index: clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
===
--- clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
+++ clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
@@ -1,5 +1,20 @@
 // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-pc-linux -emit-llvm -o - | 
FileCheck --check-prefix=ELF --check-prefix=ALL %s
 // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-apple-darwin -emit-llvm -o - | 
FileCheck --check-prefix=MACHO --check-prefix=ALL %s
+// RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-pc-linux -emit-llvm -fdeclspec 
-DSELECTANY -o - | FileCheck --check-prefix=ELF-SELECTANY %s
+
+#ifdef SELECTANY
+struct S {
+  S();
+  ~S();
+};
+
+int f();
+
+// ELF-SELECTANY: @llvm.global_ctors = appending global [1 x { i32, void ()*, 
i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init, 
i8* bitcast (i32* @selectany to i8*) }]
+// ELF-SELECTANY: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* 
@selectany to i8*)]
+int __declspec(selectany) selectany = f();
+
+#else
 
 // ALL: ; ModuleID
 
@@ -38,6 +53,9 @@
 
 // ALL:  { i32, void ()*, i8* } { i32 65535, void ()* 
@_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp, i8* null }]
 
+/// llvm.used ensures SHT_INIT_ARRAY in a section group cannot be GCed.
+// ELF: @llvm.used = appending global [6 x i8*] [i8* bitcast (i32* 
@_ZN1AIsE1aE to i8*), i8* bitcast (i16* @_Z1xIsE to i8*), i8* bitcast (i32* 
@_ZN2ns1aIiE1iE to i8*), i8* bitcast (i32* @_ZN2ns1b1iIiEE to i8*), i8* bitcast 
(i32* @_ZN1AIvE1aE to i8*), i8* @_Z1xIcE]
+
 template int A::a;  // Unordered
 int b = foo();
 int c = foo();
@@ -76,6 +94,8 @@
 }
 int *use_internal_a = ::a;
 
+#endif
+
 // ALL: define internal void @[[unordered1]](
 // ALL: call i32 @foo()
 // ALL: store {{.*}} @_ZN1AIsE1aE
Index: clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
@@ -88,5 +88,4 @@
 inline int zoo = foo();
 inline static int boo = foo();
 
-
-// CHECK: @llvm.used = appending global [7 x i8*] [i8* bitcast (i32* 
@"?x1@selectany_init@@3HA" to i8*), i8* bitcast (i32* 
@"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*), i8* bitcast (i32* 
@"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds (%struct.A, %struct.A* 
@"?aoo@S1@@2UA@@A", i32 0, i32 0), i8* bitcast (i32* @"?zoo@@3HA" to i8*), i8* 
getelementptr inbounds (%struct.S, %struct.S* 
@"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section 
"llvm.metadata"
+// CHECK: @llvm.used = appending global [8 x i8*] [i8* bitcast (i32* 
@"?x@selectany_init@@3HA" to i8*), i8* bitcast (i32* @"?x1@selectany_init@@3HA" 
to i8*), i8* bitcast (i32* @"?x@?$A@H@explicit_template_instantiation@@2HA" to 
i8*), i8* bitcast (i32* @"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds 
(%struct.A, %struct.A* @"?aoo@S1@@2UA@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?zoo@@3HA" to i8*), i8* getelementptr inbounds (%struct.S, %struct.S* 
@"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section 
"llvm.metadata"
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -555,7 +555,8 @@
   PrioritizedCXXGlobalInits.size());
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
   } else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
- getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR) {
+ getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR ||
+ D->hasAttr()) {
 // C++ [basic.start.init]p2:
 //   Definitions of explicitly specialized class template static data
 //   members have ordered initialization. Other class template static data
@@ -568,17 +569,18 @@
 // group with the global being initialized.  On most platforms, this is a
 // minor startup time optimization.  In the MS C++ ABI, there are no guard
 // variables, so this COMDAT key is required for 

[clang] 828767f - COFF/ELF: Place llvm.global_ctors elements in llvm.used if comdat is used

2021-07-28 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-07-28T11:44:19-07:00
New Revision: 828767f325b5dd0356c5fd90e40a1c047010853e

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

LOG: COFF/ELF: Place llvm.global_ctors elements in llvm.used if comdat is used

On ELF, an SHT_INIT_ARRAY outside a section group is a GC root. The current
codegen abuses SHT_INIT_ARRAY in a section group to mean a GC root.

On PE/COFF, the dynamic initialization for `__declspec(selectany)` in a comdat
can be garbage collected by `-opt:ref`.

Call `addUsedGlobal` for the two cases to fix the abuse/bug.

Reviewed By: rnk

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

Added: 


Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index d43fb99550a85..553fedebfe56b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -555,7 +555,8 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl 
*D,
   PrioritizedCXXGlobalInits.size());
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
   } else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
- getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR) {
+ getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR ||
+ D->hasAttr()) {
 // C++ [basic.start.init]p2:
 //   Definitions of explicitly specialized class template static data
 //   members have ordered initialization. Other class template static data
@@ -568,17 +569,18 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl 
*D,
 // group with the global being initialized.  On most platforms, this is a
 // minor startup time optimization.  In the MS C++ ABI, there are no guard
 // variables, so this COMDAT key is required for correctness.
-AddGlobalCtor(Fn, 65535, COMDATKey);
-if (getTarget().getCXXABI().isMicrosoft() && COMDATKey) {
-  // In The MS C++, MS add template static data member in the linker
-  // drective.
-  addUsedGlobal(COMDATKey);
-}
-  } else if (D->hasAttr()) {
+//
 // SelectAny globals will be comdat-folded. Put the initializer into a
 // COMDAT group associated with the global, so the initializers get folded
 // too.
+
 AddGlobalCtor(Fn, 65535, COMDATKey);
+if (COMDATKey && (getTriple().isOSBinFormatELF() ||
+  getTarget().getCXXABI().isMicrosoft())) {
+  // When COMDAT is used on ELF or in the MS C++ ABI, the key must be in
+  // llvm.used to prevent linker GC.
+  addUsedGlobal(COMDATKey);
+}
   } else {
 I = DelayedCXXInitPosition.find(D); // Re-do lookup in case of re-hash.
 if (I == DelayedCXXInitPosition.end()) {

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
index 3b419c18c0e23..d8d0ed3950803 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
@@ -88,5 +88,4 @@ int foo();
 inline int zoo = foo();
 inline static int boo = foo();
 
-
-// CHECK: @llvm.used = appending global [7 x i8*] [i8* bitcast (i32* 
@"?x1@selectany_init@@3HA" to i8*), i8* bitcast (i32* 
@"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*), i8* bitcast (i32* 
@"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds (%struct.A, %struct.A* 
@"?aoo@S1@@2UA@@A", i32 0, i32 0), i8* bitcast (i32* @"?zoo@@3HA" to i8*), i8* 
getelementptr inbounds (%struct.S, %struct.S* 
@"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section 
"llvm.metadata"
+// CHECK: @llvm.used = appending global [8 x i8*] [i8* bitcast (i32* 
@"?x@selectany_init@@3HA" to i8*), i8* bitcast (i32* @"?x1@selectany_init@@3HA" 
to i8*), i8* bitcast (i32* @"?x@?$A@H@explicit_template_instantiation@@2HA" to 
i8*), i8* bitcast (i32* @"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds 
(%struct.A, %struct.A* @"?aoo@S1@@2UA@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?zoo@@3HA" to i8*), i8* getelementptr inbounds (%struct.S, %struct.S* 
@"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section 
"llvm.metadata"

diff  --git 
a/clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp 
b/clang/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
index 2bd01b301e522..13323e7efe79c 100644
--- 

[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

They are used here:
https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/malloc_common.h;l=54;drc=f3968e89cb72400951f93a2a8237ac1428d2627c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D106898: Revert "Revert "[clang][pp] adds '#pragma include_instead'""

2021-07-28 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 362479.
cjdb added a comment.

- attempts to get CI passing (@aaron.ballman)
- minimises test case (@hans)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106898

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorLexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/PCH/ms-pch-macro-include_instead-regression.c
  clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
  clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
  clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
  clang/test/Preprocessor/Inputs/include_instead/private-x.h
  clang/test/Preprocessor/Inputs/include_instead/private1.h
  clang/test/Preprocessor/Inputs/include_instead/private2.h
  clang/test/Preprocessor/Inputs/include_instead/private3.h
  clang/test/Preprocessor/Inputs/include_instead/public-after.h
  clang/test/Preprocessor/Inputs/include_instead/public-before.h
  clang/test/Preprocessor/Inputs/include_instead/public-empty.h
  clang/test/Preprocessor/include_instead.cpp
  clang/test/Preprocessor/include_instead_file_not_found.cpp

Index: clang/test/Preprocessor/include_instead_file_not_found.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/include_instead_file_not_found.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -I %S/Inputs %s
+#include 
Index: clang/test/Preprocessor/include_instead.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/include_instead.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -I %S/Inputs %s
+
+#include 
+#include 
+
+#include 
+// expected-error@-1{{header '' is an implementation detail; #include '' instead}}
+
+#include "include_instead/private2.h"
+// expected-error@-1{{header '"include_instead/private2.h"' is an implementation detail; #include either '' or '"include_instead/public-after.h"' instead}}
+
+#include 
+// expected-error@-1{{header '' is an implementation detail; #include one of {'', '', '"include_instead/public-before.h"'} instead}}
+
+#include 
+#include 
Index: clang/test/Preprocessor/Inputs/include_instead/public-empty.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/public-empty.h
@@ -0,0 +1 @@
+// This file simply needs to exist.
Index: clang/test/Preprocessor/Inputs/include_instead/public-before.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/public-before.h
@@ -0,0 +1,5 @@
+#pragma GCC system_header
+
+#include  // no warning expected
+#include  // no warning expected
+#include  // no warning expected
Index: clang/test/Preprocessor/Inputs/include_instead/public-after.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/public-after.h
@@ -0,0 +1,2 @@
+#include 
+#pragma GCC system_header
Index: clang/test/Preprocessor/Inputs/include_instead/private3.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/private3.h
@@ -0,0 +1,5 @@
+#pragma GCC system_header
+
+#pragma clang include_instead()
+#pragma clang include_instead()
+#pragma clang include_instead("include_instead/public-before.h")
Index: clang/test/Preprocessor/Inputs/include_instead/private2.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/private2.h
@@ -0,0 +1,4 @@
+#pragma GCC system_header
+
+#pragma clang include_instead()
+#pragma clang include_instead("include_instead/public-after.h")
Index: clang/test/Preprocessor/Inputs/include_instead/private1.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/private1.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+#pragma clang include_instead()
Index: clang/test/Preprocessor/Inputs/include_instead/private-x.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/private-x.h
@@ -0,0 +1,4 @@
+#include 
+
+#pragma GCC system_header
+#pragma clang include_instead()
Index: clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
===
--- /dev/null
+++ clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
@@ -0,0 +1,2 @@
+#pragma clang include_instead()
+// expected-error@-1{{'#pragma clang include_instead' cannot be 

[PATCH] D105191: [Clang][OpenMP] Add support for Static Device Libraries

2021-07-28 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

Do I must use llvm-ar/ranlib  or system ar/ranlib is OK?

1. existing use case breaks

Use https://github.com/ye-luo/openmp-target/blob/master/tests/math/modf.cpp
$ clang++ -fopenmp -fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 
-march=sm_80 modf.cpp  # still OK
$ clang++ -fopenmp -fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 
-march=sm_80 modf.o 
clang-14: warning: Unknown CUDA version. version.txt: 11.0.228. Assuming the 
latest supported version 10.1 [-Wunknown-cuda-version]
nvlink fatal   : Could not open input file '/tmp/modf-0bf89b.cubin'
clang-14: error: nvlink command failed with exit code 1 (use -v to see 
invocation)

2. could you make my test case working?

https://github.com/ye-luo/openmp-target/tree/master/tests/link_static_fat_bin
both compile-amd.sh and compile.sh doesn't work for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105191

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


[PATCH] D99381: [compiler-rt][hwasan] Remove __sanitizer allocation functions from hwasan interface

2021-07-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D99381#2908102 , @vitalybuka wrote:

> @eugenis Why do we have them in here and in sanitizer/hwasan_interface.h ?

And if we don't need them in sanitizer/hwasan_interface.h  and 
interface_internal, 
SANITIZER_INTERFACE_ATTRIBUTE

I can't find any callers  other then 
compiler-rt/test/hwasan/TestCases/sanitizer_malloc.cpp
Could we remove these functions (including implementation)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[PATCH] D106674: Runtime for Interop directive

2021-07-28 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: openmp/libomptarget/src/interop.cpp:13
+static omp_interop_rc_t
+__kmpc_interop_get_property_err_type(omp_interop_property_t property) {
+  switch (property) {

tianshilei1992 wrote:
> There are some conventions in current `libomptarget`.
> 1. If a function is internal, use LLVM code style.
> 2. If a function is exported and exposed to compiler, it should be `extern 
> "C"` and use code style similar to existing functions whose name prefix with 
> `__tgt`.
> 
> So basically, if these functions are only visible to this file, please format 
> it with LLVM code style, and use anonymous name space.
I mean, this function doesn't have to start with `__tgt` because it is 
internal. Functions starting with `__tgt` are usually interface functions. From 
my perspective, it is better to name it as `getPropertyErrorType`, a.k.a. to 
use LLVM code style.



Comment at: openmp/libomptarget/src/interop.cpp:63
+template 
+PropertyTy __tgt_interop_get_property(omp_interop_val_t _val,
+  omp_interop_property_t property,

Same here



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1501
+return (*fptr)(interop);
+  } else { // liboffload & libomptarget don't exist
+return 0;

ditto



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1515
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return 0;

ditto



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1527
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return (void *)0;

ditto



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1539
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return (const char *)0;

ditto



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1550
+return (*fptr)(interop, property_id);
+  } else { // liboffload & libomptarget don't exist
+return (const char *)0;

same as below



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1561
+return (*fptr)(interop, property_id);
+  } else { // liboffload & libomptarget don't exist
+return (const char *)0;

same as below



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1570-1574
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_rec_desc"))) {
+return (*fptr)(interop, property_id);
+  } else { // liboffload & libomptarget don't exist
+return (const char *)0;
+  }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106674

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


[PATCH] D106974: libcang: Add missing function to libclang.map

2021-07-28 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 accepted this revision.
jrtc27 added a comment.
This revision is now accepted and ready to land.

Thanks; I can confirm the test passes if and only if I apply this patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106974

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


[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-07-28 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a subscriber: rjmccall.
Anastasia added a comment.

The patch looks good but I would like to check with @rjmccall whether it would 
make sense to add this functionality generically for C/C++ too just like 
`__remove_const` and other builtins proposed in https://reviews.llvm.org/D67052?


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

https://reviews.llvm.org/D106785

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


[clang] 71f0359 - Simplify allowing pragma float_control in a linkage specification

2021-07-28 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-07-28T13:29:41-04:00
New Revision: 71f0359a9defbf3e35828189629f166508390d5d

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

LOG: Simplify allowing pragma float_control in a linkage specification

This amends b0ef3d8f666fa6008abb09340b73d9340d442569 based on a suggestion from 
James Y Knight.

Added: 


Modified: 
clang/lib/Sema/SemaAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index b58c092f21e0..c19b44989b5f 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -475,8 +475,7 @@ void Sema::ActOnPragmaFloatControl(SourceLocation Loc,
PragmaFloatControlKind Value) {
   FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
   if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
-  !(CurContext->isTranslationUnit()) && !CurContext->isNamespace() &&
-  !isa(CurContext)) {
+  !CurContext->getRedeclContext()->isFileContext()) {
 // Push and pop can only occur at file or namespace scope, or within a
 // language linkage declaration.
 Diag(Loc, diag::err_pragma_fc_pp_scope);



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


[PATCH] D106755: Extended format string checking to wprintf/wscanf

2021-07-28 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 362446.

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

https://reviews.llvm.org/D106755

Files:
  clang-tools-extra/clang-tidy/boost/UseToStringCheck.cpp
  clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/FormatString.h
  clang/include/clang/AST/Type.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/OSLog.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaFixItUtils.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/test/Sema/format-strings-c90.c
  clang/test/Sema/format-strings-darwin.c
  clang/test/Sema/format-strings-int-typedefs.c
  clang/test/Sema/format-strings-ms.c
  clang/test/Sema/format-strings-non-iso.c
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/string-plus-char.c
  clang/test/SemaCXX/format-strings-0x.cpp
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -8,6 +8,9 @@
 extern int scanf(const char *restrict, ...);
 extern int printf(const char *restrict, ...);
 extern int vprintf(const char *restrict, va_list);
+extern int wscanf(const wchar_t *restrict, ...);
+extern int wprintf(const wchar_t *restrict, ...);
+extern int vwprintf(const wchar_t *restrict, va_list);
 }
 
 void f(char **sp, float *fp) {
@@ -18,12 +21,23 @@
   // expected-warning@-4 {{format specifies type 'float *' but the argument has type 'char **'}}
 #endif
 
+  scanf("%as", sp);
+#if __cplusplus <= 199711L
+  // expected-warning@-2 {{'a' length modifier is not supported by ISO C}}
+#else
+  // expected-warning@-4 {{format specifies type 'float *' but the argument has type 'wchar_t **'}}
+#endif
+
   printf("%a", 1.0);
   scanf("%afoobar", fp);
+
+  wprintf("%a", 1.0);
+  wscanf("%afoobar", fp);
 }
 
 void g() {
   printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
+  wprintf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
 }
 
 // Test that we properly handle format_idx on C++ members.
Index: clang/test/SemaCXX/format-strings-0x.cpp
===
--- clang/test/SemaCXX/format-strings-0x.cpp
+++ clang/test/SemaCXX/format-strings-0x.cpp
@@ -3,33 +3,53 @@
 extern "C" {
 extern int scanf(const char *restrict, ...);
 extern int printf(const char *restrict, ...);
+extern int wscanf(const wchar_t *restrict, ...);
 }
 
 void f(char **sp, float *fp) {
   scanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}}
+  wscanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'wchar_t **'}}
 
   printf("%p", sp); // expected-warning{{format specifies type 'void *' but the argument has type 'char **'}}
+  wprintf("%p", sp); // expected-warning{{format specifies type 'void *' but the argument has type 'wchar_t **'}}
   scanf("%p", sp);  // expected-warning{{format specifies type 'void **' but the argument has type 'char **'}}
+  wscanf("%p", sp); // expected-warning{{format specifies type 'void **' but the argument has type 'wchar_t **'}}
 
   printf("%a", 1.0);
   scanf("%afoobar", fp);
+  wprintf("%a", 1.0);
+  wscanf("%afoobar", fp);
   printf(nullptr);
   printf(*sp); // expected-warning {{not a string literal}}
   // expected-note@-1{{treat the string as an argument to avoid this}}
+  wprintf(*sp); // expected-warning {{not a string literal}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
 
   // PR13099
   printf(
 R"foobar(%)foobar"
 R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}}
 R"xyzzy()xyzzy");
+  wprintf(
+  R"foobar(%)foobar"
+  R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}}
+  R"xyzzy()xyzzy");
 
   printf(u8"this is %d test", 0); // ok
+  wprintf(u8"this is %d test", 0); // ok
   printf(u8R"foo(
   \u1234\U0010fffe
   %d)foo" // expected-warning {{more '%' conversions than data arguments}}
   );
+  wprintf(u8R"foo(
+  \u1234\U0010fffe
+  %d)foo" // expected-warning {{more '%' conversions than data arguments}}

[PATCH] D106899: [LLVM][NFC] Remove LLVM_ATTRIBUTE_NORETURN and use [[noreturn]] directly

2021-07-28 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit added a comment.

In D106899#2910655 , @MaskRay wrote:

> I migrated all llvm/ files. You need to remove them from the patch.
>
> It is a good idea to drop the macro definition in 
> `llvm/include/llvm/Support/Compiler.h` separately.
>
> It makes it easy to bring back the definition if some important downstream 
> users want extended time for migration.
> (Note: the policy is that downstream is on their own. Our thinking of this is 
> kindness, not an obligation of llvm-project.)
> For example, swift is using `LLVM_ATTRIBUTE_NORETURN`.
> (I researched a bit: `LLVM_ATTRIBUTE_NORETURN` is not common in downstream 
> projects.)

Alright, but can we cherry pick this to release when this is all said and done?


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

https://reviews.llvm.org/D106899

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


[PATCH] D106899: [LLVM][NFC] Remove LLVM_ATTRIBUTE_NORETURN and use [[noreturn]] directly

2021-07-28 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 362437.
gAlfonso-bit added a comment.

Rebased


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

https://reviews.llvm.org/D106899

Files:
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  flang/include/flang/Optimizer/Support/FatalError.h
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
  lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
  llvm/include/llvm/Support/Compiler.h


Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -242,7 +242,14 @@
 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
 #endif
 
-#ifdef __GNUC__
+// C++14 and up has [[noreturn]]
+#if defined(__cplusplus) && __cplusplus > 201300 &&
\
+LLVM_HAS_CPP_ATTRIBUTE(noreturn)
+#define LLVM_ATTRIBUTE_NORETURN [[noreturn]]
+// C11 and up has _Noreturn
+#elif !defined(__cplusplus) && __STDC_VERSION__ > 201112L
+#define LLVM_ATTRIBUTE_NORETURN _Noreturn
+#elif defined(__GNUC__) || __has_attribute(noreturn)
 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
 #elif defined(_MSC_VER)
 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
Index: lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
===
--- lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
+++ lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
@@ -29,7 +29,7 @@
 #if defined(__arm64__) || defined(__aarch64__)
 namespace {
 
-void LLVM_ATTRIBUTE_NORETURN Child() {
+[[noreturn]] void Child() {
   if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
 _exit(1);
 
Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -46,8 +46,7 @@
 #endif
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ExitWithError(int error_fd,
-  const char *operation) {
+[[noreturn]] static void ExitWithError(int error_fd, const char *operation) {
   int err = errno;
   llvm::raw_fd_ostream os(error_fd, true);
   os << operation << " failed: " << llvm::sys::StrError(err);
@@ -88,7 +87,7 @@
   return;
 }
 
-static void LLVM_ATTRIBUTE_NORETURN ChildFunc(int error_fd,
+[[noreturn]] static void ChildFunc(int error_fd,
   const ProcessLaunchInfo ) {
   if (info.GetFlags().Test(eLaunchFlagLaunchInSeparateProcessGroup)) {
 if (setpgid(0, 0) != 0)
Index: flang/include/flang/Optimizer/Support/FatalError.h
===
--- flang/include/flang/Optimizer/Support/FatalError.h
+++ flang/include/flang/Optimizer/Support/FatalError.h
@@ -20,8 +20,8 @@
 
 /// Fatal error reporting helper. Report a fatal error with a source location
 /// and immediately abort flang.
-LLVM_ATTRIBUTE_NORETURN inline void emitFatalError(mlir::Location loc,
-   const llvm::Twine ) 
{
+[[noreturn]] inline void emitFatalError(mlir::Location loc,
+const llvm::Twine ) {
   mlir::emitError(loc, message);
   llvm::report_fatal_error("aborting");
 }
Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -614,7 +614,7 @@
 return It->second.Root;
   }
 
-  LLVM_ATTRIBUTE_NORETURN void PrintFatalError(llvm::Twine const ) const {
+  [[noreturn]] void PrintFatalError(llvm::Twine const ) const {
 assert(EvaluatingRecord && "not evaluating a record?");
 llvm::PrintFatalError(EvaluatingRecord->getLoc(), Msg);
   }
Index: clang-tools-extra/pp-trace/PPTrace.cpp
===
--- clang-tools-extra/pp-trace/PPTrace.cpp
+++ clang-tools-extra/pp-trace/PPTrace.cpp
@@ -69,7 +69,7 @@
 cl::desc("Output trace to the given file name or '-' for stdout."),
 cl::cat(Cat));
 
-LLVM_ATTRIBUTE_NORETURN static void error(Twine Message) {
+[[noreturn]] static void error(Twine Message) {
   WithColor::error() << Message << '\n';
   exit(1);
 }


Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -242,7 +242,14 @@
 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
 #endif
 
-#ifdef __GNUC__
+// C++14 and up has [[noreturn]]
+#if defined(__cplusplus) && __cplusplus > 201300 &&\
+LLVM_HAS_CPP_ATTRIBUTE(noreturn)
+#define LLVM_ATTRIBUTE_NORETURN [[noreturn]]
+// C11 and up has _Noreturn
+#elif 

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-07-28 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 362433.
gandhi21299 added a comment.

- added more tests with supported combinations of address spaces
- minor nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-fp-atomics.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics.cl
@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_add
+// GFX90A:  global_atomic_add_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_add(__global double *addr, double x) {
+  __builtin_amdgcn_global_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_constant_add
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fadd.f64.p4f64.f64(double addrspace(4)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_constant_add
+// GFX90A:  global_atomic_add_f64 v2, v[0:1], s[0:1]
+// GFX90A:  s_endpgm
+kernel void test_global_constant_add(__constant double *addr, double x) {
+  __builtin_amdgcn_global_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_local_add
+// CHECK: tail call double @llvm.amdgcn.global.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_global_local_add
+// GFX90A:  ds_add_f64
+// GFX90A:  s_endpgm
+kernel void test_global_local_add(__local double *addr, double x) {
+  __builtin_amdgcn_global_atomic_fadd_f64(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_addf
+// CHECK: tail call float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* %{{.*}}, float %{{.*}})
+// GFX90A-LABEL: test_global_addf
+// GFX90A: global_atomic_add_f32 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_addf(__global float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_constant_addf
+// CHECK: tail call float @llvm.amdgcn.global.atomic.fadd.f32.p4f32.f32(float addrspace(4)* %{{.*}}, float %{{.*}})
+// GFX90A-LABEL: test_global_constant_addf
+// GFX90A: global_atomic_add_f32 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_constant_addf(__constant float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_local_addf
+// CHECK: tail call float @llvm.amdgcn.global.atomic.fadd.f32.p3f32.f32(float addrspace(3)* %{{.*}}, float %{{.*}})
+// GFX90A-LABEL: test_global_local_addf
+// GFX90A: ds_add_f32
+// GFX90A: s_endpgm
+kernel void test_global_local_addf(__local float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_add2h
+// CHECK: tail call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1v2f16.v2f16(<2 x half> addrspace(1)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL: test_global_add2h
+// GFX90A: global_atomic_pk_add_f16 v0, v1, s[0:1]
+// GFX90A: s_endpgm
+kernel void test_global_add2h(__global half2 *addr, half2 x){
+  __builtin_amdgcn_global_atomic_fadd_2f16(addr, x, memory_order_relaxed);
+}
+
+// CHECK-LABEL: test_global_constant_add2h
+// CHECK: tail call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p4v2f16.v2f16(<2 x half> addrspace(4)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL: test_global_constant_add2h
+// GFX90A: global_atomic_pk_add_f16
+kernel void test_global_constant_add2h(__constant half2 *addr, half2 x){
+  __builtin_amdgcn_global_atomic_fadd_2f16(addr, x, memory_order_relaxed);
+}
+
+// CaHECK-LABEL: test_global_local_add2h
+// CHaECK: tail call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p3v2f16.v2f16(<2 x half> addrspace(3)* %{{.*}}, <2 x half> %{{.*}})
+// kernel void test_global_local_add2h(__local half2 *addr, half2 x){
+//   __builtin_amdgcn_global_atomic_fadd_2f16(addr, x, memory_order_relaxed); // expected-error{{fatal error: error in backend: Cannot select: t22: v2f16,ch = AtomicLoadFAdd<(volatile 

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-07-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D104854#2905430 , @efriedma wrote:

> In D104854#2904826 , @sepavloff 
> wrote:
>
>> In D104854#2886328 , @efriedma 
>> wrote:
>>
 The options '-ffast-math' and '-fno-honor-nans' imply that FP operation
 operands are never NaNs. This assumption however should not be applied
 to the functions that check FP number properties, including 'isnan'. If
 such function returns expected result instead of actually making
 checks, it becomes useless in many cases.
>>>
>>> This doesn't work the way you want it to, at least given the way nnan/ninf 
>>> are currently defined in LangRef.  It's possible to end up in a situation 
>>> where `isnan(x) == isnan(x)` evaluates to false at runtime.  It doesn't 
>>> matter how you compute isnan; the problem is that the input is poisoned.
>>>
>>> I think the right solution to this sort of issue is to insert a "freeze" in 
>>> the LLVM IR, or something like that.  Not sure how we'd expect users to 
>>> write this in C.  Suggestions welcome.
>>
>> According to the documentation, nnan/ninf may be applied to `fneg`, `fadd`, 
>> `fsub`, `fmul`, `fdiv`, `frem`, `fcmp`, `phi`, `select` and `call`. We can 
>> ignore this flag for calls of isnan and similar functions. Of course, if 
>> conditions of using `-ffast-math` are broken, we have undefined behavior and 
>> `isnan(x) != isnan(x)` becomes possible, like in this code:
>
> Right... so how can you produce a NaN in these circumstances?  You could load 
> one from memory, I guess?

Yes, they come from structures in memory. I think they can also come from 
function arguments, if some source files are compiled with option `-ffast-math` 
and some without.

> It would probably be a good idea to have an instcombine that combines away 
> isnan on a value produced by an operation marked nnan, so we don't confuse 
> people reading assembly into assuming isnan is actually reliable in that 
> context.

Added such transformation (file 
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp, test in 
llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D106756: Added l16/l32 length modifiers for char16_t/char32_t

2021-07-28 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 362444.
MarcusJohnson91 added a comment.

Added a couple tests


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

https://reviews.llvm.org/D106756

Files:
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/test/Sema/format-strings-int-typedefs.c
  clang/test/SemaCXX/format-strings.cpp

Index: clang/test/SemaCXX/format-strings.cpp
===
--- clang/test/SemaCXX/format-strings.cpp
+++ clang/test/SemaCXX/format-strings.cpp
@@ -24,6 +24,8 @@
 
 void g() {
   printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
+  printf("%l16s", "foo"); // expected-warning{{format specifies type 'char16_t *' but the argument has type 'const char *'}}
+  printf("%l32s", "foo"); // expected-warning{{format specifies type 'char32_t *' but the argument has type 'const char *'}}
 }
 
 // Test that we properly handle format_idx on C++ members.
Index: clang/test/Sema/format-strings-int-typedefs.c
===
--- clang/test/Sema/format-strings-int-typedefs.c
+++ clang/test/Sema/format-strings-int-typedefs.c
@@ -10,8 +10,17 @@
   printf("%td", 42.0); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'int')}}
   printf("%lc", 42.0); // expected-warning {{format specifies type 'wint_t' (aka 'int')}}
   printf("%ls", 42.0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+  printf("%l16c", 42.0); // expected-warning {{format specifies type 'char16_t' (aka 'int')}}
+  printf("%l16s", 42.0); // expected-warning {{format specifies type 'char16_t *' (aka 'int *')}}
+  printf("%l32c", 42.0); // expected-warning {{format specifies type 'char32_t' (aka 'int')}}
+  printf("%l32s", 42.0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
   printf("%S", 42.0);  // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
   printf("%C", 42.0);  // expected-warning {{format specifies type 'wchar_t' (aka 'int')}}
+  
+  wprintf(L"%l16c", 42.0); // expected-warning {{format specifies type 'char16_t' (aka 'short')}}
+  wprintf(L"%l16s", 42.0); // expected-warning {{format specifies type 'char16_t *' (aka 'short *')}}
+  wprintf(L"%l32c", 42.0); // expected-warning {{format specifies type 'char32_t' (aka 'int')}}
+  wprintf(L"%l32s", 42.0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
 
   scanf("%jd", 0); // expected-warning {{format specifies type 'intmax_t *' (aka 'long long *')}}
   scanf("%ju", 0); // expected-warning {{format specifies type 'uintmax_t *' (aka 'unsigned long long *')}}
@@ -19,8 +28,17 @@
   scanf("%td", 0); // expected-warning {{format specifies type 'ptrdiff_t *' (aka 'int *')}}
   scanf("%lc", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
   scanf("%ls", 0); // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+  scanf("%l16c", 0); // expected-warning {{format specifies type 'char16_t *' (aka 'int *')}}
+  scanf("%l16s", 0); // expected-warning {{format specifies type 'char16_t *' (aka 'int *')}}
+  scanf("%l32c", 0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
+  scanf("%l32s", 0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
   scanf("%S",  0);  // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
   scanf("%C",  0);  // expected-warning {{format specifies type 'wchar_t *' (aka 'int *')}}
+  
+  wscanf("%l16c", 0); // expected-warning {{format specifies type 'char16_t *' (aka 'int *')}}
+  wscanf("%l16s", 0); // expected-warning {{format specifies type 'char16_t *' (aka 'int *')}}
+  wscanf("%l32c", 0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
+  wscanf("%l32s", 0); // expected-warning {{format specifies type 'char32_t *' (aka 'int *')}}
 
 
   // typedef size_t et al. to something crazy.
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -520,6 +520,12 @@
 case WCStrTy:
   Res = C.getPointerType(C.getWideCharType());
   break;
+case Char16Ty:
+  Res = C.getPointerType(C.getChar16Type());
+  break;
+case Char32Ty:
+  Res = C.getPointerType(C.getChar32Type());
+  break;
 case ObjCPointerTy:
   Res = C.ObjCBuiltinIdTy;
   break;
@@ -607,6 +613,10 @@
 return "m";
   case AsWide:
 return "w";
+  case AsUTF16:
+return "l16";
+  case AsUTF32:
+return "l32";
   case None:
 return "";
   }
@@ -860,6 +870,17 @@
 default:
   return false;
   }
+case LengthModifier::AsUTF16:
+case LengthModifier::AsUTF32:
+  switch (CS.getKind()) {
+  case ConversionSpecifier::cArg:
+  case 

[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

2021-07-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D106394#2910571 , @cjdb wrote:

> In D106394#2905660 , @dblaikie 
> wrote:
>
>> Just a thought (nothing to hold up this patch/suggest a revert/suggest any 
>> immediate action), but:
>>
>>> The problem with extending this to non-system headers is that you need a 
>>> way to tell which headers are allowed to include the detail headers and 
>>> which ones are not.
>>
>> What if the analysis was done on the entire #include path from the current 
>> primary source file - rather than from the immediate include location? Then 
>> the requirement could be "This header must be directly or indirectly 
>> included from one of the headers listed in include_instead, otherwise there 
>> will be a warning" - could that generalize to other use cases/not only 
>> system headers?
>
> I think this would mean that something like libc++'s `<__ranges/concepts.h>` 
> couldn't directly include `<__iterator/concepts.h>`?

Ah, I think I follow what you're getting at - I think you're suggesting that 
the include_insteads are not intended to be exhaustive? (they're not all the 
ways you might get these declarations by including public headers - they are 
only meant to enumerate the public/intended entry points to these declarations)

So despite the fact that `ranges` indirectly includes `__iterator/concepts .h`, 
you wouldn't want to tell the user that they could include `ranges` to get the 
declarations in `__iterator/concepts.h` ?

Because `__iterator/concepts.h` is only needed as an implementation detail of 
`ranges`, not as part of its public interface? Fair enough.

Pity - if the enumeration of public headers that can indirectly include an 
implementation header was complete, then that would be sufficient to implement 
a warning without needing the system header detection, I think? So one option 
would be to annotate the include_instead with "implementation detail" V "public 
interface" bit/distinction and that would work instead of the system header 
detection? But I guess that'd be left to another project/further work to 
generalize this feature.

> Also, how does this play with `#pragma GCC system_header` detection?

I don't think my suggestion would have anything to do with system header 
detection, so far as I can think of - could you describe this concern in more 
detail?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106394

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


[PATCH] D106974: libcang: Add missing function to libclang.map

2021-07-28 Thread Tom Stellard via Phabricator via cfe-commits
tstellar updated this revision to Diff 362439.
tstellar added a comment.

Add missing ;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106974

Files:
  clang/tools/libclang/libclang.map


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources;
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources;
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105527: libclang.so: Make SONAME independent from LLVM version

2021-07-28 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

Can you let me know if D106974  fixes the 
problem?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105527

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


[PATCH] D106974: libcang: Add missing function to libclang.map

2021-07-28 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
tstellar added a reviewer: jrtc27.
tstellar requested review of this revision.
Herald added a project: clang.

This function is marked with CINDEX_LINKAGE, but was never added to the
export list / linker script.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106974

Files:
  clang/tools/libclang/libclang.map


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -49,6 +49,7 @@
 clang_CompileCommand_getMappedSourceContent;
 clang_CompileCommand_getMappedSourcePath;
 clang_CompileCommand_getNumArgs;
+clang_CompileCommand_getNumMappedSources
 clang_CompileCommands_dispose;
 clang_CompileCommands_getCommand;
 clang_CompileCommands_getSize;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106924

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


[PATCH] D106431: [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum FixIt, and add support for initialization check of scoped enum.

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

LGTM -- it's not the cleanest solution (we're duplicating the call to 
`diag()`), but it'll suffice. If we wanted to clean it up a bit, we could use 
an `llvm::Optional Diagnose  = llvm::None;` where a non-`None` 
value means "diagnose" and if the stored pointer value is not null, it 
additionally adds the fixit information.


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

https://reviews.llvm.org/D106431

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


[PATCH] D106753: ConvertUTF: Created wrapper convertUTF32ToUTF8String

2021-07-28 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 updated this revision to Diff 362431.
MarcusJohnson91 added a comment.

Updated the tests


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

https://reviews.llvm.org/D106753

Files:
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTFWrapper.cpp
  llvm/unittests/Support/ConvertUTFTest.cpp

Index: llvm/unittests/Support/ConvertUTFTest.cpp
===
--- llvm/unittests/Support/ConvertUTFTest.cpp
+++ llvm/unittests/Support/ConvertUTFTest.cpp
@@ -36,6 +36,28 @@
   EXPECT_EQ(Expected, Result);
 }
 
+TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xA0\x0C\x00\x00_\xA0\x0C\x00\x00";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\x00\x00\x0C\xA0_\x00\x00\x0C\xA0";
+  ArrayRef Ref(Src, sizeof(Src) - 1);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(Ref, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
   // Src is the look of disapproval.
   static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0";
@@ -78,6 +100,17 @@
   EXPECT_FALSE(HasBOM);
 }
 
+TEST(ConvertUTFTest, UTF32WrappersForConvertUTF32ToUTF8String) {
+  // Src is the look of disapproval.
+  alignas(UTF32) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
+  ArrayRef SrcRef = makeArrayRef((const UTF32 *)Src, 4);
+  std::string Result;
+  bool Success = convertUTF32ToUTF8String(SrcRef, Result);
+  EXPECT_TRUE(Success);
+  std::string Expected("\xe0\xb2\xa0_\xe0\xb2\xa0");
+  EXPECT_EQ(Expected, Result);
+}
+
 TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) {
   // Src is the look of disapproval.
   alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
Index: llvm/lib/Support/ConvertUTFWrapper.cpp
===
--- llvm/lib/Support/ConvertUTFWrapper.cpp
+++ llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -141,6 +141,64 @@
   Src.size() * sizeof(UTF16)), Out);
 }
 
+bool convertUTF32ToUTF8String(ArrayRef SrcBytes, std::string ) {
+  assert(Out.empty());
+
+  // Error out on an uneven byte count.
+  if (SrcBytes.size() % 4)
+return false;
+
+  // Avoid OOB by returning early on empty input.
+  if (SrcBytes.empty())
+return true;
+
+  const UTF32 *Src = reinterpret_cast(SrcBytes.begin());
+  const UTF32 *SrcEnd = reinterpret_cast(SrcBytes.end());
+
+  assert((uintptr_t)Src % sizeof(UTF32) == 0);
+
+  // Byteswap if necessary.
+  std::vector ByteSwapped;
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
+ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
+for (unsigned I = 0, E = ByteSwapped.size(); I != E; ++I)
+  ByteSwapped[I] = llvm::ByteSwap_32(ByteSwapped[I]);
+Src = [0];
+SrcEnd = [ByteSwapped.size() - 1] + 1;
+  }
+
+  // Skip the BOM for conversion.
+  if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_NATIVE)
+Src++;
+
+  // Just allocate enough space up front.  We'll shrink it later.  Allocate
+  // enough that we can fit a null terminator without reallocating.
+  Out.resize(SrcBytes.size() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
+  UTF8 *Dst = reinterpret_cast([0]);
+  UTF8 *DstEnd = Dst + Out.size();
+
+  ConversionResult CR =
+  ConvertUTF32toUTF8(, SrcEnd, , DstEnd, strictConversion);
+  assert(CR != targetExhausted);
+
+  if (CR != conversionOK) {
+Out.clear();
+return false;
+  }
+
+  Out.resize(reinterpret_cast(Dst) - [0]);
+  Out.push_back(0);
+  Out.pop_back();
+  return true;
+}
+
+bool convertUTF32ToUTF8String(ArrayRef Src, std::string ) {
+  return convertUTF32ToUTF8String(
+  llvm::ArrayRef(reinterpret_cast(Src.data()),
+   Src.size() * sizeof(UTF32)),
+  Out);
+}
+
 bool convertUTF8ToUTF16String(StringRef SrcUTF8,
   SmallVectorImpl ) {
   assert(DstUTF16.empty());
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -278,6 +278,24 @@
 */
 bool convertUTF16ToUTF8String(ArrayRef Src, std::string );
 
+/**
+ * Converts a stream of raw bytes assumed to be UTF32 into a UTF8 std::string.
+ *
+ * \param [in] SrcBytes A buffer of what is assumed to be UTF-32 encoded text.
+ * \param [out] Out Converted UTF-8 is stored here on success.
+ * \returns true on success
+ */
+bool convertUTF32ToUTF8String(ArrayRef SrcBytes, std::string );
+

[PATCH] D106925: COFF/ELF: Place llvm.global_ctors elements in llvm.used if comdat is used

2021-07-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D106925#2910638 , @rnk wrote:

> lgtm
>
> So the main impact here is that, on ELF, linker GC will no longer be able to 
> GC vague linkage global variables with dynamic initializers. Those are things 
> like
>
> - C++17 inline globals
> - selectany globals
> - static data members of class template instantiations
>
> Seems reasonable to me.

That is it! The ELF linker GC is similar to link.exe GC in this regard: ctor 
sections in a group/COMDAT are not special (GC roots).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106925

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


  1   2   >