Author: Timm Baeder Date: 2026-03-28T05:52:23+01:00 New Revision: cb8b65e3206ee9c054500d3852f9e972b62179bc
URL: https://github.com/llvm/llvm-project/commit/cb8b65e3206ee9c054500d3852f9e972b62179bc DIFF: https://github.com/llvm/llvm-project/commit/cb8b65e3206ee9c054500d3852f9e972b62179bc.diff LOG: [clang][bytecode] Add support for objc array- and dictionary literals (#189058) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Compiler.h clang/test/CodeGenObjC/no-nsconstant-literals.m clang/test/CodeGenObjC/objc2-constant-collection-literals.m Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index aa3aa6854247d..c7f074c9efc6a 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4227,6 +4227,21 @@ bool Compiler<Emitter>::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { return true; } +template <class Emitter> +bool Compiler<Emitter>::VisitObjCDictionaryLiteral( + const ObjCDictionaryLiteral *E) { + if (E->isExpressibleAsConstantInitializer()) + return this->emitDummyPtr(E, E); + return this->emitError(E); +} + +template <class Emitter> +bool Compiler<Emitter>::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { + if (E->isExpressibleAsConstantInitializer()) + return this->emitDummyPtr(E, E); + return this->emitError(E); +} + template <class Emitter> bool Compiler<Emitter>::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { assert(Ctx.getLangOpts().CPlusPlus); diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index f867fcc9fcbaa..cd14f72b87f9f 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -230,6 +230,8 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>, bool VisitCXXDeleteExpr(const CXXDeleteExpr *E); bool VisitBlockExpr(const BlockExpr *E); bool VisitCXXTypeidExpr(const CXXTypeidExpr *E); + bool VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); + bool VisitObjCArrayLiteral(const ObjCArrayLiteral *E); // Statements. bool visitCompoundStmt(const CompoundStmt *S); diff --git a/clang/test/CodeGenObjC/no-nsconstant-literals.m b/clang/test/CodeGenObjC/no-nsconstant-literals.m index 8a10869f48528..bcf2056945544 100644 --- a/clang/test/CodeGenObjC/no-nsconstant-literals.m +++ b/clang/test/CodeGenObjC/no-nsconstant-literals.m @@ -1,9 +1,15 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -fobjc-runtime=macosx-10.14.0 -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck --check-prefix CHECK-ALL-DISABLED %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -fobjc-runtime=macosx-10.14.0 -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s -fexperimental-new-constant-interpreter | FileCheck --check-prefix CHECK-ALL-DISABLED %s // RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck --check-prefix CHECK-ALL-DISABLED-CONST-ON %s // RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck --check-prefix CHECK-NUMBERS-DISABLED %s // RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s | FileCheck --check-prefix CHECK-DICT-DISABLED %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s -fexperimental-new-constant-interpreter | FileCheck --check-prefix CHECK-ALL-DISABLED-CONST-ON %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s -fexperimental-new-constant-interpreter | FileCheck --check-prefix CHECK-NUMBERS-DISABLED %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -I %S/Inputs -emit-llvm -no-enable-noundef-analysis -o - %s -fexperimental-new-constant-interpreter | FileCheck --check-prefix CHECK-DICT-DISABLED %s + + #if __has_feature(objc_bool) #define YES __objc_yes #define NO __objc_no diff --git a/clang/test/CodeGenObjC/objc2-constant-collection-literals.m b/clang/test/CodeGenObjC/objc2-constant-collection-literals.m index acc9004fdad57..792d9241b8d92 100644 --- a/clang/test/CodeGenObjC/objc2-constant-collection-literals.m +++ b/clang/test/CodeGenObjC/objc2-constant-collection-literals.m @@ -2,6 +2,12 @@ // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK // RUN: %clang_cc1 -triple arm64-apple-ios14.0 -fobjc-runtime=ios-14.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK +// RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix=CHECK +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-macosx11.0.0 -fobjc-runtime=macosx-11.0.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix=CHECK +// RUN: %clang_cc1 -triple arm64-apple-ios14.0 -fobjc-runtime=ios-14.0 -fobjc-constant-literals -fconstant-nsnumber-literals -fconstant-nsarray-literals -fconstant-nsdictionary-literals -I %S/Inputs -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix=CHECK + + + #if __has_feature(objc_constant_literals) #if __has_feature(objc_bool) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
