From a210f350fa78c263caa26e0f999cce85bb235309 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 7 Mar 2009 20:17:55 +0000 Subject: [PATCH] Make constant emission for @encode use the common string emission code. This is a bit cleaner, and also "fixes" bad code that compares the addresses of the string constants. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66346 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 8 ++------ test/CodeGenObjC/encode-test-4.m | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 test/CodeGenObjC/encode-test-4.m diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 95d881bc49..16ba94791f 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1132,12 +1132,8 @@ llvm::Constant * CodeGenModule::GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *E) { std::string Str; getContext().getObjCEncodingForType(E->getEncodedType(), Str); - - llvm::Constant *C = llvm::ConstantArray::get(Str); - C = new llvm::GlobalVariable(C->getType(), true, - llvm::GlobalValue::InternalLinkage, - C, ".str", &getModule()); - return C; + + return GetAddrOfConstantCString(Str); } diff --git a/test/CodeGenObjC/encode-test-4.m b/test/CodeGenObjC/encode-test-4.m new file mode 100644 index 0000000000..4d39a532d2 --- /dev/null +++ b/test/CodeGenObjC/encode-test-4.m @@ -0,0 +1,5 @@ +// RUN: clang -emit-llvm -o - %s -O2 | grep "ret i32 1" + +int a() { + return @encode(int) == @encode(int); +}