Skip to content

Conversation

@Sh0g0-1758
Copy link
Member

Fixes : #69085 , #69200

PR SUMMARY: "Added Null check for negative sized array and a test for the same"

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels Feb 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2024

@llvm/pr-subscribers-clang

Author: Shourya Goel (Sh0g0-1758)

Changes

Fixes : #69085 , #69200

PR SUMMARY: "Added Null check for negative sized array and a test for the same"


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaOpenMP.cpp (+2)
  • (added) clang/test/OpenMP/bug69085.c (+10)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 1556f6e8546135..1f73fe6f8742e3 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -21124,6 +21124,8 @@ Sema::ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, ExprTy = ATy->getElementType(); else ExprTy = BaseType->getPointeeType(); + if (ExprTy.isNull()) + continue; ExprTy = ExprTy.getNonReferenceType(); const Expr *Length = OASE->getLength(); Expr::EvalResult Result; diff --git a/clang/test/OpenMP/bug69085.c b/clang/test/OpenMP/bug69085.c new file mode 100644 index 00000000000000..1017ea53b41e3d --- /dev/null +++ b/clang/test/OpenMP/bug69085.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -verify -O0 -fopenmp-simd %s + +int k[-1]; // expected-error {{'k' declared as an array with a negative size}} + +void foo() { + #pragma omp task depend(inout: k [:]) + { + k[0] = 1; + } +} 
@Sh0g0-1758 Sh0g0-1758 changed the title [Clang][OpenMP] Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed. [Clang][OpenMP] Fix `!isNull() && "Cannot retrieve a NULL type pointer"' fail. Feb 7, 2024
@jhuber6
Copy link
Contributor

jhuber6 commented Feb 7, 2024

I'll merge it for you once the CI builder finishes without issue, thanks.

else
ExprTy = BaseType->getPointeeType();
if (ExprTy.isNull())
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure to continue here is a good idea. Probably you want return nullptr;.

Copy link
Contributor

@jhuber6 jhuber6 Feb 7, 2024

Choose a reason for hiding this comment

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

We do continue above where we throw another error, so I figured it was fine. But you're right now that I look at it harder. We should do this instead. (Github reviews don't allow code suggestion on lines that aren't altered).

if (ExprTy.isNull()) return nullptr;

I think both are correct, but this is probably better. Thanks. Please make this small update. (Also just read that the ExprTy is later)

Copy link
Member Author

@Sh0g0-1758 Sh0g0-1758 Feb 7, 2024

Choose a reason for hiding this comment

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

done, and checked the build and tests locally.

@Sh0g0-1758
Copy link
Member Author

The build is failing because of a formatting error which I don't think is related to the changes that I made. Any thoughts as to why it is failing?

@jhuber6
Copy link
Contributor

jhuber6 commented Feb 7, 2024

The build is failing because of a formatting error which I don't think is related to the changes that I made. Any thoughts as to why it is failing?

That's unrelated, I'll fix it.

@Sh0g0-1758
Copy link
Member Author

Great, pre-commits tests passed.

@jhuber6 jhuber6 merged commit b89eb97 into llvm:main Feb 7, 2024
@Sh0g0-1758 Sh0g0-1758 deleted the 69085 branch February 7, 2024 19:54
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:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category

4 participants