Author: Timm Baeder
Date: 2024-08-06T16:19:56+02:00
New Revision: e958456840c1663b496e5ee4a44ce73ae780f50d

URL: 
https://github.com/llvm/llvm-project/commit/e958456840c1663b496e5ee4a44ce73ae780f50d
DIFF: 
https://github.com/llvm/llvm-project/commit/e958456840c1663b496e5ee4a44ce73ae780f50d.diff

LOG: [clang][Interp] Ignore ObjCBoxedExpr subexpr... (#102136)

... if it can't be expressed as a constant initializer.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Compiler.cpp
    clang/test/AST/Interp/objc.mm

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 02cbe38f5fb1f..95f4fe9bd0bec 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3161,10 +3161,11 @@ bool Compiler<Emitter>::VisitExtVectorElementExpr(
 
 template <class Emitter>
 bool Compiler<Emitter>::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
+  const Expr *SubExpr = E->getSubExpr();
   if (!E->isExpressibleAsConstantInitializer())
-    return this->emitInvalid(E);
+    return this->discard(SubExpr) && this->emitInvalid(E);
 
-  return this->delegate(E->getSubExpr());
+  return this->delegate(SubExpr);
 }
 
 template <class Emitter>

diff  --git a/clang/test/AST/Interp/objc.mm b/clang/test/AST/Interp/objc.mm
index 6402c8ae098fd..f6c4ba12dc5d1 100644
--- a/clang/test/AST/Interp/objc.mm
+++ b/clang/test/AST/Interp/objc.mm
@@ -11,3 +11,28 @@ @interface NSString
 @end
 constexpr NSString *t0 = @"abc";
 constexpr NSString *t1 = @("abc");
+
+
+#if __LP64__
+typedef unsigned long NSUInteger;
+typedef long NSInteger;
+#else
+typedef unsigned int NSUInteger;
+typedef int NSInteger;
+#endif
+
+
+@class NSNumber;
+
+
+@interface NSObject
++ (NSObject*)nsobject;
+@end
+
+@interface NSNumber : NSObject
++ (NSNumber *)numberWithInt:(int)value;
+@end
+
+int main(void) {
+  NSNumber *bv = @(1391126400 * 1000); // both-warning {{overflow in 
expression; result is -443'003'904 with type 'int'}}
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to