[clang] bc034ba - [clang][Interp] Protect InitPtr from non-initializable pointers
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 10 10:50:02 PST 2024
Author: Timm Bäder
Date: 2024-02-10T19:45:10+01:00
New Revision: bc034baaff1f6ce4e18b68c20df3be45bfb5104f
URL: https://github.com/llvm/llvm-project/commit/bc034baaff1f6ce4e18b68c20df3be45bfb5104f
DIFF: https://github.com/llvm/llvm-project/commit/bc034baaff1f6ce4e18b68c20df3be45bfb5104f.diff
LOG: [clang][Interp] Protect InitPtr from non-initializable pointers
This can happen when an initializer returns a dummy pointer.
Added:
clang/test/AST/Interp/complex.c
Modified:
clang/lib/AST/Interp/Interp.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 290edc07fdc87a..15c137098af355 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1278,13 +1278,16 @@ inline bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
inline bool InitPtrPop(InterpState &S, CodePtr OpPC) {
const Pointer &Ptr = S.Stk.pop<Pointer>();
- Ptr.initialize();
+ if (Ptr.canBeInitialized())
+ Ptr.initialize();
return true;
}
inline bool InitPtr(InterpState &S, CodePtr OpPC) {
const Pointer &Ptr = S.Stk.peek<Pointer>();
- Ptr.initialize();
+
+ if (Ptr.canBeInitialized())
+ Ptr.initialize();
return true;
}
diff --git a/clang/test/AST/Interp/complex.c b/clang/test/AST/Interp/complex.c
new file mode 100644
index 00000000000000..b07d0241da12d6
--- /dev/null
+++ b/clang/test/AST/Interp/complex.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -Wno-unused-value %s
+// RUN: %clang_cc1 -verify=ref,both -Wno-unused-value %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+void blah() {
+ __complex__ unsigned xx;
+ __complex__ signed yy;
+ __complex__ int result;
+
+ /// The following line calls into the constant interpreter.
+ result = xx * yy;
+}
More information about the cfe-commits
mailing list