Skip to content

Flang: Add support for Cray pointers in OpenMP constructs #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kiranktp
Copy link
Owner

@kiranktp kiranktp commented Jan 9, 2025

@coderabbitai

Summary by CodeRabbit

  • New Features

    • Added test case for Cray pointer usage in OpenMP parallel regions.
  • Tests

    • Introduced a new test subroutine test_crayptr demonstrating Cray pointer behavior with different OpenMP sharing attributes.
  • Bug Fixes

    • Improved handling of Cray pointers in OpenMP construct resolution to prevent unintended symbol flag updates.

…sharing attributes

Issue description:
	When DEFAULT DSA is NONE, all data refs must be listed in one of the data sharing clause.
	When a Cray pointer is listed in one of the data sharing clause, Cray pointee can be used in parallel region.
	This is valid as per standard.
	"Cray pointees have the same data-sharing attribute as the storage with which their Cray pointers are associated."
        Currently compiler crashes for default(none).
        Also current semantic checks incorrectly updates the symbol flags related to Craypointee symbols.
        due to this incorrect updation, compiler crashes when default(private) and default(firstprivate) is specified.

Solution:
        Added an additional check to skip updation of symbol flags related to Craypointee symbols.
        This also prevents from checking cray pointee when DEFAULT DSA is NONE.

This patch has code changes and a test case.
Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces modifications to the Flang compiler's handling of Cray pointers in OpenMP constructs. A change in the resolve-directives.cpp file modifies the OmpAttributeVisitor::Post method to add a special check for Cray Pointee symbols. A corresponding test file cray-pointer-usage.f90 is added to validate the behavior of Cray pointers in different OpenMP parallel region configurations.

Changes

File Change Summary
flang/lib/Semantics/resolve-directives.cpp Added conditional check to early return for CrayPointee symbols in OpenMP attribute processing
flang/test/Semantics/OpenMP/cray-pointer-usage.f90 New test subroutine test_crayptr demonstrating Cray pointer behavior in OpenMP parallel regions

Sequence Diagram

sequenceDiagram
    participant Compiler
    participant OmpAttributeVisitor
    participant Symbol
    
    Compiler->>OmpAttributeVisitor: Process OpenMP Attributes
    OmpAttributeVisitor->>Symbol: Check Symbol Type
    alt Is CrayPointee
        OmpAttributeVisitor-->>Compiler: Early Return
    else Not CrayPointee
        OmpAttributeVisitor->>Symbol: Continue Processing
    end
Loading

Poem

🐰 A Rabbit's Ode to Cray Pointers

In OpenMP's parallel dance,
Cray pointers take a special stance
With early returns so neat and clean,
No warnings, no fuss, a compiler's dream!
Hopping through code with magical might 🚀

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review.

Finishing Touches

  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kiranktp
Copy link
Owner Author

kiranktp commented Jan 9, 2025

@coderabbitai help

Copy link

coderabbitai bot commented Jan 9, 2025

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

@kiranktp
Copy link
Owner Author

kiranktp commented Jan 9, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented Jan 9, 2025

✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai bot changed the title @coderabbitai Flang: Add support for Cray pointers in OpenMP constructs Jan 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
flang/test/Semantics/OpenMP/cray-pointer-usage.f90 (2)

12-26: Consider enhancing test coverage and verification.

While the parallel regions effectively test different data-sharing combinations, consider these improvements:

  1. Add explicit value verification instead of just printing
  2. Add synchronization between parallel regions
  3. Include a test case for threadprivate

Example addition for threadprivate:

  !$omp threadprivate(ivar)
  !$omp parallel num_threads(2)
    print *, var(1)
  !$omp end parallel

1-29: Consider structured test result verification.

While the test effectively covers various OpenMP data-sharing attributes with Cray pointers, consider implementing a more structured verification approach:

  1. Add expected results as comments
  2. Implement result validation instead of print statements
  3. Consider using OpenMP critical sections for deterministic output

Example structured verification:

  real*8 :: expected_value = 42.0
  logical :: test_passed = .true.
  !$omp parallel num_threads(2) default(none) shared(ivar, test_passed, expected_value)
    !$omp critical
      if (var(1) /= expected_value) then
        test_passed = .false.
      endif
    !$omp end critical
  !$omp end parallel
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aba6bb0 and 127024c.

📒 Files selected for processing (2)
  • flang/lib/Semantics/resolve-directives.cpp (1 hunks)
  • flang/test/Semantics/OpenMP/cray-pointer-usage.f90 (1 hunks)
🔇 Additional comments (3)
flang/lib/Semantics/resolve-directives.cpp (1)

2245-2260: LGTM! The special handling for Cray pointers is correct.

The changes properly handle Cray pointers by skipping flag updates when a symbol has the CrayPointee flag set, while still preserving the DEFAULT(NONE) clause validation. This prevents unnecessary symbol flag modifications for Cray pointers in OpenMP constructs.

flang/test/Semantics/OpenMP/cray-pointer-usage.f90 (2)

1-8: LGTM! Well-structured test setup.

The test configuration and variable declarations are correct. The use of test_errors.py with -fopenmp flag ensures proper OpenMP directive validation.


9-11: LGTM! Correct pointer initialization sequence.

The initialization of the pointee array and Cray pointer setup using loc() follows the standard pattern.

kiranktp pushed a commit that referenced this pull request Feb 13, 2025
…StrictPackMatch field (llvm#126215)

This addresses the MSAN failure reported
in
llvm#125791 (comment):
```
==5633==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 in clang::ASTNodeImporter::CallOverloadedCreateFun<clang::ClassTemplateSpecializationDecl>::operator()
    #1 in bool clang::ASTNodeImporter::GetImportedOrCreateSpecialDecl<...>
...
```

The ASTImporter reads `D->hasStrictPackMatch()` and forwards it to the
constructor of the destination `ClassTemplateSpecializationDecl`. But if
`D` is a decl that LLDB created from debug-info, it would've been
created using `ClassTemplateSpecializationDecl::CreateDeserialized`,
which doesn't initialize the `StrictPackMatch` field.

This patch just initializes the field to a fixed value of `false`, to
preserve previous behaviour and avoid the use-of-uninitialized-value.

An alternative would be to always initialize it in the
`ClassTemplateSpecializationDecl` constructor, but there were
reservations about providing a default value for it because it might
lead to hard-to-diagnose problems down the line.
kiranktp pushed a commit that referenced this pull request Feb 13, 2025
We can't guaranty that underlying string is
0-terminated and [String.size()] is even in the
same allocation.


https://lab.llvm.org/buildbot/#/builders/94/builds/4152/steps/17/logs/stdio
```
==c-index-test==1846256==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0  in clang::cxstring::createRef(llvm::StringRef) llvm-project/clang/tools/libclang/CXString.cpp:96:36
    #1  in DumpCXCommentInternal llvm-project/clang/tools/c-index-test/c-index-test.c:521:39
    llvm#2  in DumpCXCommentInternal llvm-project/clang/tools/c-index-test/c-index-test.c:674:7
    llvm#3  in DumpCXCommentInternal llvm-project/clang/tools/c-index-test/c-index-test.c:674:7
    llvm#4  in DumpCXComment llvm-project/clang/tools/c-index-test/c-index-test.c:685:3
    llvm#5  in PrintCursorComments llvm-project/clang/tools/c-index-test/c-index-test.c:768:7

  Memory was marked as uninitialized
    #0  in __msan_allocated_memory llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:1023:5
    #1  in Allocate llvm-project/llvm/include/llvm/Support/Allocator.h:172:7
    llvm#2  in Allocate llvm-project/llvm/include/llvm/Support/Allocator.h:216:12
    llvm#3  in Allocate llvm-project/llvm/include/llvm/Support/AllocatorBase.h:53:43
    llvm#4  in Allocate<char> llvm-project/llvm/include/llvm/Support/AllocatorBase.h:76:29
    llvm#5  in convertCodePointToUTF8 llvm-project/clang/lib/AST/CommentLexer.cpp:42:30
    llvm#6  in clang::comments::Lexer::resolveHTMLDecimalCharacterReference(llvm::StringRef) const llvm-project/clang/lib/AST/CommentLexer.cpp:76:10
    llvm#7  in clang::comments::Lexer::lexHTMLCharacterReference(clang::comments::Token&) llvm-project/clang/lib/AST/CommentLexer.cpp:615:16
    llvm#8  in consumeToken llvm-project/clang/include/clang/AST/CommentParser.h:62:9
    llvm#9  in clang::comments::Parser::parseParagraphOrBlockCommand() llvm-project/clang/lib/AST/CommentParser.cpp
    llvm#10 in clang::comments::Parser::parseFullComment() llvm-project/clang/lib/AST/CommentParser.cpp:925:22
    llvm#11 in clang::RawComment::parse(clang::ASTContext const&, clang::Preprocessor const*, clang::Decl const*) const llvm-project/clang/lib/AST/RawCommentList.cpp:221:12
    llvm#12 in clang::ASTContext::getCommentForDecl(clang::Decl const*, clang::Preprocessor const*) const llvm-project/clang/lib/AST/ASTContext.cpp:714:35
    llvm#13 in clang_Cursor_getParsedComment llvm-project/clang/tools/libclang/CXComment.cpp:36:35
    llvm#14 in PrintCursorComments llvm-project/clang/tools/c-index-test/c-index-test.c:756:25
 ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant