Skip to content

Conversation

@pradt2
Copy link

@pradt2 pradt2 commented Feb 17, 2025

This addresses issue #113094

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 17, 2025

@llvm/pr-subscribers-clang

Author: None (pradt2)

Changes

This addresses issue #113094


Full diff: https://github.com/llvm/llvm-project/pull/127439.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaType.cpp (+6-7)
  • (added) clang/test/Sema/bug113094.cpp (+6)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1fa5239a597c8..0c5cfdbba8d3d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8336,12 +8336,11 @@ static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
 /// match one of the standard Neon vector types.
 static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
                                      Sema &S, VectorKind VecKind) {
-  bool IsTargetCUDAAndHostARM = false;
-  if (S.getLangOpts().CUDAIsDevice) {
-    const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
-    IsTargetCUDAAndHostARM =
-        AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
-  }
+  const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
+  bool IsArm = AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
+
+  bool IsTargetCUDAAndHostARM = IsArm && S.getLangOpts().CUDAIsDevice;
+  bool IsTargetOpenMPDeviceAndHostARM = IsArm && S.getLangOpts().OpenMPIsTargetDevice;
 
   // Target must have NEON (or MVE, whose vectors are similar enough
   // not to need a separate attribute)
@@ -8376,7 +8375,7 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
 
   // Only certain element types are supported for Neon vectors.
   if (!isPermittedNeonBaseType(CurType, VecKind, S) &&
-      !IsTargetCUDAAndHostARM) {
+      !IsTargetCUDAAndHostARM && !IsTargetOpenMPDeviceAndHostARM) {
     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
     Attr.setInvalid();
     return;
diff --git a/clang/test/Sema/bug113094.cpp b/clang/test/Sema/bug113094.cpp
new file mode 100644
index 0000000000000..0900db9efb041
--- /dev/null
+++ b/clang/test/Sema/bug113094.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang -fopenmp --offload-arch=sm_90 -nocudalib -target aarch64-unknown-linux-gnu -c -Xclang -verify %s
+// REQUIRES: aarch64-registered-target
+
+// expected-no-diagnostics
+
+typedef __attribute__ ((__neon_vector_type__ (4))) float __f32x4_t;

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix! I added more reviewers with offloading/OpenMP background. Could you please also modify the title and the description of the PR so it says what was the problem and how it was fixed instead of simply saying it fixed this bug?

@@ -0,0 +1,6 @@
// RUN: %clang -fopenmp --offload-arch=sm_90 -nocudalib -target aarch64-unknown-linux-gnu -c -Xclang -verify %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually use clang driver in front-end tests. Could you please create a run line using pure front-end, i.e. via %clang_cc1 ?
Also, since this is OpenMP related, could you please put the test to OpenMP/ directory?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems CUDA used to have a test for this but it was removed for some reason? I would just stash it in SemaOpenMP or OpenMP and copy one of the existing -verify tests.

const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
bool IsArm = AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());

bool IsTargetCUDAAndHostARM = IsArm && S.getLangOpts().CUDAIsDevice;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a question to offloading experts of the community. I think all single-source offloading models eventually run into similar problems. It doesn't depend on the language being used (CUDA/OpenMP/SYCL) and what are the architectures. So I wonder if it makes sense to do a more generalized check, something like "if device doesn't support but the host does, dont error out".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, unfortunately a lot of this handling is spread out all over the place. There's #126956 up which also tries to clean some of this up. However, right now I'd say that would be a larger cleanup out of scope for this bug fix.

@jhuber6 jhuber6 changed the title Clang/bug113094 [OpenMP] Silencly accept neon_vector_type for the offloading device Feb 17, 2025
@jhuber6
Copy link
Contributor

jhuber6 commented Feb 17, 2025

The test you added doesn't seem to pass. You can run it locally with llvm-lit /path/to/your/test -v.

@github-actions
Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff d841c8842e17b7e74c3ee98c13a8a2505566deed 55e4d444572da286fdd4218178c6bc03c3e56b5b --extensions cpp -- clang/test/Sema/bug113094.cpp clang/lib/Sema/SemaType.cpp
View the diff from clang-format here.
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 0c5cfdbba8..9aeab7595d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8337,10 +8337,12 @@ static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
 static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
                                      Sema &S, VectorKind VecKind) {
   const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
-  bool IsArm = AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
+  bool IsArm =
+      AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
 
   bool IsTargetCUDAAndHostARM = IsArm && S.getLangOpts().CUDAIsDevice;
-  bool IsTargetOpenMPDeviceAndHostARM = IsArm && S.getLangOpts().OpenMPIsTargetDevice;
+  bool IsTargetOpenMPDeviceAndHostARM =
+      IsArm && S.getLangOpts().OpenMPIsTargetDevice;
 
   // Target must have NEON (or MVE, whose vectors are similar enough
   // not to need a separate attribute)

@jhuber6 jhuber6 changed the title [OpenMP] Silencly accept neon_vector_type for the offloading device [OpenMP] Silently accept neon_vector_type for the offloading device Feb 17, 2025
@@ -0,0 +1,6 @@
// RUN: %clang -fopenmp --offload-arch=sm_90 -nocudalib -target aarch64-unknown-linux-gnu -c -Xclang -verify %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %clang_cc1 here instead of the driver.

@pradt2
Copy link
Author

pradt2 commented Feb 19, 2025

While I was working on the tests, I realised I can no longer replicate this issue in main. I guess it got fixed by someone, somewhere. I'm gonna close this now.

@pradt2 pradt2 closed this Feb 19, 2025
@jhuber6
Copy link
Contributor

jhuber6 commented Feb 19, 2025

While I was working on the tests, I realised I can no longer replicate this issue in main. I guess it got fixed by someone, somewhere. I'm gonna close this now.

I'm not aware of any changes in this area, but if it doesn't fail anymore I guess that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants