@@ -366,6 +366,39 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef mangledName, mlir::Type ty,
366366 CIRGenModule::createGlobalOp (*this , loc, mangledName, ty,
367367 /* insertPoint=*/ entry.getOperation ());
368368
369+ // Handle things which are present even on external declarations.
370+ if (d) {
371+ if (langOpts.OpenMP && !langOpts.OpenMPSimd )
372+ errorNYI (d->getSourceRange (), " OpenMP target global variable" );
373+
374+ gv.setAlignmentAttr (getSize (astContext.getDeclAlign (d)));
375+ assert (!cir::MissingFeatures::opGlobalConstant ());
376+ assert (!cir::MissingFeatures::opGlobalLinkage ());
377+
378+ if (d->getTLSKind ())
379+ errorNYI (d->getSourceRange (), " thread local global variable" );
380+
381+ assert (!cir::MissingFeatures::opGlobalDLLImportExport ());
382+ assert (!cir::MissingFeatures::opGlobalPartition ());
383+ assert (!cir::MissingFeatures::setDSOLocal ());
384+
385+ // If required by the ABI, treat declarations of static data members with
386+ // inline initializers as definitions.
387+ if (astContext.isMSStaticDataMemberInlineDefinition (d))
388+ errorNYI (d->getSourceRange (), " MS static data member inline definition" );
389+
390+ assert (!cir::MissingFeatures::opGlobalSection ());
391+ assert (!cir::MissingFeatures::opGlobalVisibility ());
392+
393+ // Handle XCore specific ABI requirements.
394+ if (getTriple ().getArch () == llvm::Triple::xcore)
395+ errorNYI (d->getSourceRange (), " XCore specific ABI requirements" );
396+
397+ // We need to check for external const declarations with initializers here,
398+ // but the 'isPublic()' part of the check uses the CIRGlobalValueInterface.
399+ assert (!cir::MissingFeatures::opGlobalCIRGlobalValueInterface ());
400+ }
401+
369402 return gv;
370403}
371404
@@ -775,7 +808,8 @@ CIRGenModule::getCIRLinkageVarDefinition(const VarDecl *vd, bool isConstant) {
775808
776809static cir::GlobalOp generateStringLiteral (mlir::Location loc,
777810 mlir::TypedAttr c, CIRGenModule &cgm,
778- StringRef globalName) {
811+ StringRef globalName,
812+ CharUnits alignment) {
779813 assert (!cir::MissingFeatures::addressSpace ());
780814
781815 // Create a global variable for this string
@@ -784,7 +818,7 @@ static cir::GlobalOp generateStringLiteral(mlir::Location loc,
784818 CIRGenModule::createGlobalOp (cgm, loc, globalName, c.getType ());
785819
786820 // Set up extra information and add to the module
787- assert (! cir::MissingFeatures::opGlobalAlignment ( ));
821+ gv. setAlignmentAttr (cgm. getSize (alignment ));
788822 assert (!cir::MissingFeatures::opGlobalLinkage ());
789823 assert (!cir::MissingFeatures::opGlobalThreadLocal ());
790824 assert (!cir::MissingFeatures::opGlobalUnnamedAddr ());
@@ -821,6 +855,9 @@ std::string CIRGenModule::getUniqueGlobalName(const std::string &baseName) {
821855// / Return a pointer to a constant array for the given string literal.
822856cir::GlobalOp CIRGenModule::getGlobalForStringLiteral (const StringLiteral *s,
823857 StringRef name) {
858+ CharUnits alignment =
859+ astContext.getAlignOfGlobalVarInChars (s->getType (), /* VD=*/ nullptr );
860+
824861 mlir::Attribute c = getConstantArrayFromStringLiteral (s);
825862
826863 if (getLangOpts ().WritableStrings ) {
@@ -842,8 +879,8 @@ cir::GlobalOp CIRGenModule::getGlobalForStringLiteral(const StringLiteral *s,
842879 std::string uniqueName = getUniqueGlobalName (name.str ());
843880 mlir::Location loc = getLoc (s->getSourceRange ());
844881 auto typedC = llvm::cast<mlir::TypedAttr>(c);
845- assert (! cir::MissingFeatures::opGlobalAlignment ());
846- cir::GlobalOp gv = generateStringLiteral (loc, typedC, *this , uniqueName);
882+ cir::GlobalOp gv =
883+ generateStringLiteral (loc, typedC, *this , uniqueName, alignment );
847884 assert (!cir::MissingFeatures::opGlobalDSOLocal ());
848885
849886 assert (!cir::MissingFeatures::sanitizers ());
@@ -918,7 +955,7 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
918955void CIRGenModule::setInitializer (cir::GlobalOp &op, mlir::Attribute value) {
919956 // Recompute visibility when updating initializer.
920957 op.setInitialValueAttr (value);
921- assert (!cir::MissingFeatures::opGlobalSetVisitibility ());
958+ assert (!cir::MissingFeatures::opGlobalVisibility ());
922959}
923960
924961cir::FuncOp CIRGenModule::getAddrOfFunction (clang::GlobalDecl gd,
0 commit comments