-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathllvm-14.patch
838 lines (747 loc) · 33.9 KB
/
llvm-14.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
From 8234a03c1bdc61c75d1c55e0305fa42648573d81 Mon Sep 17 00:00:00 2001
From: vmihalko <[email protected]>
Date: Tue, 3 May 2022 13:28:38 +0200
Subject: [PATCH 1/3] cmake: LLVM 14 requires C as a project language
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Lukáš Zaoral <[email protected]>
Co-authored-by: Vincent Mihalkovic <[email protected]>
---
CMakeLists.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm2c/CMakeLists.txt b/llvm2c/CMakeLists.txt
index eb849b9..b921002 100644
--- a/llvm2c/CMakeLists.txt
+++ b/llvm2c/CMakeLists.txt
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.1)
-project(llvm2c CXX)
+
+# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
+# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
+project(llvm2c LANGUAGES C CXX)
# --------------------------------------------------
# Build type
From 47d6f616eaf37233a2049743ceec64ae46f04db4 Mon Sep 17 00:00:00 2001
From: vmihalko <[email protected]>
Date: Tue, 3 May 2022 13:31:58 +0200
Subject: [PATCH 2/3] llvm14: PointerType::getElementType() was deprecated
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
... for LLVM 14 in [1] and has already been removed from the LLVM 15
branch in [2].
Some changes are only temporary to silence the warning though, as
Type::getPointerElementType() is planned to be removed as well. [3]
[1] https://reviews.llvm.org/D117885/new/
[2] llvm/llvm-project@d593cf7
[3] https://llvm.org/docs/OpaquePointers.html#migration-instructions
Co-authored-by: Lukáš Zaoral <[email protected]>
Co-authored-by: Vincent Mihalkovic <[email protected]>
---
parser/computeGlobalVarsOrder.cpp | 4 +---
parser/createExpressions.cpp | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/llvm2c/parser/computeGlobalVarsOrder.cpp b/llvm2c/parser/computeGlobalVarsOrder.cpp
index 567a0ce..0302e3f 100644
--- a/llvm2c/parser/computeGlobalVarsOrder.cpp
+++ b/llvm2c/parser/computeGlobalVarsOrder.cpp
@@ -32,9 +32,7 @@ static void parseGlobalVar(const llvm::GlobalVariable& gvar, Program& program) {
program.globalVarNames.insert(gvarName);
}
- llvm::PointerType* PT = llvm::cast<llvm::PointerType>(gvar.getType());
-
- auto type = program.getType(PT->getElementType());
+ auto type = program.getType(gvar.getValueType());
if (!type)
assert(false && "Unable to determine global variable type");
diff --git a/llvm2c/parser/createExpressions.cpp b/llvm2c/parser/createExpressions.cpp
index fc95d4a..be3444f 100644
--- a/llvm2c/parser/createExpressions.cpp
+++ b/llvm2c/parser/createExpressions.cpp
@@ -114,7 +114,7 @@ static void createFuncCallParam(const llvm::Use& param, Program& program) {
if (llvm::PointerType* PT = llvm::dyn_cast_or_null<llvm::PointerType>(param->getType())) {
if (llvm::isa<llvm::ConstantPointerNull>(param)) {
program.exprMap[param] = createConstantValue(param, program);
- } else if (PT->getElementType()->isFunctionTy() && !param->getName().empty()) {
+ } else if (PT->getPointerElementType()->isFunctionTy() && !param->getName().empty()) {
auto val = std::make_unique<Value>(param->getName().str(), program.typeHandler.voidType.get());
program.exprMap[param] = program.addOwnership(std::move(val));
} else {
From 1d41236c910c8e11dea54c40e6ee9917242e9954 Mon Sep 17 00:00:00 2001
From: vmihalko <[email protected]>
Date: Tue, 3 May 2022 13:49:52 +0200
Subject: [PATCH 3/3] llvm14: CallInst::arg_operands was removed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
... we creater a static inline wrapper function to
preserve compatibility with older LLVM versions
Co-authored-by: Lukáš Zaoral <[email protected]>
Co-authored-by: Vincent Mihalkovic <[email protected]>
---
parser/createExpressions.cpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/llvm2c/parser/createExpressions.cpp b/llvm2c/parser/createExpressions.cpp
index be3444f..94751da 100644
--- a/llvm2c/parser/createExpressions.cpp
+++ b/llvm2c/parser/createExpressions.cpp
@@ -5,6 +5,7 @@
#include "cfunc.h"
#include "compare.h"
+#include <llvm/ADT/iterator_range.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IntrinsicInst.h>
@@ -55,6 +56,15 @@ static std::unordered_set<int> read_only = {
Expr* parseLLVMInstruction(const llvm::Instruction& ins, Program& program);
static void parseInlineASM(const llvm::Instruction& ins, Func* func, Block* block);
+// FIXME: Remove this when LLVM 8 is the minimal version for LLVM2C!
+static inline llvm::iterator_range<llvm::User::op_iterator> args_wrapper(llvm::CallInst *CI) {
+ return make_range(CI->arg_begin(), CI->arg_end());
+}
+
+static inline llvm::iterator_range<llvm::User::const_op_iterator> args_wrapper(const llvm::CallInst *CI) {
+ return make_range(CI->arg_begin(), CI->arg_end());
+}
+
const llvm::Instruction *getNextNonDebugInstruction(const llvm::Instruction *ins) {
#if LLVM_VERSION_MAJOR > 6
return ins->getNextNonDebugInstruction();
@@ -730,7 +740,7 @@ static void parseCallInstruction(const llvm::Instruction& ins, Func* func, Block
}
int i = 0;
- for (const llvm::Use& param : callInst->arg_operands()) {
+ for (const llvm::Use& param : args_wrapper(callInst)) {
//sometimes LLVM uses these functions with more arguments than their C counterparts
if ((funcName.compare("memcpy") == 0 || funcName.compare("memmove") == 0 || funcName.compare("memset") == 0) && i == 3) {
break;
@@ -830,7 +840,7 @@ static void parseInlineASM(const llvm::Instruction& ins, Func* func, Block* bloc
}
std::vector<Expr*> args;
- for (const llvm::Use& arg : callInst->arg_operands()) {
+ for (const llvm::Use& arg : args_wrapper(callInst)) {
if (!func->getExpr(arg.get())) {
createFuncCallParam(arg, *func->program);
}
From 7242470fb66d72f2edfc53c2e85199a86a31cc40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Tue, 3 May 2022 21:13:41 +0200
Subject: [PATCH] cmake: LLVM 14 requires C as a project language
... due to a bug.
See: https://github.com/llvm/llvm-project/issues/53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
/usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
CMakeLists.txt:31 (find_package)
---
CMakeLists.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sbt-slicer/CMakeLists.txt b/sbt-slicer/CMakeLists.txt
index a1b0ad8..2eec431 100644
--- a/sbt-slicer/CMakeLists.txt
+++ b/sbt-slicer/CMakeLists.txt
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.1.0)
-project(sbt-slicer CXX)
+
+# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
+# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
+project(sbt-slicer LANGUAGES C CXX)
# --------------------------------------------------
# Build type
From 3fea5999f343e25dc562fa1d8dcfed516e9d6c59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Sat, 19 Feb 2022 13:49:38 +0100
Subject: [PATCH 2/3] cmake: LLVM 14 requires C as a project language
... due to a bug.
See: https://github.com/llvm/llvm-project/issues/53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
/usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
CMakeLists.txt:31 (find_package)
---
CMakeLists.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dg/tools/llvm-slicer-metadata.cpp b/dg/tools/llvm-slicer-metadata.cpp
index ce08442..d238f1a 100644
--- a/dg/tools/llvm-slicer-metadata.cpp
+++ b/dg/tools/llvm-slicer-metadata.cpp
@@ -6,6 +6,8 @@
#include "dg/tools/llvm-slicer-utils.h"
+#include <map>
+
using MapTy = std::map<const llvm::Value *, CVariableDecl>;
// create the mapping from LLVM values to C variable names
diff --git a/dg/CMakeLists.txt b/dg/CMakeLists.txt
index 4248dfe63..f13e07762 100644
--- a/dg/CMakeLists.txt
+++ b/dg/CMakeLists.txt
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.1)
-project(dg CXX)
+
+# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
+# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
+project(dg LANGUAGES C CXX)
include(CTest)
From 2915acc8b4fac6eae42ef86119a2796677449cad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Tue, 3 May 2022 12:43:58 +0200
Subject: [PATCH 3/3] llvm14: CallBase::getNumArgOperands was removed
---
include/dg/llvm/CallGraph/CallGraph.h | 13 ++++--
lib/llvm/PointerAnalysis/Interprocedural.cpp | 12 ++---
lib/llvm/PointerAnalysis/PointerAnalysis.cpp | 6 +--
lib/llvm/ReadWriteGraph/Calls.cpp | 10 ++---
.../SystemDependenceGraph.cpp | 8 ++--
lib/llvm/ValueRelations/StructureAnalyzer.cpp | 4 +-
lib/llvm/llvm-utils.h | 45 ++++++++++++++++---
tools/llvm-pta-ben.cpp | 6 ++-
8 files changed, 76 insertions(+), 28 deletions(-)
diff --git a/dg/include/dg/llvm/ValueRelations/StructureAnalyzer.h b/dg/include/dg/llvm/ValueRelations/StructureAnalyzer.h
index 1c7181a..b9b9a89 100644
--- a/dg/include/dg/llvm/ValueRelations/StructureAnalyzer.h
+++ b/dg/include/dg/llvm/ValueRelations/StructureAnalyzer.h
@@ -793,7 +793,7 @@ class StructureAnalyzer {
// set formal parameters equal to real
unsigned argCount = 0;
for (const llvm::Argument &receivedArg : function.args()) {
- if (argCount > call->getNumArgOperands())
+ if (argCount > call->arg_size())
break;
const llvm::Value *sentArg = call->getArgOperand(argCount);
diff --git a/dg/include/dg/llvm/CallGraph/CallGraph.h b/dg/include/dg/llvm/CallGraph/CallGraph.h
index 7e5bb005e..7e20a7a38 100644
--- a/dg/include/dg/llvm/CallGraph/CallGraph.h
+++ b/dg/include/dg/llvm/CallGraph/CallGraph.h
@@ -135,14 +135,20 @@ callIsCompatible(const llvm::Function *F, const llvm::CallInst *CI,
CallCompatibility policy = CallCompatibility::LOOSE) {
using namespace llvm;
+#if LLVM_VERSION_MAJOR >= 8
+ auto max_idx = CI->arg_size();
+#else
+ auto max_idx = CI->getNumArgOperands();
+#endif
+
if (policy != CallCompatibility::MATCHING_ARGS) {
if (F->isVarArg()) {
- if (F->arg_size() > CI->getNumArgOperands()) {
+ if (F->arg_size() > max_idx) {
return false;
}
- } else if (F->arg_size() != CI->getNumArgOperands()) {
+ } else if (F->arg_size() != max_idx) {
if (policy == CallCompatibility::STRICT ||
- F->arg_size() > CI->getNumArgOperands()) {
+ F->arg_size() > max_idx) {
// too few arguments
return false;
}
@@ -159,7 +165,6 @@ callIsCompatible(const llvm::Function *F, const llvm::CallInst *CI,
}
size_t idx = 0;
- auto max_idx = CI->getNumArgOperands();
for (auto A = F->arg_begin(), E = F->arg_end(); idx < max_idx && A != E;
++A, ++idx) {
Type *CTy = CI->getArgOperand(idx)->getType();
diff --git a/dg/lib/llvm/PointerAnalysis/Interprocedural.cpp b/dg/lib/llvm/PointerAnalysis/Interprocedural.cpp
index d44476c59..946234f3a 100644
--- a/dg/lib/llvm/PointerAnalysis/Interprocedural.cpp
+++ b/dg/lib/llvm/PointerAnalysis/Interprocedural.cpp
@@ -12,12 +12,14 @@
#include "dg/llvm/PointerAnalysis/PointerGraph.h"
+#include "llvm/llvm-utils.h"
+
namespace dg {
namespace pta {
void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst *CI,
PSNode *arg, unsigned idx) {
- assert(idx < CI->getNumArgOperands());
+ assert(idx < llvmutils::getNumArgOperands(CI));
PSNode *op = tryGetOperand(CI->getArgOperand(idx));
if (op && !arg->hasOperand(op)) {
// NOTE: do not add an operand multiple-times
@@ -29,9 +31,8 @@ void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst *CI,
void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst &CI,
PSNode &node) {
- auto sentinel = CI.getNumArgOperands();
- for (unsigned i = 0; i < sentinel; ++i) {
- PSNode *operand = tryGetOperand(CI.getArgOperand(i));
+ for (const auto &arg : llvmutils::args(CI)) {
+ PSNode *operand = tryGetOperand(arg);
if (operand && !node.hasOperand(operand)) {
node.addOperand(operand);
}
@@ -75,7 +76,8 @@ void LLVMPointerGraphBuilder::addArgumentsOperands(const llvm::Function *F,
void LLVMPointerGraphBuilder::addVariadicArgumentOperands(
const llvm::Function *F, const llvm::CallInst *CI, PSNode *arg) {
- for (unsigned idx = F->arg_size() - 1; idx < CI->getNumArgOperands(); ++idx)
+ for (unsigned idx = F->arg_size() - 1;
+ idx < llvmutils::getNumArgOperands(CI); ++idx)
addArgumentOperands(CI, arg, idx);
}
diff --git a/dg/lib/llvm/PointerAnalysis/PointerAnalysis.cpp b/dg/lib/llvm/PointerAnalysis/PointerAnalysis.cpp
index af5bc6d4d..62d01c3bf 100644
--- a/dg/lib/llvm/PointerAnalysis/PointerAnalysis.cpp
+++ b/dg/lib/llvm/PointerAnalysis/PointerAnalysis.cpp
@@ -73,9 +73,9 @@ LLVMPointerAnalysis::getAccessedMemory(const llvm::Instruction *I) {
// check which operands are pointers and get the information for them
bool hasUnknown = false;
- for (unsigned i = 0; i < CI->getNumArgOperands(); ++i) {
- if (hasPointsTo(CI->getArgOperand(i))) {
- auto tmp = getLLVMPointsToChecked(CI->getArgOperand(i));
+ for (const auto &arg : llvmutils::args(CI)) {
+ if (hasPointsTo(arg)) {
+ auto tmp = getLLVMPointsToChecked(arg);
hasUnknown |= tmp.first;
// translate to regions
for (const auto &ptr : tmp.second) {
diff --git a/dg/lib/llvm/ReadWriteGraph/Calls.cpp b/dg/lib/llvm/ReadWriteGraph/Calls.cpp
index d191dca18..2a35f537c 100644
--- a/dg/lib/llvm/ReadWriteGraph/Calls.cpp
+++ b/dg/lib/llvm/ReadWriteGraph/Calls.cpp
@@ -111,12 +111,10 @@ LLVMReadWriteGraphBuilder::createUnknownCall(const llvm::CallInst *CInst) {
// every pointer we pass into the undefined call may be defined
// in the function
- for (unsigned int i = 0; i < CInst->getNumArgOperands(); ++i) {
- const Value *llvmOp = CInst->getArgOperand(i);
-
+ for (const auto &arg : llvmutils::args(CInst)) {
// constants cannot be redefined except for global variables
// (that are constant, but may point to non constant memory
- const Value *strippedValue = llvmOp->stripPointerCasts();
+ const Value *strippedValue = arg->stripPointerCasts();
if (isa<Constant>(strippedValue)) {
const GlobalVariable *GV = dyn_cast<GlobalVariable>(strippedValue);
// if the constant is not global variable,
@@ -125,7 +123,7 @@ LLVMReadWriteGraphBuilder::createUnknownCall(const llvm::CallInst *CInst) {
continue;
}
- auto pts = PTA->getLLVMPointsToChecked(llvmOp);
+ auto pts = PTA->getLLVMPointsToChecked(arg);
// if we do not have a pts, this is not pointer
// relevant instruction. We must do it this way
// instead of type checking, due to the inttoptr.
@@ -275,7 +273,7 @@ RWNode *LLVMReadWriteGraphBuilder::funcFromModel(const FunctionModel *model,
const llvm::CallInst *CInst) {
RWNode *node = &create(RWNodeType::GENERIC);
- for (unsigned int i = 0; i < CInst->getNumArgOperands(); ++i) {
+ for (unsigned int i = 0; i < llvmutils::getNumArgOperands(CInst); ++i) {
if (!model->handles(i))
continue;
diff --git a/dg/lib/llvm/SystemDependenceGraph/SystemDependenceGraph.cpp b/dg/lib/llvm/SystemDependenceGraph/SystemDependenceGraph.cpp
index cb867a3b1..5d1889e2d 100644
--- a/dg/lib/llvm/SystemDependenceGraph/SystemDependenceGraph.cpp
+++ b/dg/lib/llvm/SystemDependenceGraph/SystemDependenceGraph.cpp
@@ -1,6 +1,8 @@
#include "dg/llvm/SystemDependenceGraph/SystemDependenceGraph.h"
#include "dg/util/debug.h"
+#include "llvm/llvm-utils.h"
+
namespace dg {
namespace llvmdg {
@@ -49,9 +51,9 @@ struct SDGBuilder {
// create actual parameters
auto ¶ms = node.getParameters();
- for (unsigned i = 0; i < CI->getNumArgOperands(); ++i) {
- auto *A = CI->getArgOperand(i);
- llvm::errs() << "Act: " << *A << "\n";
+
+ for (const auto &arg : llvmutils::args(CI)) {
+ llvm::errs() << "Act: " << *arg << "\n";
params.createParameter();
}
return node;
diff --git a/dg/lib/llvm/llvm-utils.h b/dg/lib/llvm/llvm-utils.h
index 4c6fa0392..346f20633 100644
--- a/dg/lib/llvm/llvm-utils.h
+++ b/dg/lib/llvm/llvm-utils.h
@@ -1,12 +1,14 @@
#ifndef DG_LLVM_UTILS_H_
#define DG_LLVM_UTILS_H_
+#include <llvm/ADT/iterator_range.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/IntrinsicInst.h>
+#include <llvm/Support/raw_ostream.h>
#include "dg/Offset.h"
@@ -15,6 +17,39 @@ namespace llvmutils {
using namespace llvm;
+/* ----------------------------------------------
+ * -- COMPAT
+ * ---------------------------------------------- */
+
+// FIXME: Remove this when LLVM 8 is the minimal version for DG!
+inline iterator_range<User::op_iterator> args(CallInst *CI) {
+ return make_range(CI->arg_begin(), CI->arg_end());
+}
+
+inline iterator_range<User::const_op_iterator> args(const CallInst *CI) {
+ return make_range(CI->arg_begin(), CI->arg_end());
+}
+
+inline iterator_range<User::op_iterator> args(CallInst &CI) {
+ return args(&CI);
+}
+
+inline iterator_range<User::const_op_iterator> args(const CallInst &CI) {
+ return args(&CI);
+}
+
+inline unsigned getNumArgOperands(const CallInst *CI) {
+#if LLVM_VERSION_MAJOR >= 8
+ return CI->arg_size();
+#else
+ return CI->getNumArgOperands();
+#endif
+}
+
+inline unsigned getNumArgOperands(const CallInst &CI) {
+ return getNumArgOperands(&CI);
+}
+
/* ----------------------------------------------
* -- PRINTING
* ---------------------------------------------- */
@@ -57,14 +92,15 @@ callIsCompatible(const Function *F, const CallInst *CI,
CallCompatibility policy = CallCompatibility::LOOSE) {
using namespace llvm;
+ auto ci_arg_size = getNumArgOperands(CI);
if (policy != CallCompatibility::MATCHING_ARGS) {
if (F->isVarArg()) {
- if (F->arg_size() > CI->getNumArgOperands()) {
+ if (F->arg_size() > ci_arg_size) {
return false;
}
- } else if (F->arg_size() != CI->getNumArgOperands()) {
+ } else if (F->arg_size() != ci_arg_size) {
if (policy == CallCompatibility::STRICT ||
- F->arg_size() > CI->getNumArgOperands()) {
+ F->arg_size() > ci_arg_size) {
// too few arguments
return false;
}
@@ -81,8 +117,7 @@ callIsCompatible(const Function *F, const CallInst *CI,
}
size_t idx = 0;
- auto max_idx = CI->getNumArgOperands();
- for (auto A = F->arg_begin(), E = F->arg_end(); idx < max_idx && A != E;
+ for (auto A = F->arg_begin(), E = F->arg_end(); idx < ci_arg_size && A != E;
++A, ++idx) {
Type *CTy = CI->getArgOperand(idx)->getType();
Type *ATy = A->getType();
diff --git a/dg/tools/llvm-pta-ben.cpp b/dg/tools/llvm-pta-ben.cpp
index cfc07a3b7..ff804edee 100644
--- a/dg/tools/llvm-pta-ben.cpp
+++ b/dg/tools/llvm-pta-ben.cpp
@@ -30,6 +30,8 @@
#include "dg/tools/TimeMeasure.h"
+#include "llvm/llvm-utils.h"
+
using namespace dg;
using namespace dg::pta;
using dg::debug::TimeMeasure;
@@ -247,8 +249,10 @@ static void evalPSNode(DGLLVMPointerAnalysis *pta, PSNode *node) {
const llvm::Function *called = llvm::cast<llvm::Function>(v);
const llvm::StringRef &fun = called->getName();
- if (call->getNumArgOperands() != 2)
+
+ if (llvmutils::getNumArgOperands(call) != 2)
return;
+
if (!test_checkfunc(fun))
return;
From 6e2843e01065602ec11d7fa5c1d50660640f7443 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Sat, 5 Mar 2022 13:48:35 +0100
Subject: [PATCH 3/5] Module/InstructionOperandTypeCheckPass: Fix
-Wbitwise-instead-of-logical warning
This warning was introduced in Clang 14.
---
lib/Module/InstructionOperandTypeCheckPass.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/klee/lib/Module/InstructionOperandTypeCheckPass.cpp b/klee/lib/Module/InstructionOperandTypeCheckPass.cpp
index 5f428471c1..e67f051c15 100644
--- a/klee/lib/Module/InstructionOperandTypeCheckPass.cpp
+++ b/klee/lib/Module/InstructionOperandTypeCheckPass.cpp
@@ -94,7 +94,7 @@ bool checkInstruction(const Instruction *i) {
// scalarizer pass might not remove these. This could be selecting which
// vector operand to feed to another instruction. The Executor can handle
// this so case so this is not a problem
- return checkOperandTypeIsScalarInt(i, 0) &
+ return checkOperandTypeIsScalarInt(i, 0) &&
checkOperandsHaveSameType(i, 1, 2);
}
// Integer arithmetic, logical and shifting
@@ -111,12 +111,12 @@ bool checkInstruction(const Instruction *i) {
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr: {
- return checkOperandTypeIsScalarInt(i, 0) &
+ return checkOperandTypeIsScalarInt(i, 0) &&
checkOperandTypeIsScalarInt(i, 1);
}
// Integer comparison
case Instruction::ICmp: {
- return checkOperandTypeIsScalarIntOrPointer(i, 0) &
+ return checkOperandTypeIsScalarIntOrPointer(i, 0) &&
checkOperandTypeIsScalarIntOrPointer(i, 1);
}
// Integer Conversion
@@ -136,7 +136,7 @@ bool checkInstruction(const Instruction *i) {
case Instruction::FMul:
case Instruction::FDiv:
case Instruction::FRem: {
- return checkOperandTypeIsScalarFloat(i, 0) &
+ return checkOperandTypeIsScalarFloat(i, 0) &&
checkOperandTypeIsScalarFloat(i, 1);
}
// Floating point conversion
@@ -152,7 +152,7 @@ bool checkInstruction(const Instruction *i) {
}
// Floating point comparison
case Instruction::FCmp: {
- return checkOperandTypeIsScalarFloat(i, 0) &
+ return checkOperandTypeIsScalarFloat(i, 0) &&
checkOperandTypeIsScalarFloat(i, 1);
}
default:
From 8f006a41e27ea667943b15a61692fb8e90921a9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Sat, 5 Mar 2022 14:08:11 +0100
Subject: [PATCH 4/5] llvm14: TargetRegistry.h was moved from Support to MC
---
lib/Module/RaiseAsm.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/klee/lib/Module/RaiseAsm.cpp b/klee/lib/Module/RaiseAsm.cpp
index 248b434460..972a74b300 100644
--- a/klee/lib/Module/RaiseAsm.cpp
+++ b/klee/lib/Module/RaiseAsm.cpp
@@ -18,7 +18,11 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Host.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(14, 0)
+#include "llvm/MC/TargetRegistry.h"
+#else
#include "llvm/Support/TargetRegistry.h"
+#endif
#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Target/TargetMachine.h"
From a8fa12d03e1d41d703db0d7cfdded6f3a4ece640 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Sat, 5 Mar 2022 16:50:36 +0100
Subject: [PATCH 5/5] llvm14: PointerType::getElementType() was deprecated
... for LLVM 14 in [1] and has already been removed from the LLVM 15
branch in [2].
Some changes are only temporary to silence the warning though, as
Type::getPointerElementType() is planned to be removed as well. [3]
[1] https://reviews.llvm.org/D117885/new/
[2] https://github.com/llvm/llvm-project/commit/d593cf7
[3] https://llvm.org/docs/OpaquePointers.html#migration-instructions
---
lib/Core/Executor.cpp | 30 ++++++++++++----------------
lib/Core/Executor.h | 2 +-
lib/Core/ExternalDispatcher.cpp | 3 +--
lib/Core/GetElementPtrTypeIterator.h | 4 ++--
lib/Module/FunctionAlias.cpp | 6 ++----
5 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/klee/lib/Core/Executor.cpp b/klee/lib/Core/Executor.cpp
index 5e22937..134392a 100644
--- a/klee/lib/Core/Executor.cpp
+++ b/klee/lib/Core/Executor.cpp
@@ -730,7 +730,7 @@ void Executor::initializeGlobals(ExecutionState &state) {
// better we could support user definition, or use the EXE style
// hack where we check the object file information.
- Type *ty = i->getType()->getElementType();
+ Type *ty = i->getValueType();
uint64_t size = 0;
if (ty->isSized()) {
size = kmodule->targetData->getTypeStoreSize(ty);
@@ -2100,10 +2100,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
arguments.push_back(eval(ki, j+1, state));
if (f) {
- const FunctionType *fType =
- dyn_cast<FunctionType>(cast<PointerType>(f->getType())->getElementType());
+ const FunctionType *fType = dyn_cast<FunctionType>(f->getValueType());
const FunctionType *fpType =
- dyn_cast<FunctionType>(cast<PointerType>(fp->getType())->getElementType());
+ dyn_cast<FunctionType>(fp->getType()->getPointerElementType());
// special case the call with a bitcast case
if (fType != fpType) {
@@ -2948,9 +2947,12 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue());
constantOffset = constantOffset->Add(ConstantExpr::alloc(addend,
Context::get().getPointerWidth()));
- } else if (const auto set = dyn_cast<ArrayType>(*ii)) {
- uint64_t elementSize =
- kmodule->targetData->getTypeStoreSize(set->getElementType());
+ } else if (isa<ArrayType>(*ii) || isa<VectorType>(*ii) ||
+ isa<PointerType>(*ii)) {
+ assert(ii->getNumContainedTypes() == 1 &&
+ "Sequential type must contain one subtype");
+ uint64_t elementSize =
+ kmodule->targetData->getTypeStoreSize(ii->getContainedType(0));
Value *operand = ii.getOperand();
if (Constant *c = dyn_cast<Constant>(operand)) {
ref<ConstantExpr> index =
@@ -2962,36 +2964,6 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
} else {
kgepi->indices.push_back(std::make_pair(index, elementSize));
}
- } else if (const auto set = dyn_cast<VectorType>(*ii)) {
- uint64_t elementSize =
- kmodule->targetData->getTypeStoreSize(set->getElementType());
- Value *operand = ii.getOperand();
- if (Constant *c = dyn_cast<Constant>(operand)) {
- ref<ConstantExpr> index =
- cast<ConstantExpr>(evalConstant(c).getValue())->SExt(Context::get().getPointerWidth());
- ref<ConstantExpr> addend =
- index->Mul(ConstantExpr::alloc(elementSize,
- Context::get().getPointerWidth()));
- constantOffset = constantOffset->Add(addend);
- } else {
- kgepi->indices.push_back(std::make_pair(index, elementSize));
- }
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
- } else if (const auto ptr = dyn_cast<PointerType>(*ii)) {
- auto elementSize =
- kmodule->targetData->getTypeStoreSize(ptr->getElementType());
- auto operand = ii.getOperand();
- if (auto c = dyn_cast<Constant>(operand)) {
- auto index
- = cast<ConstantExpr>(evalConstant(c).getValue())->SExt(
- Context::get().getPointerWidth());
- auto addend = index->Mul(ConstantExpr::alloc(elementSize,
- Context::get().getPointerWidth()));
- constantOffset = constantOffset->Add(addend);
- } else {
- kgepi->indices.push_back(std::make_pair(index, elementSize));
- }
-#endif
} else
assert("invalid type" && 0);
index++;
@@ -4798,10 +4770,9 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const {
alignment = GO->getAlignment();
if (const GlobalVariable *globalVar = dyn_cast<GlobalVariable>(GO)) {
// All GlobalVariables's have pointer type
- llvm::PointerType *ptrType =
- dyn_cast<llvm::PointerType>(globalVar->getType());
- assert(ptrType && "globalVar's type is not a pointer");
- type = ptrType->getElementType();
+ assert(globalVar->getType()->isPointerTy() &&
+ "globalVar's type is not a pointer");
+ type = globalVar->getValueType();
} else {
type = GO->getType();
}
diff --git a/klee/lib/Core/ExternalDispatcher.cpp b/klee/lib/Core/ExternalDispatcher.cpp
index aadb340d8c..b0575ee231 100644
--- a/klee/lib/Core/ExternalDispatcher.cpp
+++ b/klee/lib/Core/ExternalDispatcher.cpp
@@ -280,8 +280,7 @@ Function *ExternalDispatcherImpl::createDispatcher(Function *target,
auto argI64s = Builder.CreateLoad(argI64sp->getType()->getPointerElementType(), argI64sp, "args");
// Get the target function type.
- FunctionType *FTy = cast<FunctionType>(
- cast<PointerType>(target->getType())->getElementType());
+ FunctionType *FTy = cast<FunctionType>(target->getValueType());
// Each argument will be passed by writing it into gTheArgsP[i].
unsigned i = 0, idx = 2;
diff --git a/klee/include/klee/util/GetElementPtrTypeIterator.h b/klee/include/klee/util/GetElementPtrTypeIterator.h
index 89606a0a39..54fe6a297d 100644
--- a/klee/include/klee/util/GetElementPtrTypeIterator.h
+++ b/klee/include/klee/util/GetElementPtrTypeIterator.h
@@ -80,8 +80,8 @@ class generic_gep_type_iterator
llvm::isa<llvm::VectorType>(CurTy)) {
CurTy = llvm::GetElementPtrInst::getTypeAtIndex(CurTy, getOperand());
#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
- } else if (auto ptr = llvm::dyn_cast<llvm::PointerType>(CurTy)) {
- CurTy = ptr->getElementType();
+ } else if (llvm::isa<llvm::PointerType>(CurTy)) {
+ CurTy = CurTy->getPointerElementType();
#endif
} else {
CurTy = 0;
diff --git a/klee/lib/Module/FunctionAlias.cpp b/klee/lib/Module/FunctionAlias.cpp
index a98b74fb60..aa80b35d6e 100644
--- a/klee/lib/Module/FunctionAlias.cpp
+++ b/klee/lib/Module/FunctionAlias.cpp
@@ -135,10 +135,8 @@ bool FunctionAliasPass::runOnModule(Module &M) {
const FunctionType *FunctionAliasPass::getFunctionType(const GlobalValue *gv) {
const Type *type = gv->getType();
- while (type->isPointerTy()) {
- const PointerType *ptr = cast<PointerType>(type);
- type = ptr->getElementType();
- }
+ while (type->isPointerTy())
+ type = type->getPointerElementType();
return cast<FunctionType>(type);
}
From 9c41dd94a417fe45e8e95b5c81c94b165dd3c5ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Tue, 3 May 2022 21:18:56 +0200
Subject: [PATCH 1/2] cmake: LLVM 14 requires C as a project language
... due to a bug.
See: https://github.com/llvm/llvm-project/issues/53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
/usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
/usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
CMakeLists.txt:31 (find_package)
---
CMakeLists.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sbt-instrumentation/CMakeLists.txt b/sbt-instrumentation/CMakeLists.txt
index dc7a896..cb1111f 100644
--- a/sbt-instrumentation/CMakeLists.txt
+++ b/sbt-instrumentation/CMakeLists.txt
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.1.0)
-project(sbt-instrumentation CXX)
+
+# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
+# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
+project(sbt-instrumentation LANGUAGES C CXX)
# --------------------------------------------------
# Build type
From e69e7f77a1294d7d716e3e874270fb36e27f198d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <[email protected]>
Date: Tue, 3 May 2022 23:33:55 +0200
Subject: [PATCH 2/2] llvm14: PointerType::getElementType() was deprecated
... for LLVM 14 in [1] and has already been removed from the LLVM 15
branch in [2].
[1] https://reviews.llvm.org/D117885/new/
[2] https://github.com/llvm/llvm-project/commit/d593cf7
---
src/instr.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sbt-instrumentation/src/instr.cpp b/sbt-instrumentation/src/instr.cpp
index 8a37ef4..4b6fe76 100644
--- a/sbt-instrumentation/src/instr.cpp
+++ b/sbt-instrumentation/src/instr.cpp
@@ -1014,8 +1014,7 @@ bool checkInstruction(Instruction* ins, Function* F, RewriterConfig rw_config, i
* @return size of global variable.
*/
uint64_t getGlobalVarSize(GlobalVariable* GV, const Module& M) {
- Type* Ty = GV->getType()->getElementType();
-
+ Type* Ty = GV->getValueType();
if (!Ty->isSized())
return 0;