[PATCH] D155408: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

2023-07-17 Thread Cassie Jones 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 rG45ff63ba6112: [Driver] Also warn about -mwatchos-version-min 
and -mtvos-version-min (authored by porglezomp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155408

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,17 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos 
-mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 
-### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-mios-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-m{{ios|watchos|tvos}}-version-min=5'
+// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option '-mios-version-min=' 
for target 'thumbv7-apple-tvos'
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
+#include "llvm/TargetParser/Triple.h"
 #include  // ::getenv
 
 using namespace clang::driver;
@@ -85,10 +86,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
-if (T.isiOS())
+// Don't reject these -version-min= if we have the appropriate triple.
+if (T.getOS() == llvm::Triple::IOS)
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
+if (T.getOS() == llvm::Triple::WatchOS)
+  for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
+A->ignoreTargetSpecific();
+if (T.getOS() == llvm::Triple::TvOS)
+  for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
+A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
 T.setObjectFormat(llvm::Triple::MachO);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,17 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5'
+// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option 

[PATCH] D155408: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

2023-07-17 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 541157.
porglezomp added a comment.

Update to check the target OSes more precisely


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155408

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,17 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos 
-mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 
-### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-mios-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-m{{ios|watchos|tvos}}-version-min=5'
+// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option '-mios-version-min=' 
for target 'thumbv7-apple-tvos'
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
+#include "llvm/TargetParser/Triple.h"
 #include  // ::getenv
 
 using namespace clang::driver;
@@ -85,10 +86,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
-if (T.isiOS())
+// Don't reject these -version-min= if we have the appropriate triple.
+if (T.getOS() == llvm::Triple::IOS)
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
+if (T.getOS() == llvm::Triple::WatchOS)
+  for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
+A->ignoreTargetSpecific();
+if (T.getOS() == llvm::Triple::TvOS)
+  for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
+A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
 T.setObjectFormat(llvm::Triple::MachO);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,17 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5'
+// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option '-mios-version-min=' for target 'thumbv7-apple-tvos'
Index: clang/lib/Driver/ToolChains/Darwin.cpp

[PATCH] D155407: [Driver] Warn about all instances -mios-version-min not just the last

2023-07-16 Thread Cassie Jones 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 rGf7ad7d147b9c: [Driver] Warn about all instances 
-mios-version-min not just the last (authored by porglezomp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155407

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155408: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

2023-07-16 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: arphaman, t.p.northover, MaskRay, ahatanak.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sometimes users pass this option when targeting embedded architectures like 
armv7m on non-darwin platforms.
This applies to watchOS and tvOS as well as iOS.

Depends on D155407 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155408

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,14 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos 
-mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-mios-version-min=5'
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-m{{ios|watchos|tvos}}-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -85,10 +85,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
+// Don't reject these -version-min= if we have the appropriate triple.
 if (T.isiOS())
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
+if (T.isWatchOS())
+  for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
+A->ignoreTargetSpecific();
+if (T.isTvOS())
+  for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
+A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
 T.setObjectFormat(llvm::Triple::MachO);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,14 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5'
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -85,10 +85,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
+// Don't reject these -version-min= if we have the appropriate triple.
 if (T.isiOS())
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 

[PATCH] D155407: [Driver] Warn about all instances -mios-version-min not just the last

2023-07-16 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: arphaman, t.p.northover, MaskRay, ahatanak.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Follow-up to D155123 , uniformly handle cases 
where there are duplicate
-mios-verion-min arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155407

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151532: [test] Test ext_vector_type operators with implicit conversions

2023-05-26 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 525974.
porglezomp added a comment.

Add significantly more variations in this test case. I discovered multiple
inconsistencies while expanding this list out. Filed an issue on GitHub here:
https://github.com/llvm/llvm-project/issues/62949


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151532

Files:
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -772,3 +772,193 @@
 }
 #endif
 }
+
+namespace vector_implicit_conversions {
+// Test ext_vector_type builtin operators in the presence of implicit conversions
+
+typedef int __attribute__((ext_vector_type(4))) vec4i;
+
+struct vec4i_wrapper {
+vec4i x;
+
+vec4i_wrapper(const vec4i& val): x(val) {}
+operator vec4i() const { return x; } // expected-note 1+ {{candidate function}}
+};
+
+vec4i_wrapper operator| (const vec4i_wrapper& lhs, const vec4i_wrapper rhs) { return vec4i(lhs) | vec4i(rhs); }
+vec4i_wrapper& operator|= (vec4i_wrapper& lhs, const vec4i_wrapper& rhs) { return lhs = lhs | rhs; } // #oreq_operator
+
+vec4i_wrapper test_compound_assignment_mixed(vec4i_wrapper a, vec4i b) {
+  // These are not accepted because the LHS isn't subject to conversions, so no built-in operators apply here
+  a += b; // expected-error{{no viable overloaded '+='}}
+  a -= b; // expected-error{{no viable overloaded '-='}}
+  a *= b; // expected-error{{no viable overloaded '*='}}
+  a /= b; // expected-error{{no viable overloaded '/='}}
+  a %= b; // expected-error{{no viable overloaded '%='}}
+  a &= b; // expected-error{{no viable overloaded '&='}}
+  // Note: This operator is explicitly defined above, so it is accpted via implicit conversions
+  a |= b;
+  a ^= b; // expected-error{{no viable overloaded '^='}}
+  a >>= b; // expected-error{{no viable overloaded '>>='}}
+  a <<= b; // expected-error{{no viable overloaded '<<='}}
+
+  b += a;
+  b -= a;
+  b *= a;
+  b /= a;
+  // FIXME: Consistency for vector builtin operators with implicit conversions https://github.com/llvm/llvm-project/issues/62949
+  b %= a; // expected-error{{invalid operands to binary expression}}
+  b &= a; // expected-error{{invalid operands to binary expression}}
+  b |= a; // expected-error{{invalid operands to binary expression}}
+  // expected-note@#oreq_operator{{candidate function not viable}}
+  b ^= a; // expected-error{{invalid operands to binary expression}}
+  b >>= a; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+  b <<= a; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+
+  return a;
+}
+
+vec4i_wrapper test_operators_mixed(vec4i_wrapper a, vec4i b) {
+  // The operator overload isn't defined, so this is implicitly:
+  // a = vec4i_wrapper(vec4i(a) + b)
+  a = a + b;
+  a = b + a;
+  a = a - b;
+  a = b - a;
+  a = a * b;
+  a = b * a;
+  a = a / b;
+  a = b / a;
+  // FIXME: Consistency for vector builtin operators with implicit conversions https://github.com/llvm/llvm-project/issues/62949
+  a = a % b; // expected-error{{invalid operands to binary expression}}
+  a = b % a; // expected-error{{invalid operands to binary expression}}
+
+  // Conditionals yield vectors of integers
+  vec4i c;
+  c = a == b;
+  c = b == a;
+  c = a != b;
+  c = b != a;
+  c = a <= b;
+  c = b <= a;
+  c = a >= b;
+  c = b >= a;
+  c = a < b;
+  c = b < a;
+  c = a > b;
+  c = b > a;
+
+  a = a && b; // expected-error{{invalid operands to binary expression}}
+  // expected-error@-1{{cannot convert between vector and non-scalar values}}
+  a = b && a; // expected-error{{invalid operands to binary expression}}
+  // expected-error@-1{{cannot convert between vector and non-scalar values}}
+  a = a || b; // expected-error{{invalid operands to binary expression}}
+  // expected-error@-1{{cannot convert between vector and non-scalar values}}
+  a = b || a; // expected-error{{invalid operands to binary expression}}
+  // expected-error@-1{{cannot convert between vector and non-scalar values}}
+
+  a = a & b; // expected-error{{invalid operands to binary expression}}
+  a = b & a; // expected-error{{invalid operands to binary expression}}
+  // Note: These have a user-defined operator overload which is being selected
+  a = a | b;
+  a = b | a;
+  a = a ^ b; // expected-error{{invalid operands to binary expression}}
+  a = b ^ a; // expected-error{{invalid operands to binary expression}}
+  a = a << b; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+  a = b << a; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+  a = a >> b; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+  a = b >> a; // expected-error{{used type 'vec4i_wrapper' where integer is required}}
+
+  return a;
+}
+
+vec4i_wrapper 

[PATCH] D151060: [Clang][Sema] Generate vector vs scalar builtin overloads

2023-05-25 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

Confirming your sense that those loops look a bit suspicious, I've found that 
this makes some implicit conversions ambiguous.
Put a test case up for that at D151532 , I 
think I understand what those loops should be changed to instead, so I'll 
update when I have something passing this new test as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151060

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


[PATCH] D151532: [test] Test ext_vector_type operators with implicit conversions

2023-05-25 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: aaron.ballman, fhahn.
Herald added a subscriber: StephenFan.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An extra test for implicit conversion issues discovered while testing D151060 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151532

Files:
  clang/test/SemaCXX/vector.cpp


Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -772,3 +772,27 @@
 }
 #endif
 }
+
+namespace {
+// Test ext_vector_type builtin operators in the presence of implicit 
conversions
+
+typedef int __attribute__((ext_vector_type(4))) vec4i;
+
+struct simd4i {
+vec4i x;
+
+simd4i(const vec4i& val): x(val) {}
+operator vec4i() const { return x; }
+};
+
+simd4i operator| (const simd4i& lhs, const simd4i& rhs) { return vec4i(lhs) | 
vec4i(rhs); }
+simd4i& operator|= (simd4i& lhs, const simd4i& rhs) { return lhs = lhs | rhs; }
+
+simd4i test1(simd4i a, vec4i b) {
+return a |= b;
+}
+
+simd4i test2(simd4i a, vec4i b) {
+return a | b;
+}
+}


Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -772,3 +772,27 @@
 }
 #endif
 }
+
+namespace {
+// Test ext_vector_type builtin operators in the presence of implicit conversions
+
+typedef int __attribute__((ext_vector_type(4))) vec4i;
+
+struct simd4i {
+vec4i x;
+
+simd4i(const vec4i& val): x(val) {}
+operator vec4i() const { return x; }
+};
+
+simd4i operator| (const simd4i& lhs, const simd4i& rhs) { return vec4i(lhs) | vec4i(rhs); }
+simd4i& operator|= (simd4i& lhs, const simd4i& rhs) { return lhs = lhs | rhs; }
+
+simd4i test1(simd4i a, vec4i b) {
+return a |= b;
+}
+
+simd4i test2(simd4i a, vec4i b) {
+return a | b;
+}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151060: [Clang][Sema] Generate vector vs scalar builtin overloads

2023-05-25 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:9041-9044
+  // (allowing splatting the scalar to a vector).
+  for (unsigned Candidate = 0; Candidate < 2; ++Candidate) {
+for (QualType Vec1Ty : CandidateTypes[Candidate].vector_types()) {
+  for (QualType Vec2Ty : CandidateTypes[Candidate].vector_types()) {

aaron.ballman wrote:
> I'm a bit confused -- the comment says this is to allow splatting the scalar 
> to a vector, but... what is the scalar type in these loops?
Right, so my goal here is to generate the two vector-operand overload 
candidates so that overload resolution can pick one of those and then apply the 
implicit scalar->vector conversion with the splat. I //think// this is the 
correct approach (it's based on how the compound assignment operators already 
handle this) but I need to improve my comments here.

Also, how do we like the loop here for trying both sides, as opposed to 
duplicating the code? This is really acting as an `if left operand / else if 
right operand` to avoid duplicating the code but I was worried writing it that 
the loop obscures the intent. Maybe that's also just "make the comment better" 
or maybe that part is clear enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151060

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


[PATCH] D151059: [test] Add C++ ext_vector_type tests

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG590eb76ba3cd: [test] Add C++ ext_vector_type tests (authored 
by porglezomp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151059

Files:
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -545,3 +545,230 @@
   auto b4 = (v4 >= 0x12);
 }
 #endif
+
+namespace all_operators {
+typedef unsigned int v2u __attribute__((ext_vector_type(2)));
+typedef float v2f __attribute__((ext_vector_type(2)));
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Operators with one integer vector and one integer scalar operand. The scalar will splat.
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Operators with one float vector and one float scalar operand. The scalar will splat.
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer 

[PATCH] D151061: [test] Add ext_vector_type tests for C

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5b689679e1e: [test] Add more ext_vector_type tests for C 
(authored by porglezomp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151061

Files:
  clang/test/Sema/ext_vector_ops.c
  clang/test/Sema/vecshift.c

Index: clang/test/Sema/vecshift.c
===
--- clang/test/Sema/vecshift.c
+++ clang/test/Sema/vecshift.c
@@ -65,6 +65,20 @@
   vs8 = ui << vs8;
   vus8 = 1 << vus8;
 
+  vc8 = vc8 << c;
+  vuc8 = vuc8 << uc;
+  vs8 = vs8 << s;
+  vus8 = vus8 << us;
+  vi8 = vi8 << i;
+  vui8 = vui8 << ui;
+
+  vc8 = vc8 << i;
+  vuc8 = vuc8 << i;
+  vs8 = vs8 << i;
+  vus8 = vus8 << i;
+  vi8 = vi8 << i;
+  vui8 = vui8 << i;
+
   vc8 = vc8 << vc8;
 #ifdef ERR
   vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
Index: clang/test/Sema/ext_vector_ops.c
===
--- clang/test/Sema/ext_vector_ops.c
+++ clang/test/Sema/ext_vector_ops.c
@@ -25,3 +25,211 @@
   v2u *v2u_ptr = 0;
   v2s *v2s_ptr;
 }
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Operations with one integer vector and one scalar. These splat the scalar.
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Operations with one float vector and one scalar. These splat the scalar.
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua << v2fa); // expected-error{{used type 'v2f' 

[PATCH] D151060: [Clang][Sema] Generate vector vs scalar builtin overloads

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 524432.
porglezomp added a comment.

Rebasing onto modified tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151060

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -728,12 +728,10 @@
   (void)(ea | v2ua); // expected-error{{cannot convert between vector values of different size}}
   (void)(v2ua ^ ea); // expected-error{{cannot convert between vector values of different size}}
   (void)(ea ^ v2ua); // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // https://github.com/llvm/llvm-project/issues/62870
-  // (void)(v2ua << ea);
-  // (void)(ea << v2ua);
-  // (void)(v2ua >> ea);
-  // (void)(ea >> v2ua);
+  (void)(v2ua << ea);
+  (void)(ea << v2ua);
+  (void)(v2ua >> ea);
+  (void)(ea >> v2ua);
 
   v2ua += ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua -= ea; // expected-error{{cannot convert between vector values of different size}}
@@ -743,10 +741,8 @@
   v2ua &= ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua |= ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua ^= ea; // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // https://github.com/llvm/llvm-project/issues/62870
-  // v2ua >>= ea;
-  // v2ua <<= ea;
+  v2ua >>= ea;
+  v2ua <<= ea;
 
   ea += v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea -= v2ua; // expected-error{{cannot convert between vector values of different size}}
@@ -756,10 +752,8 @@
   ea &= v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea |= v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea ^= v2ua; // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // https://github.com/llvm/llvm-project/issues/62870
-  // ea >>= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
-  // ea <<= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
+  ea >>= v2ua; // expected-error{{assigning to 'Enum' from incompatible type 'v2u'}}
+  ea <<= v2ua; // expected-error{{assigning to 'Enum' from incompatible type 'v2u'}}
 }
 
 #if __cplusplus >= 201103L // C++11 or later
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9024,6 +9024,30 @@
 S.AddBuiltinCandidate(LandR, Args, CandidateSet);
   }
 }
+
+// Extension: Add the binary bitwise operators for vector types
+if (!CandidateTypes[0].vector_types().empty() &&
+!CandidateTypes[1].vector_types().empty()) {
+  // If both candidates have vector types, then add them pairwise...
+  for (QualType Vec1Ty : CandidateTypes[0].vector_types()) {
+for (QualType Vec2Ty : CandidateTypes[1].vector_types()) {
+  QualType LandR[2] = {Vec1Ty, Vec2Ty};
+  S.AddBuiltinCandidate(LandR, Args, CandidateSet);
+}
+  }
+} else {
+  // ...but if only one side has vector candidates, use that set of
+  // vector candidates pairwise for both sides of the operator
+  // (allowing splatting the scalar to a vector).
+  for (unsigned Candidate = 0; Candidate < 2; ++Candidate) {
+for (QualType Vec1Ty : CandidateTypes[Candidate].vector_types()) {
+  for (QualType Vec2Ty : CandidateTypes[Candidate].vector_types()) {
+QualType LandR[2] = {Vec1Ty, Vec2Ty};
+S.AddBuiltinCandidate(LandR, Args, CandidateSet);
+  }
+}
+  }
+}
   }
 
   // C++ [over.built]p20:
@@ -9250,6 +9274,25 @@
 });
   }
 }
+
+// Extension: Add the binary operators %=, <<=, >>=, &=, ^=, |= for vector types.
+for (QualType Vec1Ty : CandidateTypes[0].vector_types())
+  for (QualType Vec2Ty : CandidateTypes[0].vector_types()) {
+QualType ParamTypes[2];
+ParamTypes[1] = Vec2Ty;
+// Add this built-in operator as a candidate (VQ is empty).
+ParamTypes[0] = S.Context.getLValueReferenceType(Vec1Ty);
+S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
+  /*IsAssignmentOperator=*/false);
+
+// Add this built-in operator as a candidate (VQ is 'volatile').
+if (VisibleTypeConversionsQuals.hasVolatile()) {
+  ParamTypes[0] = 

[PATCH] D151059: [test] Add C++ ext_vector_type tests

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 524429.
porglezomp added a comment.

Address review comments.
File GitHub issues and reference them with the FIXMEs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151059

Files:
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -545,3 +545,230 @@
   auto b4 = (v4 >= 0x12);
 }
 #endif
+
+namespace all_operators {
+typedef unsigned int v2u __attribute__((ext_vector_type(2)));
+typedef float v2f __attribute__((ext_vector_type(2)));
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Operators with one integer vector and one integer scalar operand. The scalar will splat.
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Operators with one float vector and one float scalar operand. The scalar will splat.
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is 

[PATCH] D151061: [test] Add ext_vector_type tests for C

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 524405.
porglezomp added a comment.

Address the comment suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151061

Files:
  clang/test/Sema/ext_vector_ops.c
  clang/test/Sema/vecshift.c

Index: clang/test/Sema/vecshift.c
===
--- clang/test/Sema/vecshift.c
+++ clang/test/Sema/vecshift.c
@@ -65,6 +65,20 @@
   vs8 = ui << vs8;
   vus8 = 1 << vus8;
 
+  vc8 = vc8 << c;
+  vuc8 = vuc8 << uc;
+  vs8 = vs8 << s;
+  vus8 = vus8 << us;
+  vi8 = vi8 << i;
+  vui8 = vui8 << ui;
+
+  vc8 = vc8 << i;
+  vuc8 = vuc8 << i;
+  vs8 = vs8 << i;
+  vus8 = vus8 << i;
+  vi8 = vi8 << i;
+  vui8 = vui8 << i;
+
   vc8 = vc8 << vc8;
 #ifdef ERR
   vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
Index: clang/test/Sema/ext_vector_ops.c
===
--- clang/test/Sema/ext_vector_ops.c
+++ clang/test/Sema/ext_vector_ops.c
@@ -25,3 +25,211 @@
   v2u *v2u_ptr = 0;
   v2s *v2s_ptr;
 }
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Operations with one integer vector and one scalar. These splat the scalar.
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Operations with one float vector and one scalar. These splat the scalar.
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  

[PATCH] D151059: [test] Add C++ ext_vector_type tests

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

See also: C versions of these test cases: D151061 


I think the C versions behave correctly and that C++ should match that behavior.
Interested in feedback from anyone working with ext_vector_types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151059

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


[PATCH] D151061: [test] Add ext_vector_type tests for C

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

See also: very similar baseline tests for C++: D151059 


I'm interested in any feedback about the correct semantics for this.
I started writing these tests while investigating the behavior of vector vs 
scalar operations in C++ for D151060  and 
finding a lot of that inconsistent.
I want to get down checks that these cases are all appropriately accepted.
Interested in feedback from anyone working with the ext_vector_types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151061

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


[PATCH] D151061: [test] Add ext_vector_type tests for C

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: aaron.ballman, fhahn.
Herald added a subscriber: StephenFan.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Test that all vector-vs-scalar builtin operators type check
successfully.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151061

Files:
  clang/test/Sema/ext_vector_ops.c
  clang/test/Sema/vecshift.c

Index: clang/test/Sema/vecshift.c
===
--- clang/test/Sema/vecshift.c
+++ clang/test/Sema/vecshift.c
@@ -65,6 +65,20 @@
   vs8 = ui << vs8;
   vus8 = 1 << vus8;
 
+  vc8 = vc8 << c;
+  vuc8 = vuc8 << uc;
+  vs8 = vs8 << s;
+  vus8 = vus8 << us;
+  vi8 = vi8 << i;
+  vui8 = vui8 << ui;
+
+  vc8 = vc8 << i;
+  vuc8 = vuc8 << i;
+  vs8 = vs8 << i;
+  vus8 = vus8 << i;
+  vi8 = vi8 << i;
+  vui8 = vui8 << i;
+
   vc8 = vc8 << vc8;
 #ifdef ERR
   vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
Index: clang/test/Sema/ext_vector_ops.c
===
--- clang/test/Sema/ext_vector_ops.c
+++ clang/test/Sema/ext_vector_ops.c
@@ -25,3 +25,210 @@
   v2u *v2u_ptr = 0;
   v2s *v2s_ptr;
 }
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Integer vector vs integer operators. These will splat
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Float vector vs float operators. These will splat
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+ 

[PATCH] D151060: [Clang][Sema] Generate vector vs scalar builtin overloads

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: aaron.ballman, fhahn.
Herald added a subscriber: StephenFan.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The bit-shifting operator builtin support vector vs scalars, but the
operator overloads did not. That mismatch caused an assertion failure
when trying to shift a vector by an enum.

This makes C++ match the behavior of C for these conversions on
bit-shifts.

rdar://108819842
Depends on D151059 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151060

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -726,11 +726,10 @@
   (void)(ea | v2ua); // expected-error{{cannot convert between vector values of different size}}
   (void)(v2ua ^ ea); // expected-error{{cannot convert between vector values of different size}}
   (void)(ea ^ v2ua); // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // (void)(v2ua << ea);
-  // (void)(ea << v2ua);
-  // (void)(v2ua >> ea);
-  // (void)(ea >> v2ua);
+  (void)(v2ua << ea);
+  (void)(ea << v2ua);
+  (void)(v2ua >> ea);
+  (void)(ea >> v2ua);
 
   v2ua += ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua -= ea; // expected-error{{cannot convert between vector values of different size}}
@@ -740,9 +739,8 @@
   v2ua &= ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua |= ea; // expected-error{{cannot convert between vector values of different size}}
   v2ua ^= ea; // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // v2ua >>= ea;
-  // v2ua <<= ea;
+  v2ua >>= ea;
+  v2ua <<= ea;
 
   ea += v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea -= v2ua; // expected-error{{cannot convert between vector values of different size}}
@@ -752,9 +750,8 @@
   ea &= v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea |= v2ua; // expected-error{{cannot convert between vector values of different size}}
   ea ^= v2ua; // expected-error{{cannot convert between vector values of different size}}
-  // FIXME: Vector/scalar shifts cause an assertion failure
-  // ea >>= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
-  // ea <<= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
+  ea >>= v2ua; // expected-error{{assigning to 'Enum' from incompatible type 'v2u'}}
+  ea <<= v2ua; // expected-error{{assigning to 'Enum' from incompatible type 'v2u'}}
 }
 
 #if __cplusplus >= 201103L // C++11 or later
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9024,6 +9024,30 @@
 S.AddBuiltinCandidate(LandR, Args, CandidateSet);
   }
 }
+
+// Extension: Add the binary bitwise operators for vector types
+if (!CandidateTypes[0].vector_types().empty() &&
+!CandidateTypes[1].vector_types().empty()) {
+  // If both candidates have vector types, then add them pairwise...
+  for (QualType Vec1Ty : CandidateTypes[0].vector_types()) {
+for (QualType Vec2Ty : CandidateTypes[1].vector_types()) {
+  QualType LandR[2] = {Vec1Ty, Vec2Ty};
+  S.AddBuiltinCandidate(LandR, Args, CandidateSet);
+}
+  }
+} else {
+  // ...but if only one side has vector candidates, use that set of
+  // vector candidates pairwise for both sides of the operator
+  // (allowing splatting the scalar to a vector).
+  for (unsigned Candidate = 0; Candidate < 2; ++Candidate) {
+for (QualType Vec1Ty : CandidateTypes[Candidate].vector_types()) {
+  for (QualType Vec2Ty : CandidateTypes[Candidate].vector_types()) {
+QualType LandR[2] = {Vec1Ty, Vec2Ty};
+S.AddBuiltinCandidate(LandR, Args, CandidateSet);
+  }
+}
+  }
+}
   }
 
   // C++ [over.built]p20:
@@ -9250,6 +9274,25 @@
 });
   }
 }
+
+// Extension: Add the binary operators %=, <<=, >>=, &=, ^=, |= for vector types.
+for (QualType Vec1Ty : CandidateTypes[0].vector_types())
+  for (QualType Vec2Ty : CandidateTypes[0].vector_types()) {
+QualType ParamTypes[2];
+ParamTypes[1] = Vec2Ty;
+// Add this built-in operator as a candidate (VQ is empty).
+ParamTypes[0] = S.Context.getLValueReferenceType(Vec1Ty);
+S.AddBuiltinCandidate(ParamTypes, Args, 

[PATCH] D151059: [test] Add C++ ext_vector_type tests

2023-05-22 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: aaron.ballman, fhahn.
Herald added a subscriber: StephenFan.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add initial tests for the behavior of ext_vector_type vectors for
vector vs scalar ops in C++. Their behavior doesn't agree with the behavior in
C and what the behavior seems like it should be, these are baseline tests before
implementing those changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151059

Files:
  clang/test/SemaCXX/vector.cpp

Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp
@@ -545,3 +545,225 @@
   auto b4 = (v4 >= 0x12);
 }
 #endif
+
+namespace all_operators {
+typedef unsigned int v2u __attribute__((ext_vector_type(2)));
+typedef float v2f __attribute__((ext_vector_type(2)));
+
+void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
+  // Integer vector vs integer operators. These will splat
+  (void)(v2ua + ua);
+  (void)(ua + v2ua);
+  (void)(v2ua - ua);
+  (void)(ua - v2ua);
+  (void)(v2ua * ua);
+  (void)(ua * v2ua);
+  (void)(v2ua / ua);
+  (void)(ua / v2ua);
+  (void)(v2ua % ua);
+  (void)(ua % v2ua);
+
+  (void)(v2ua == ua);
+  (void)(ua == v2ua);
+  (void)(v2ua != ua);
+  (void)(ua != v2ua);
+  (void)(v2ua <= ua);
+  (void)(ua <= v2ua);
+  (void)(v2ua >= ua);
+  (void)(ua >= v2ua);
+  (void)(v2ua < ua);
+  (void)(ua < v2ua);
+  (void)(v2ua > ua);
+  (void)(ua > v2ua);
+  (void)(v2ua && ua);
+  (void)(ua && v2ua);
+  (void)(v2ua || ua);
+  (void)(ua || v2ua);
+
+  (void)(v2ua & ua);
+  (void)(ua & v2ua);
+  (void)(v2ua | ua);
+  (void)(ua | v2ua);
+  (void)(v2ua ^ ua);
+  (void)(ua ^ v2ua);
+  (void)(v2ua << ua);
+  (void)(ua << v2ua);
+  (void)(v2ua >> ua);
+  (void)(ua >> v2ua);
+
+  v2ua += ua;
+  v2ua -= ua;
+  v2ua *= ua;
+  v2ua /= ua;
+  v2ua %= ua;
+  v2ua &= ua;
+  v2ua |= ua;
+  v2ua ^= ua;
+  v2ua >>= ua;
+  v2ua <<= ua;
+
+  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
+}
+
+void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
+  // Float vector vs float operators. These will splat
+  (void)(v2fa + fa);
+  (void)(fa + v2fa);
+  (void)(v2fa - fa);
+  (void)(fa - v2fa);
+  (void)(v2fa * fa);
+  (void)(fa * v2fa);
+  (void)(v2fa / fa);
+  (void)(fa / v2fa);
+  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
+
+  (void)(v2fa == fa);
+  (void)(fa == v2fa);
+  (void)(v2fa != fa);
+  (void)(fa != v2fa);
+  (void)(v2fa <= fa);
+  (void)(fa <= v2fa);
+  (void)(v2fa >= fa);
+  (void)(fa >= v2fa);
+  (void)(v2fa < fa);
+  (void)(fa < v2fa);
+  (void)(v2fa > fa);
+  (void)(fa > v2fa);
+  (void)(v2fa && fa);
+  (void)(fa && v2fa);
+  (void)(v2fa || fa);
+  (void)(fa || v2fa);
+
+  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
+  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
+  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
+  (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
+  (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) 

[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-14 Thread Cassie Jones via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e2709479636: [clang] Include clang config.h in 
LangStandards.cpp (authored by porglezomp).

Changed prior to commit:
  https://reviews.llvm.org/D124974?vs=429275=429416#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

Files:
  clang/lib/Basic/LangStandards.cpp


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-13 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 429275.
porglezomp added a comment.

I haven't used arc in a little while and am having trouble sorry for the emails


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

Files:
  clang/include/clang/Config/config.h.cmake
  clang/lib/Basic/LangStandards.cpp


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -57,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_CXX
+#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
+#endif
 
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -57,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to 

[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-13 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 429274.
porglezomp added a comment.

Arcanist accidentally threw away the first commit in the sequence...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

Files:
  clang/include/clang/Config/config.h.cmake
  clang/lib/Basic/LangStandards.cpp


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -58,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_CXX
+#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
+#endif
 
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -58,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_CXX
+#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
+#endif
 
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-13 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp updated this revision to Diff 429273.
porglezomp added a comment.
Herald added a subscriber: mgorny.

Add changes suggested by Duncan to make CLANG_DEFAULT_STD_C more 
misuse-resistant


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

Files:
  clang/include/clang/Config/config.h.cmake
  clang/lib/Basic/LangStandards.cpp


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -58,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_CXX
+#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
+#endif
 
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -58,27 +58,24 @@
 return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 // The PS4 uses C99 as the default C standard.
 if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
-#endif
   case Language::ObjC:
-#if defined(CLANG_DEFAULT_STD_C)
-return CLANG_DEFAULT_STD_C;
-#else
+if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_C;
+
 return LangStandard::lang_gnu11;
-#endif
   case Language::CXX:
   case Language::ObjCXX:
-#if defined(CLANG_DEFAULT_STD_CXX)
-return CLANG_DEFAULT_STD_CXX;
-#else
+if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified)
+  return CLANG_DEFAULT_STD_CXX;
+
 return LangStandard::lang_gnucxx14;
-#endif
   case Language::RenderScript:
 return LangStandard::lang_c99;
   case Language::HIP:
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -16,9 +16,19 @@
 
 /* Default C/ObjC standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_C
+#define CLANG_DEFAULT_STD_C LangStandard::lang_unspecified
+#endif
 
 /* Default C++/ObjC++ standard to use. */
 #cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+// Always #define something so that missing the config.h #include at use sites
+// becomes a compile error.
+#ifndef CLANG_DEFAULT_STD_CXX
+#define CLANG_DEFAULT_STD_CXX LangStandard::lang_unspecified
+#endif
 
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-13 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

That looks good to me. I'm testing it out locally to make sure it still works 
right and also catches the issue, and will plan put up an updated patch in the 
morning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

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


[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-10 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

Ah, so it'd be a test that passes pretty trivially on any bot that doesn't have 
a custom version of `CLANG_DEFAULT_STD_C` and `CLANG_DEFAULT_STD_CXX` like the 
default config, but could get caught by any other bots that do set it?

What's the best way to get the compiler to report the standard it's using for 
this test?

For C++ I can do:

  clang++ -xc++ -dM -E - < /dev/null | grep cplusplus

And it will print e.g.

  #define __cplusplus 199711L

But that requires quite some decoding to compare against 
`CLANG_DEFAULT_STD_CXX` which would look like `LangStandard::lang_gnucxx98`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

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


[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-09 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp added a comment.

Unless anyone has an idea about how to test this, I'm going to commit this 
without adding a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124974

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


[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

2022-05-04 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: hokein, sammccall, dexonsmith.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is necessary in order to pick up the default C/C++ standard from
the CLANG_DEFAULT_STD_C(XX) defines. This fixes a bug that was
introduced when this default language standard code was moved from
Frontend to Basic, making compilers ignore the configured default
language version override.

Fixes a bug introduced by D121375 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124974

Files:
  clang/lib/Basic/LangStandards.cpp


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"


Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Basic/LangStandard.h"
+#include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits