Skip to content

Conversation

apach301
Copy link
Contributor

@apach301 apach301 commented Sep 8, 2025

Fixes #157452

@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-mlir-emitc

Author: Daniel Kuts (apach301)

Changes

Fixes #157452


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/EmitC/IR/EmitC.cpp (+5-1)
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index a73470cdf76c5..6b88e2c525d07 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -1320,7 +1320,11 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
 
   // global has non-array type
   auto lvalueType = dyn_cast<LValueType>(resultType);
-  if (!lvalueType || lvalueType.getValueType() != globalType)
+  if (!lvalueType)
+    return emitOpError("on non-array type result type is not defined "
+                       "for the global @")
+           << getName();
+  if (lvalueType.getValueType() != globalType)
     return emitOpError("on non-array type expects result inner type ")
            << lvalueType.getValueType() << " to match type " << globalType
            << " of the global @" << getName();

@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-mlir

Author: Daniel Kuts (apach301)

Changes

Fixes #157452


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/EmitC/IR/EmitC.cpp (+5-1)
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index a73470cdf76c5..6b88e2c525d07 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -1320,7 +1320,11 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
 
   // global has non-array type
   auto lvalueType = dyn_cast<LValueType>(resultType);
-  if (!lvalueType || lvalueType.getValueType() != globalType)
+  if (!lvalueType)
+    return emitOpError("on non-array type result type is not defined "
+                       "for the global @")
+           << getName();
+  if (lvalueType.getValueType() != globalType)
     return emitOpError("on non-array type expects result inner type ")
            << lvalueType.getValueType() << " to match type " << globalType
            << " of the global @" << getName();

Copy link
Contributor

@CoTinker CoTinker left a comment

Choose a reason for hiding this comment

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

Could you please add a test?

Copy link
Contributor

@simon-camp simon-camp left a comment

Choose a reason for hiding this comment

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

Thanks you for the fix.

Can you rephrase the Message to something like "... expects result type to be an lvalue type for the global ...". I think that gives a better hint on what is expected for users not familiär with the details of the Operation.

@apach301
Copy link
Contributor Author

apach301 commented Sep 9, 2025

Could you please add a test?

That was a static analyzer report, so I don't know how to run this code or have any input data. But the problem is that code is syntactically inconsistent: there is a check that ensures lvalueType is non-null and is of correct type. And if that check is failed - it tries to dereference lvalueType.

@apach301
Copy link
Contributor Author

Can you rephrase the Message to something like "... expects result type to be an lvalue type for the global ...". I think that gives a better hint on what is expected for users not familiär with the details of the Operation.

Done

@apach301 apach301 force-pushed the mlir-emitc-null-dereference branch from 6fa4e9e to 335e5bc Compare September 15, 2025 19:27
@apach301 apach301 force-pushed the mlir-emitc-null-dereference branch from 335e5bc to 1734346 Compare September 15, 2025 19:46
@apach301 apach301 requested a review from simon-camp September 15, 2025 21:04
@joker-eph joker-eph merged commit ad96f68 into llvm:main Sep 15, 2025
9 checks passed
@apach301 apach301 deleted the mlir-emitc-null-dereference branch September 15, 2025 21:06
kimsh02 pushed a commit to kimsh02/llvm-project that referenced this pull request Sep 19, 2025
itzexpoexpo pushed a commit to itzexpoexpo/llvm-project that referenced this pull request Sep 21, 2025
SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible NULL dereference in mlir/Dialect/EmitC/IR
5 participants