[PATCH] D133267: [Verifier] Reject dllexport with non-default visibility

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 3 22:18:46 PDT 2022


MaskRay created this revision.
MaskRay added reviewers: mstorsjo, mati865, rnk, DiggerLin, daltenty.
Herald added subscribers: StephenFan, hiraditya, nemanjai.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add a visibility check for dllimport and dllexport. Note: dllimport with a
non-default visibility (implicit dso_local) is already rejected, but with a less
clear dso_local error.

The MC level visibility `MCSA_Exported` (D123951 <https://reviews.llvm.org/D123951>) is mapped from IR level
default visibility when dllexport is specified. The D123951 <https://reviews.llvm.org/D123951> error is now very
difficult to trigger (needs to disable the IR verifier).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133267

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/CodeGen/PowerPC/aix-xcoff-exported-nondefault.ll
  llvm/test/Feature/globalvars.ll


Index: llvm/test/Feature/globalvars.ll
===================================================================
--- llvm/test/Feature/globalvars.ll
+++ llvm/test/Feature/globalvars.ll
@@ -16,5 +16,5 @@
         ret i32 %blah
 }
 
- at 1 = hidden dllexport global i32 42
+ at 1 = default dllexport global i32 42
 @2 = dllexport global i32 42
Index: llvm/test/CodeGen/PowerPC/aix-xcoff-exported-nondefault.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/aix-xcoff-exported-nondefault.ll
+++ llvm/test/CodeGen/PowerPC/aix-xcoff-exported-nondefault.ll
@@ -1,15 +1,5 @@
-; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff 2>&1 < %s | \
-; RUN:   FileCheck %s
-; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff 2>&1 < %s |\
-; RUN:   FileCheck %s
+; RUN: not llc -filetype=null -mtriple powerpc-ibm-aix-xcoff 2>&1 %s | FileCheck %s
+; RUN: not llc -filetype=null -mtriple powerpc64-ibm-aix-xcoff 2>&1 %s | FileCheck %s
 
-; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff \
-; RUN:     -filetype=obj -o %t.o < %s 2>&1 | \
-; RUN:   FileCheck %s
-
-; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \
-; RUN:     -filetype=obj -o %t.o 2>&1 < %s 2>&1 | \
-; RUN:   FileCheck %s
-
-; CHECK: LLVM ERROR: Cannot not be both dllexport and non-default visibility
+; CHECK: dllexport GlobalValue must have default visibility
 @b_e = hidden dllexport global i32 0, align 4
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -663,7 +663,13 @@
   if (GV.isDeclarationForLinker())
     Check(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV);
 
+  if (GV.hasDLLExportStorageClass()) {
+    Check(GV.hasDefaultVisibility(),
+          "dllexport GlobalValue must have default visibility", &GV);
+  }
   if (GV.hasDLLImportStorageClass()) {
+    Check(GV.hasDefaultVisibility(),
+          "dllimport GlobalValue must have default visibility", &GV);
     Check(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!",
           &GV);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133267.457832.patch
Type: text/x-patch
Size: 2200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220904/6c43a836/attachment.bin>


More information about the llvm-commits mailing list