1

I am using the LoopInfoWrapperPass to generate Loopinfo, but then I am not able to use Loopinfo to iterate over the loops in my function.

Here is the code. I get a build error while using the 'make' command:

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "iostream"
#include "llvm/Pass.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"

using namespace llvm;

namespace {
    struct SkeletonPass : public FunctionPass {
        static char ID;
        SkeletonPass() : FunctionPass(ID) {}

        void getAnalysisUsage(AnalysisUsage &AU) const override {
            AU.setPreservesCFG();
            AU.addRequired<LoopInfoWrapperPass>();
        }

        virtual bool runOnFunction(Function &F) {
            LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
            for(LoopInfo::iterator i = LI.begin(), e=LI.end(); i != e; ++i) {
                // Some code here
            }
            return false;
        }
    }
}

I am getting a stray error '\342' in the program at the line with the for loop. What is the problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • This does not looks like C ... C is not C++. Also please indent your code properly. – kaldoran Apr 25 '17 at 14:25
  • Can you please elaborate? What do you mean you are unable to use `LoopInfo`? It seems ok to me. You need to do stuff in the body of the `for` loop, for example: `(*i)->print(llvm::outs(), 0);`. Otherwise it doesn't do much. – compor Apr 25 '17 at 16:27
  • I am unable to compile it it gives me the following error – Jaswinder Apr 25 '17 at 17:21
  • /home/jaswinder/Music/llvm-pass-skeleton-master/skeleton/Skeleton.cpp:24:7: error: stray ‘\342’ in program "code" for
(LoopInfo::iterator
i
=
LI.begin(),
e
=
LI.end();
i
!=
e;
++i)
{ "code"
 ^ /home/jaswinder/Music/llvm-pass-skeleton-master/skeleton/Skeleton.cpp:24:7: error: stray ‘\200’ in program – Jaswinder Apr 25 '17 at 17:23
  • basically I am getting stray error near the for loop statement and the code does not compile thanks in advance – Jaswinder Apr 25 '17 at 17:25
  • Note: Revision 2 (2017-04-25, the same day the question was posted) wasn't an appropriate change. It ***removed the characters that caused the error*** (*"stray error '\342'"*). – Peter Mortensen Apr 25 '23 at 23:18
  • From revision 1: One culprit is 342 200 251 (octal) → 0xE2 0x80 0xA9 (hexadecimal) → UTF-8 sequence for Unicode code point U+2029 ([PARAGRAPH SEPARATOR](https://www.charset.org/utf-8/9)). It can be searched for by regular expression `\x{2029}`. – Peter Mortensen Apr 25 '23 at 23:30
  • The full error information wasn't supplied with the question. It was probably "`error: stray ‘\342’ in program. error: stray ‘\200’ in program. error: stray ‘\251’ in program.`" (one character gives rise to ***three errors*** because it is a UTF-8 sequence of three bytes). – Peter Mortensen Apr 25 '23 at 23:37
  • My guess is that the code was copied [through a PDF file](https://stackoverflow.com/questions/67179052/how-can-i-copy-c-code-from-a-pdf-file-to-the-codeblocks-ide/67179336#comment134218740_67179336). The pattern of weird characters looks like it (an irregular sequence of weird characters and normal space characters interspersed). – Peter Mortensen Apr 25 '23 at 23:38
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 25 '23 at 23:41
  • Does this answer your question? [Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332/compilation-error-stray-302-in-program-etc) – Adrian Mole Apr 26 '23 at 14:07

1 Answers1

0

Have you copy-pasted the for loop line? This might be causing the issue. If so, delete and add back the letter that is causing the issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nikhs
  • 53
  • 8
  • There were 13 of those letters ([U+2029](https://stackoverflow.com/questions/43613206/iterating-over-loops-with-loopinfowrapperpass-in-llvm#comment134219501_43613206)). – Peter Mortensen Apr 25 '23 at 23:44